Skip to content

Commit

Permalink
chore(_tools): add npm build script
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed Jun 3, 2023
1 parent 64b18fc commit 4566ad0
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"branches": [
"main",
{
"name": "beta",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/github",
[
"@semantic-release/git",
{
"assets": [
"CHANGELOG.md"
],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
],
"tagFormat": "${version}"
}
23 changes: 23 additions & 0 deletions _tools/build_npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { build, emptyDir } from "https://deno.land/x/[email protected]/mod.ts";
import { join } from "https://deno.land/[email protected]/path/mod.ts";
import { makeOptions } from "./meta.ts";

async function buildPkg(version: string): Promise<void> {
await emptyDir("./npm");
const pkg = makeOptions(version);
await Deno.copyFile("LICENSE", join(pkg.outDir, "LICENSE"));
Deno.copyFile(
join(".", "README.md"),
join(pkg.outDir, "README.md"),
);
await build(pkg);
}

if (import.meta.main) {
const version = Deno.args[0];
if (!version) {
console.error("argument is required");
Deno.exit(1);
}
await buildPkg(version);
}
41 changes: 41 additions & 0 deletions _tools/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { BuildOptions } from "https://deno.land/x/[email protected]/mod.ts";

export const makeOptions = (version: string): BuildOptions => ({
test: false,
shims: {},
typeCheck: true,
entryPoints: ["./mod.ts"],
outDir: "./npm",
package: {
name: "@miyauci/format",
version,
description: "Formatting and printing string utilities",
keywords: [
"format",
"fmt",
"formatter",
"print",
"sprintf",
"format-string",
"replace",
"replacement",
"template",
"interpolate",
],
license: "MIT",
homepage: "https://github.com/TomokiMiyauci/format",
repository: {
type: "git",
url: "git+https://github.com/TomokiMiyauci/format.git",
},
bugs: {
url: "https://github.com/TomokiMiyauci/format/issues",
},
sideEffects: false,
type: "module",
publishConfig: {
access: "public",
},
},
packageManager: "pnpm",
});
27 changes: 27 additions & 0 deletions _tools/publish_npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { prerelease, valid } from "https://deno.land/x/[email protected]/mod.ts";
import { makeOptions } from "./meta.ts";

if (import.meta.main) {
const version = Deno.args[0];
if (!version) {
console.error("arg of version is required");
Deno.exit(1);
}
if (!valid(version)) {
console.error("The argument of version is invalid");
Deno.exit(1);
}

const isPrerelease = prerelease(version);
const tag = isPrerelease?.[0] ?? "latest";

const pkg = makeOptions(version);
const command = new Deno.Command("npm", {
args: ["publish", pkg.outDir, "--tag", String(tag)],
});
const result = await command.output();

if (!result.success) {
console.error(new TextDecoder().decode(result.stderr));
}
}

0 comments on commit 4566ad0

Please sign in to comment.