mirror of
https://github.com/garronej/ts-ci.git
synced 2025-11-30 21:43:05 +00:00
Add remove_dark_mode_specific_images_from_readme
This commit is contained in:
parent
f413caaaac
commit
4b7615d6bc
6 changed files with 178 additions and 12 deletions
|
|
@ -27,7 +27,8 @@ export const availableActions = [
|
|||
"is_well_formed_and_available_module_name",
|
||||
"string_replace",
|
||||
"tell_if_project_uses_npm_or_yarn",
|
||||
"is_package_json_version_upgraded"
|
||||
"is_package_json_version_upgraded",
|
||||
"remove_dark_mode_specific_images_from_readme"
|
||||
] as const;
|
||||
|
||||
|
||||
|
|
|
|||
15
src/main.ts
15
src/main.ts
|
|
@ -5,10 +5,13 @@ import * as sync_package_and_package_lock_version from "./sync_package_and_packa
|
|||
import * as setup_repo_webhook_for_deno_land_publishing from "./setup_repo_webhook_for_deno_land_publishing";
|
||||
import * as is_well_formed_and_available_module_name from "./is_well_formed_and_available_module_name";
|
||||
import * as tell_if_project_uses_npm_or_yarn from "./tell_if_project_uses_npm_or_yarn";
|
||||
import * as remove_dark_mode_specific_images_from_readme from "./remove_dark_mode_specific_images_from_readme";
|
||||
import * as string_replace from "./string_replace";
|
||||
import * as is_package_json_version_upgraded from "./is_package_json_version_upgraded";
|
||||
import { getActionName } from "./inputHelper";
|
||||
import * as update_changelog from "./update_changelog";
|
||||
import { assert } from "tsafe/assert";
|
||||
import type { Equals } from "tsafe";
|
||||
|
||||
async function run(): Promise<null> {
|
||||
|
||||
|
|
@ -90,12 +93,14 @@ async function run(): Promise<null> {
|
|||
)
|
||||
);
|
||||
return null;
|
||||
|
||||
case "remove_dark_mode_specific_images_from_readme":
|
||||
await remove_dark_mode_specific_images_from_readme.action(
|
||||
action_name
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (1 === 0 + 1) {
|
||||
throw new Error(`${action_name} Not supported by this toolkit`);
|
||||
}
|
||||
assert<Equals<typeof action_name, never>>(false);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -106,7 +111,7 @@ async function run(): Promise<null> {
|
|||
await run()
|
||||
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
core.setFailed(String(error));
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
21
src/remove_dark_mode_specific_images_from_readme.ts
Normal file
21
src/remove_dark_mode_specific_images_from_readme.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import * as fs from "fs";
|
||||
|
||||
export async function action(
|
||||
_actionName: "remove_dark_mode_specific_images_from_readme"
|
||||
) {
|
||||
|
||||
fs.writeFileSync("README.md",
|
||||
Buffer.from(
|
||||
removeDarkModeSpecificImageFromReadme(
|
||||
fs.readFileSync("README.md").toString("utf8")
|
||||
),
|
||||
"utf8"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
export function removeDarkModeSpecificImageFromReadme(readmeRawContent: string) {
|
||||
return readmeRawContent
|
||||
.replace(/^!\[[^\]]*\]\([^#]+#gh-dark-mode-only\)/gm, "");
|
||||
}
|
||||
84
src/test/removeDarkModeSpecificImageFromReadme.ts
Normal file
84
src/test/removeDarkModeSpecificImageFromReadme.ts
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
|
||||
import { assert } from "tsafe/assert";
|
||||
import { removeDarkModeSpecificImageFromReadme } from "../remove_dark_mode_specific_images_from_readme";
|
||||
|
||||
const input = `
|
||||
<div align="center">
|
||||
|
||||

|
||||
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
|
||||

|
||||
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
|
||||

|
||||
|
||||
</div>
|
||||
|
||||
<p align="center">
|
||||
<i>Type-safe internationalization and translation React library</i>
|
||||
<br>
|
||||
<br>
|
||||
<a href="https://github.com/garronej/i18nifty/actions">
|
||||
<img src="https://github.com/garronej/i18nifty/workflows/ci/badge.svg?branch=main">
|
||||
</a>
|
||||
<a href="https://bundlephobia.com/package/i18nifty">
|
||||
<img src="https://img.shields.io/bundlephobia/minzip/i18nifty">
|
||||
</a>
|
||||
<a href="https://www.npmjs.com/package/i18nifty">
|
||||
<img src="https://img.shields.io/npm/dm/i18nifty">
|
||||
</a>
|
||||
<a href="https://github.com/garronej/i18nifty/blob/main/LICENSE">
|
||||
<img src="https://img.shields.io/npm/l/i18nifty">
|
||||
</a>
|
||||
</p>
|
||||
`;
|
||||
|
||||
|
||||
const expected = `
|
||||
<div align="center">
|
||||
|
||||

|
||||
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<p align="center">
|
||||
<i>Type-safe internationalization and translation React library</i>
|
||||
<br>
|
||||
<br>
|
||||
<a href="https://github.com/garronej/i18nifty/actions">
|
||||
<img src="https://github.com/garronej/i18nifty/workflows/ci/badge.svg?branch=main">
|
||||
</a>
|
||||
<a href="https://bundlephobia.com/package/i18nifty">
|
||||
<img src="https://img.shields.io/bundlephobia/minzip/i18nifty">
|
||||
</a>
|
||||
<a href="https://www.npmjs.com/package/i18nifty">
|
||||
<img src="https://img.shields.io/npm/dm/i18nifty">
|
||||
</a>
|
||||
<a href="https://github.com/garronej/i18nifty/blob/main/LICENSE">
|
||||
<img src="https://img.shields.io/npm/l/i18nifty">
|
||||
</a>
|
||||
</p>
|
||||
`;
|
||||
|
||||
assert( expected === removeDarkModeSpecificImageFromReadme(input));
|
||||
|
||||
console.log("PASS!");
|
||||
Loading…
Add table
Add a link
Reference in a new issue