Skip to content

Commit

Permalink
Add remove_dark_mode_specific_images_from_readme
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Oct 21, 2022
1 parent f413caa commit 4b7615d
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 12 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ author: 'u/garronej'
inputs:
action_name:
required: true
description: 'Action to run, one of: "get_package_json_version", "dispatch_event", "update_changelog", "sync_package_and_package_lock_version", "setup_repo_webhook_for_deno_land_publishing", "is_well_formed_and_available_module_name", "string_replace", "tell_if_project_uses_npm_or_yarn", "is_package_json_version_upgraded"'
description: 'Action to run, one of: "get_package_json_version", "dispatch_event", "update_changelog", "sync_package_and_package_lock_version", "setup_repo_webhook_for_deno_land_publishing", "is_well_formed_and_available_module_name", "string_replace", "tell_if_project_uses_npm_or_yarn", "is_package_json_version_upgraded", "remove_dark_mode_specific_images_from_readme"'
owner:
required: false
description: 'Repository owner, example: ''garronej'',github.repository_owner'
Expand Down
65 changes: 60 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1783,10 +1783,12 @@ const sync_package_and_package_lock_version = __importStar(__webpack_require__(8
const setup_repo_webhook_for_deno_land_publishing = __importStar(__webpack_require__(518));
const is_well_formed_and_available_module_name = __importStar(__webpack_require__(245));
const tell_if_project_uses_npm_or_yarn = __importStar(__webpack_require__(201));
const remove_dark_mode_specific_images_from_readme = __importStar(__webpack_require__(275));
const string_replace = __importStar(__webpack_require__(599));
const is_package_json_version_upgraded = __importStar(__webpack_require__(949));
const inputHelper_1 = __webpack_require__(649);
const update_changelog = __importStar(__webpack_require__(702));
const assert_1 = __webpack_require__(606);
function run() {
return __awaiter(this, void 0, void 0, function* () {
const action_name = inputHelper_1.getActionName();
Expand Down Expand Up @@ -1818,18 +1820,19 @@ function run() {
case "is_package_json_version_upgraded":
is_package_json_version_upgraded.setOutput(yield is_package_json_version_upgraded.action(action_name, is_package_json_version_upgraded.getActionParams(), core));
return null;
case "remove_dark_mode_specific_images_from_readme":
yield remove_dark_mode_specific_images_from_readme.action(action_name);
return null;
}
if (true) {
throw new Error(`${action_name} Not supported by this toolkit`);
}
assert_1.assert(false);
});
}
(() => __awaiter(void 0, void 0, void 0, function* () {
try {
yield run();
}
catch (error) {
core.setFailed(error.message);
core.setFailed(String(error));
}
}))();

Expand Down Expand Up @@ -2284,6 +2287,57 @@ exports.assertIsRefWrapper = {
};
//# sourceMappingURL=assertIsRefWrapper.js.map

/***/ }),

/***/ 275:
/***/ (function(__unusedmodule, exports, __webpack_require__) {

"use strict";

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeDarkModeSpecificImageFromReadme = exports.action = void 0;
const fs = __importStar(__webpack_require__(747));
function action(_actionName) {
return __awaiter(this, void 0, void 0, function* () {
fs.writeFileSync("README.md", Buffer.from(removeDarkModeSpecificImageFromReadme(fs.readFileSync("README.md").toString("utf8")), "utf8"));
});
}
exports.action = action;
function removeDarkModeSpecificImageFromReadme(readmeRawContent) {
return readmeRawContent
.replace(/^!\[[^\]]*\]\([^#]+#gh-dark-mode-only\)/gm, "");
}
exports.removeDarkModeSpecificImageFromReadme = removeDarkModeSpecificImageFromReadme;


/***/ }),

/***/ 280:
Expand Down Expand Up @@ -10747,7 +10801,8 @@ exports.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"
];
function getInputDescription(inputName) {
switch (inputName) {
Expand Down
3 changes: 2 additions & 1 deletion src/inputHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
15 changes: 10 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {

Expand Down Expand Up @@ -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);

}

Expand All @@ -106,7 +111,7 @@ async function run(): Promise<null> {
await run()

} catch (error) {
core.setFailed(error.message);
core.setFailed(String(error));
}

})();
Expand Down
21 changes: 21 additions & 0 deletions src/remove_dark_mode_specific_images_from_readme.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 84 additions & 0 deletions src/test/removeDarkModeSpecificImageFromReadme.ts
Original file line number Diff line number Diff line change
@@ -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!");

0 comments on commit 4b7615d

Please sign in to comment.