Add remove_dark_mode_specific_images_from_readme

This commit is contained in:
garronej 2022-10-21 19:34:09 +02:00
parent f413caaaac
commit 4b7615d6bc
6 changed files with 178 additions and 12 deletions

View file

@ -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;

View file

@ -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));
}
})();

View 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, "");
}

View 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">
![Logo Light](https://user-images.githubusercontent.com/6702424/172086583-2014cf56-6deb-466d-b4d4-df80b6e85a1e.png#gh-light-mode-only)
</div>
<div align="center">
![Logo Dark](https://user-images.githubusercontent.com/6702424/172086369-292a3ada-8294-4328-bbb0-336061cbf830.png#gh-dark-mode-only)
</div>
<div align="center">
![](https://user-images.githubusercontent.com/6702424/xxx#gh-dark-mode-only)
</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">
![Logo Light](https://user-images.githubusercontent.com/6702424/172086583-2014cf56-6deb-466d-b4d4-df80b6e85a1e.png#gh-light-mode-only)
</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!");