Skip to content

Commit

Permalink
refactor(action): simplify export logic and enhance script replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudcome committed Jul 23, 2024
1 parent ea37e6b commit 6ce6bed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ runs:
with:
result-encoding: string
script: |
const exports = exports || {};
const exports = {};
function expose() {
// SCRIPT REPLACE START
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
Expand All @@ -80,7 +81,9 @@ runs:
}
exports.main = main;
// SCRIPT REPLACE END
await main(process.cwd(), context);
}
expose();
await exports.main(process.cwd(), context);
- name: Publish
shell: bash
Expand Down
3 changes: 2 additions & 1 deletion scripts/replace-action.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const write = (f, d) => fs.writeFileSync(resolve(f), d, 'utf8');
const source = read('dist/index.cjs');
const action = read('action.yml');
const action2 = action.replace(/^(\s+)\/\/ SCRIPT REPLACE START[\s\S]*?^(\s+)\/\/ SCRIPT REPLACE END/m, (_, indent) => {
const source2 = source.trim().replace(/^/gm, indent);
return `${indent}// SCRIPT REPLACE START
${source.trim().replace(/^/gm, indent)}
${source2}
${indent}// SCRIPT REPLACE END`;
});

Expand Down

0 comments on commit 6ce6bed

Please sign in to comment.