Skip to content

Commit

Permalink
chore: improve githubAction
Browse files Browse the repository at this point in the history
  • Loading branch information
hongaar committed Dec 14, 2022
1 parent 1b9bf64 commit 5e7c5d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/plugins/src/esbuild/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function load({ directory }: PluginArgs) {
build: "yarn clean && yarn build:typecheck && yarn build:bundle",
"build:typecheck": "tsc --noEmit",
"build:bundle":
"esbuild --bundle --platform=node --target=es2022 --outdir=dist src/index.ts",
"esbuild --bundle --platform=node --format=esm --target=es2022 --outdir=dist src/index.ts",
},
},
});
Expand All @@ -68,7 +68,7 @@ async function load({ directory }: PluginArgs) {
scripts: {
clean: "rm -rf dist",
build:
"yarn clean && esbuild --bundle --platform=node --target=es2022 --outdir=dist src/index.ts",
"yarn clean && esbuild --bundle --platform=node --format=esm --target=es2022 --outdir=dist src/index.ts",
prepublish: "yarn build",
},
},
Expand Down
34 changes: 15 additions & 19 deletions packages/templates/src/githubAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import {
hasPlugin,
installPlugin,
PluginType,
readGitignore,
TemplateArgs,
warning,
writeFile,
writeGitignore,
writePackage,
writeYaml,
} from "@mokr/core";
import { addPreCommitHookCommand } from "@mokr/plugins";
import { basename, join, resolve } from "node:path";

async function apply({ directory }: TemplateArgs) {
Expand All @@ -21,13 +19,16 @@ async function apply({ directory }: TemplateArgs) {

await installPlugin({ directory, name: "esbuild" });

// Dist directory with generated bundle should be checked in
await writeGitignore({
// We need to bundle to cjs due to some dependencies not supporting esm
// See https://github.com/evanw/esbuild/issues/1921
await writePackage({
directory,
lines: (
await readGitignore({ directory })
).filter((line) => line !== "/dist"),
append: false,
data: {
scripts: {
"build:bundle":
"esbuild --bundle --platform=node --format=cjs --target=es2022 --outfile=dist/index.cjs src/index.ts",
},
},
});

// But Git should ignore generated files
Expand All @@ -36,14 +37,6 @@ async function apply({ directory }: TemplateArgs) {
contents: `*.js linguist-generated=true`,
});

// Use Husky to build before commit
await installPlugin({ directory, name: "husky" });

await addPreCommitHookCommand({
directory,
command: "yarn build && git add dist",
});

// Required action.yml
await writeYaml({
path: resolve(directory, "action.yml"),
Expand All @@ -64,7 +57,7 @@ async function apply({ directory }: TemplateArgs) {
},
runs: {
using: "node16",
main: "dist/index.js",
main: "dist/index.cjs",
},
},
});
Expand All @@ -88,6 +81,7 @@ async function run() {
throw new Error("The GitHub token is missing");
}
// Example logic
const octokit = getOctokit(ghToken);
const { owner, repo } = context.repo;
Expand Down Expand Up @@ -145,7 +139,9 @@ ${description}

if (await hasPlugin({ directory, name: "semantic-release" })) {
warning(
'Please modify your ".releaserc.json" file to set "semantic-release-yarn.npmPublish" to "false" to prevent uploading this package to NPM. See [semantic-release-yarn plugin options](https://github.com/hongaar/semantic-release-yarn#plugin-options) for more information.'
`Please modify your ".releaserc.json" file:
- Set "semantic-release-yarn.npmPublish" to "false" to prevent uploading this package to NPM. See [semantic-release-yarn plugin options](https://github.com/hongaar/semantic-release-yarn#plugin-options) for more information.
- Add "dist/index.cjs" to the "@semantic-release/git.assets" configuration to include the generated files in the release commit.`
);
}
}
Expand Down

0 comments on commit 5e7c5d9

Please sign in to comment.