@adviser/cement 0.4.51 → 0.4.52-pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/cli/generate-version-ts-cmd.cjs +79 -0
- package/cjs/cli/generate-version-ts-cmd.cjs.map +1 -0
- package/cjs/cli/generate-version-ts-cmd.d.ts +3 -0
- package/cjs/cli/generate-version-ts-cmd.d.ts.map +1 -0
- package/cjs/cli/main.cjs +8 -3
- package/cjs/cli/main.cjs.map +1 -1
- package/cjs/cli/patch-version-cmd.cjs +3 -226
- package/cjs/cli/patch-version-cmd.cjs.map +1 -1
- package/cjs/cli/patch-version-cmd.d.ts +0 -4
- package/cjs/cli/patch-version-cmd.d.ts.map +1 -1
- package/cjs/cli/prepare-pubdir-cmd.cjs +150 -0
- package/cjs/cli/prepare-pubdir-cmd.cjs.map +1 -0
- package/cjs/cli/prepare-pubdir-cmd.d.ts +4 -0
- package/cjs/cli/prepare-pubdir-cmd.d.ts.map +1 -0
- package/cjs/cli/publish-tags-cmd.cjs +94 -0
- package/cjs/cli/publish-tags-cmd.cjs.map +1 -0
- package/cjs/cli/publish-tags-cmd.d.ts +3 -0
- package/cjs/cli/publish-tags-cmd.d.ts.map +1 -0
- package/cjs/cli/setup-deno-json-cmd.cjs +77 -0
- package/cjs/cli/setup-deno-json-cmd.cjs.map +1 -0
- package/cjs/cli/setup-deno-json-cmd.d.ts +3 -0
- package/cjs/cli/setup-deno-json-cmd.d.ts.map +1 -0
- package/cjs/cli/utils.cjs +93 -0
- package/cjs/cli/utils.cjs.map +1 -0
- package/cjs/cli/utils.d.ts +6 -0
- package/cjs/cli/utils.d.ts.map +1 -0
- package/cjs/version.cjs +1 -1
- package/cjs/version.cjs.map +1 -1
- package/cjs/version.d.ts.map +1 -1
- package/deno.json +1 -1
- package/esm/cli/generate-version-ts-cmd.d.ts +3 -0
- package/esm/cli/generate-version-ts-cmd.d.ts.map +1 -0
- package/esm/cli/generate-version-ts-cmd.js +43 -0
- package/esm/cli/generate-version-ts-cmd.js.map +1 -0
- package/esm/cli/main.js +6 -1
- package/esm/cli/main.js.map +1 -1
- package/esm/cli/patch-version-cmd.d.ts +0 -4
- package/esm/cli/patch-version-cmd.d.ts.map +1 -1
- package/esm/cli/patch-version-cmd.js +1 -220
- package/esm/cli/patch-version-cmd.js.map +1 -1
- package/esm/cli/prepare-pubdir-cmd.d.ts +4 -0
- package/esm/cli/prepare-pubdir-cmd.d.ts.map +1 -0
- package/esm/cli/prepare-pubdir-cmd.js +113 -0
- package/esm/cli/prepare-pubdir-cmd.js.map +1 -0
- package/esm/cli/publish-tags-cmd.d.ts +3 -0
- package/esm/cli/publish-tags-cmd.d.ts.map +1 -0
- package/esm/cli/publish-tags-cmd.js +58 -0
- package/esm/cli/publish-tags-cmd.js.map +1 -0
- package/esm/cli/setup-deno-json-cmd.d.ts +3 -0
- package/esm/cli/setup-deno-json-cmd.d.ts.map +1 -0
- package/esm/cli/setup-deno-json-cmd.js +41 -0
- package/esm/cli/setup-deno-json-cmd.js.map +1 -0
- package/esm/cli/utils.d.ts +6 -0
- package/esm/cli/utils.d.ts.map +1 -0
- package/esm/cli/utils.js +54 -0
- package/esm/cli/utils.js.map +1 -0
- package/esm/version.d.ts.map +1 -1
- package/esm/version.js +1 -1
- package/esm/version.js.map +1 -1
- package/package.json +42 -25
- package/src/cli/generate-version-ts-cmd.ts +43 -0
- package/src/cli/main.ts +6 -1
- package/src/cli/patch-version-cmd.ts +1 -289
- package/src/cli/prepare-pubdir-cmd.ts +156 -0
- package/src/cli/publish-tags-cmd.ts +69 -0
- package/src/cli/run.sh +10 -1
- package/src/cli/setup-deno-json-cmd.ts +51 -0
- package/src/cli/utils.ts +70 -0
- package/ts/cjs/cli/generate-version-ts-cmd.d.ts +3 -0
- package/ts/cjs/cli/generate-version-ts-cmd.d.ts.map +1 -0
- package/ts/cjs/cli/generate-version-ts-cmd.js +79 -0
- package/ts/cjs/cli/generate-version-ts-cmd.js.map +1 -0
- package/ts/cjs/cli/main.js +8 -3
- package/ts/cjs/cli/main.js.map +1 -1
- package/ts/cjs/cli/patch-version-cmd.d.ts +0 -4
- package/ts/cjs/cli/patch-version-cmd.d.ts.map +1 -1
- package/ts/cjs/cli/patch-version-cmd.js +3 -226
- package/ts/cjs/cli/patch-version-cmd.js.map +1 -1
- package/ts/cjs/cli/prepare-pubdir-cmd.d.ts +4 -0
- package/ts/cjs/cli/prepare-pubdir-cmd.d.ts.map +1 -0
- package/ts/cjs/cli/prepare-pubdir-cmd.js +150 -0
- package/ts/cjs/cli/prepare-pubdir-cmd.js.map +1 -0
- package/ts/cjs/cli/publish-tags-cmd.d.ts +3 -0
- package/ts/cjs/cli/publish-tags-cmd.d.ts.map +1 -0
- package/ts/cjs/cli/publish-tags-cmd.js +94 -0
- package/ts/cjs/cli/publish-tags-cmd.js.map +1 -0
- package/ts/cjs/cli/setup-deno-json-cmd.d.ts +3 -0
- package/ts/cjs/cli/setup-deno-json-cmd.d.ts.map +1 -0
- package/ts/cjs/cli/setup-deno-json-cmd.js +77 -0
- package/ts/cjs/cli/setup-deno-json-cmd.js.map +1 -0
- package/ts/cjs/cli/utils.d.ts +6 -0
- package/ts/cjs/cli/utils.d.ts.map +1 -0
- package/ts/cjs/cli/utils.js +93 -0
- package/ts/cjs/cli/utils.js.map +1 -0
- package/ts/cjs/version.d.ts.map +1 -1
- package/ts/cjs/version.js +1 -1
- package/ts/cjs/version.js.map +1 -1
- package/ts/esm/cli/generate-version-ts-cmd.d.ts +3 -0
- package/ts/esm/cli/generate-version-ts-cmd.d.ts.map +1 -0
- package/ts/esm/cli/generate-version-ts-cmd.js +43 -0
- package/ts/esm/cli/generate-version-ts-cmd.js.map +1 -0
- package/ts/esm/cli/main.js +6 -1
- package/ts/esm/cli/main.js.map +1 -1
- package/ts/esm/cli/patch-version-cmd.d.ts +0 -4
- package/ts/esm/cli/patch-version-cmd.d.ts.map +1 -1
- package/ts/esm/cli/patch-version-cmd.js +1 -220
- package/ts/esm/cli/patch-version-cmd.js.map +1 -1
- package/ts/esm/cli/prepare-pubdir-cmd.d.ts +4 -0
- package/ts/esm/cli/prepare-pubdir-cmd.d.ts.map +1 -0
- package/ts/esm/cli/prepare-pubdir-cmd.js +113 -0
- package/ts/esm/cli/prepare-pubdir-cmd.js.map +1 -0
- package/ts/esm/cli/publish-tags-cmd.d.ts +3 -0
- package/ts/esm/cli/publish-tags-cmd.d.ts.map +1 -0
- package/ts/esm/cli/publish-tags-cmd.js +58 -0
- package/ts/esm/cli/publish-tags-cmd.js.map +1 -0
- package/ts/esm/cli/setup-deno-json-cmd.d.ts +3 -0
- package/ts/esm/cli/setup-deno-json-cmd.d.ts.map +1 -0
- package/ts/esm/cli/setup-deno-json-cmd.js +41 -0
- package/ts/esm/cli/setup-deno-json-cmd.js.map +1 -0
- package/ts/esm/cli/utils.d.ts +6 -0
- package/ts/esm/cli/utils.d.ts.map +1 -0
- package/ts/esm/cli/utils.js +54 -0
- package/ts/esm/cli/utils.js.map +1 -0
- package/ts/esm/version.d.ts.map +1 -1
- package/ts/esm/version.js +1 -1
- package/ts/esm/version.js.map +1 -1
- package/tsconfig.json +25 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adviser/cement",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.52-pre",
|
|
4
4
|
"description": "better try/catch/finally handling",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -47,12 +47,37 @@
|
|
|
47
47
|
"import": "./esm/import-meta-env.module.js"
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"clean": "rm -rf dist node_modules",
|
|
52
|
+
"build": "pnpm run build:tsgo; pnpm run build:js; pnpm run build:deno",
|
|
53
|
+
"build:tsc": "rm -rf ./dist/ts ; pnpm run /^build:tsc:/",
|
|
54
|
+
"build:tsgo": "rm -rf ./dist/ts ; pnpm run /^build:tsgo:/",
|
|
55
|
+
"build:tsgo:global": "tsgo --noEmit",
|
|
56
|
+
"build:tsgo:esm": "tsgo -p ./tsconfig.esm.json; src/cli/run.sh generateVersionTs -t ./tsconfig.esm.json",
|
|
57
|
+
"build:tsgo:cjs": "tsgo -p ./tsconfig.cjs.json; src/cli/run.sh generateVersionTs -t ./tsconfig.cjs.json",
|
|
58
|
+
"build:js": "rm -rf dist/pkg ; mkdir -p dist/pkg; cp -pr ./dist/ts/* dist/pkg",
|
|
59
|
+
"build:deno": "deno publish --dry-run --unstable-sloppy-imports --allow-dirty --set-version 0.0.0-dev --quiet",
|
|
60
|
+
"test": "pnpm run test:js; pnpm run test:deno",
|
|
61
|
+
"test:deno": "deno run --quiet --allow-net --allow-write --allow-run --allow-sys --allow-ffi --allow-read --allow-env ./node_modules/vitest/vitest.mjs --run --project node",
|
|
62
|
+
"test:js": "vitest --run",
|
|
63
|
+
"pubdir": "src/cli/run.sh preparePubdir",
|
|
64
|
+
"presmoke": "pnpm run pubdir ; cd pubdir",
|
|
65
|
+
"deno:publish": "pnpm run pubdir; cd pubdir ; pnpm exec deno publish --allow-dirty --unstable-sloppy-imports --quiet",
|
|
66
|
+
"smoke": "bash ./smoke/it.sh",
|
|
67
|
+
"lint": "eslint .",
|
|
68
|
+
"prettier": "prettier .",
|
|
69
|
+
"format": "prettier ."
|
|
70
|
+
},
|
|
50
71
|
"keywords": [],
|
|
51
72
|
"author": "Meno Abels <meno.abels@adviser.com>",
|
|
52
73
|
"license": "AFL-2.0",
|
|
53
74
|
"bugs": {
|
|
54
75
|
"url": "https://github.com/mabels/cement/issues"
|
|
55
76
|
},
|
|
77
|
+
"repository": {
|
|
78
|
+
"type": "git",
|
|
79
|
+
"url": "git+https://github.com/mabels/cement"
|
|
80
|
+
},
|
|
56
81
|
"homepage": "https://github.com/mabels/cement#readme",
|
|
57
82
|
"dependencies": {
|
|
58
83
|
"ts-essentials": "^10.0.2",
|
|
@@ -64,6 +89,7 @@
|
|
|
64
89
|
"@types/deno": "^2.3.0",
|
|
65
90
|
"@types/fs-extra": "^11.0.4",
|
|
66
91
|
"@types/node": "^24.4.0",
|
|
92
|
+
"@types/semver": "^7.7.1",
|
|
67
93
|
"@typescript-eslint/eslint-plugin": "^8.7.0",
|
|
68
94
|
"@typescript-eslint/parser": "^8.7.0",
|
|
69
95
|
"@typescript/native-preview": "7.0.0-dev.20251006.1",
|
|
@@ -71,13 +97,11 @@
|
|
|
71
97
|
"@vitest/runner": "^3.2.4",
|
|
72
98
|
"cmd-ts": "^0.14.1",
|
|
73
99
|
"deno": "^2.5.1",
|
|
74
|
-
"esbuild-plugin-replace": "^1.4.0",
|
|
75
|
-
"esbuild-plugin-resolve": "^2.0.0",
|
|
76
100
|
"eslint": "^9.35.0",
|
|
77
101
|
"jscodeshift": "^17.3.0",
|
|
78
102
|
"playwright": "^1.54.1",
|
|
79
|
-
"playwright-chromium": "^1.54.1",
|
|
80
103
|
"prettier": "^3.6.2",
|
|
104
|
+
"semver": "^7.7.3",
|
|
81
105
|
"tsup": "^8.3.0",
|
|
82
106
|
"tsx": "^4.19.1",
|
|
83
107
|
"typescript": "^5.9.2",
|
|
@@ -90,25 +114,18 @@
|
|
|
90
114
|
"engines": {
|
|
91
115
|
"node": ">=20.19.0"
|
|
92
116
|
},
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
"pubdir": "src/cli/run.sh preparePubdir",
|
|
107
|
-
"presmoke": "pnpm run pubdir ; cd pubdir ; pnpm pack",
|
|
108
|
-
"deno:publish": "pnpm run pubdir; cd pubdir ; pnpm exec deno publish --allow-dirty --unstable-sloppy-imports",
|
|
109
|
-
"smoke": "bash ./smoke/it.sh",
|
|
110
|
-
"lint": "eslint .",
|
|
111
|
-
"prettier": "prettier .",
|
|
112
|
-
"format": "prettier ."
|
|
117
|
+
"pnpm": {
|
|
118
|
+
"ignoredBuiltDependencies": [
|
|
119
|
+
"edgedriver",
|
|
120
|
+
"geckodriver",
|
|
121
|
+
"msw",
|
|
122
|
+
"sharp"
|
|
123
|
+
],
|
|
124
|
+
"onlyBuiltDependencies": [
|
|
125
|
+
"deno",
|
|
126
|
+
"esbuild",
|
|
127
|
+
"playwright-chromium",
|
|
128
|
+
"workerd"
|
|
129
|
+
]
|
|
113
130
|
}
|
|
114
|
-
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import { command, option, string } from "cmd-ts";
|
|
3
|
+
import { createCompilerHost, readTSConfig, getVersion } from "./utils.js";
|
|
4
|
+
|
|
5
|
+
export function generateVersionTsCmd(): ReturnType<typeof command> {
|
|
6
|
+
return command({
|
|
7
|
+
name: "fireproof build cli",
|
|
8
|
+
description: "helps to build fp",
|
|
9
|
+
version: "1.0.0",
|
|
10
|
+
args: {
|
|
11
|
+
version: option({
|
|
12
|
+
long: "version",
|
|
13
|
+
short: "v",
|
|
14
|
+
defaultValue: () => getVersion(),
|
|
15
|
+
defaultValueIsSerializable: true,
|
|
16
|
+
type: string,
|
|
17
|
+
description: "Version to patch in, defaults to reading from package.json.",
|
|
18
|
+
}),
|
|
19
|
+
versionFile: option({
|
|
20
|
+
long: "versionFile",
|
|
21
|
+
short: "f",
|
|
22
|
+
defaultValue: () => "src/version.ts",
|
|
23
|
+
defaultValueIsSerializable: true,
|
|
24
|
+
type: string,
|
|
25
|
+
description: "Path to the file containing the version, defaults to './src/version.ts'.",
|
|
26
|
+
}),
|
|
27
|
+
tsconfig: option({
|
|
28
|
+
long: "tsconfig",
|
|
29
|
+
short: "t",
|
|
30
|
+
defaultValue: () => "tsconfig.json",
|
|
31
|
+
defaultValueIsSerializable: true,
|
|
32
|
+
type: string,
|
|
33
|
+
description: "Path to the tsconfig.json file, defaults to './tsconfig.json'.",
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
handler: (args) => {
|
|
37
|
+
const options = readTSConfig(args.tsconfig);
|
|
38
|
+
const host = createCompilerHost(options, args.version);
|
|
39
|
+
const program = ts.createProgram([args.versionFile], options, host);
|
|
40
|
+
program.emit();
|
|
41
|
+
},
|
|
42
|
+
}) as ReturnType<typeof command>;
|
|
43
|
+
}
|
package/src/cli/main.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { run, subcommands } from "cmd-ts";
|
|
2
|
-
import { patchVersionCmd
|
|
2
|
+
import { patchVersionCmd } from "./patch-version-cmd.js";
|
|
3
|
+
import { generateVersionTsCmd } from "./generate-version-ts-cmd.js";
|
|
4
|
+
import { setUpDenoJsonCmd } from "./setup-deno-json-cmd.js";
|
|
5
|
+
import { preparePubdirCmd } from "./prepare-pubdir-cmd.js";
|
|
6
|
+
import { publishTagsCmd } from "./publish-tags-cmd.js";
|
|
3
7
|
|
|
4
8
|
(async (): Promise<void> => {
|
|
5
9
|
const cmd = subcommands({
|
|
@@ -11,6 +15,7 @@ import { patchVersionCmd, generateVersionTsCmd, setUpDenoJsonCmd, preparePubdirC
|
|
|
11
15
|
generateVersionTs: generateVersionTsCmd(),
|
|
12
16
|
setUpDenoJson: setUpDenoJsonCmd(),
|
|
13
17
|
preparePubdir: preparePubdirCmd(),
|
|
18
|
+
publishTags: publishTagsCmd(),
|
|
14
19
|
},
|
|
15
20
|
});
|
|
16
21
|
|
|
@@ -1,117 +1,7 @@
|
|
|
1
|
-
import * as ts from "typescript";
|
|
2
1
|
import { command, option, restPositionals, string } from "cmd-ts";
|
|
3
|
-
import * as path from "node:path";
|
|
4
2
|
import * as fs from "node:fs";
|
|
5
3
|
import * as process from "node:process";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
// Custom compiler host
|
|
9
|
-
function createCompilerHost(options: ts.CompilerOptions, version: string): ts.CompilerHost {
|
|
10
|
-
const host = ts.createCompilerHost(options);
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
12
|
-
const myGetSourceFile = host.getSourceFile;
|
|
13
|
-
|
|
14
|
-
host.getSourceFile = (fileName, languageVersion, onError, shouldCreateNewSourceFile): ts.SourceFile => {
|
|
15
|
-
const sourceFile = myGetSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile);
|
|
16
|
-
if (!sourceFile) {
|
|
17
|
-
throw new Error("getSourceFile is not defined");
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Patch version.ts during compilation
|
|
21
|
-
if (fileName.endsWith("version.ts") && sourceFile) {
|
|
22
|
-
const newText = `export const VERSION: string = "${version}";`;
|
|
23
|
-
return ts.createSourceFile(fileName, newText, languageVersion);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return sourceFile;
|
|
27
|
-
};
|
|
28
|
-
return host;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function readTSConfig(configPath = "./tsconfig.json"): ts.CompilerOptions {
|
|
32
|
-
// Read the config file
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
34
|
-
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
35
|
-
|
|
36
|
-
if (configFile.error) {
|
|
37
|
-
throw new Error(`Error reading tsconfig: ${configFile.error.messageText as string}`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Parse and resolve the config
|
|
41
|
-
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath), undefined, configPath);
|
|
42
|
-
|
|
43
|
-
if (parsedConfig.errors.length > 0) {
|
|
44
|
-
const errors = parsedConfig.errors.map((err) => err.messageText as string).join("\n");
|
|
45
|
-
throw new Error(`Error parsing tsconfig: ${errors}`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return parsedConfig.options; // This is CompilerOptions
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function versionFromPackageJson(): string {
|
|
52
|
-
const packageJson = JSON.parse(fs.readFileSync("package.json").toString()) as { version: string };
|
|
53
|
-
return packageJson.version;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const versionArgs = {
|
|
57
|
-
version: option({
|
|
58
|
-
long: "version",
|
|
59
|
-
short: "v",
|
|
60
|
-
defaultValue: () => getVersion(),
|
|
61
|
-
defaultValueIsSerializable: true,
|
|
62
|
-
type: string,
|
|
63
|
-
description: "Version to patch in, defaults to reading from package.json.",
|
|
64
|
-
}),
|
|
65
|
-
versionFile: option({
|
|
66
|
-
long: "versionFile",
|
|
67
|
-
short: "f",
|
|
68
|
-
defaultValue: () => "src/version.ts",
|
|
69
|
-
defaultValueIsSerializable: true,
|
|
70
|
-
type: string,
|
|
71
|
-
description: "Path to the file containing the version, defaults to './src/version.ts'.",
|
|
72
|
-
}),
|
|
73
|
-
|
|
74
|
-
tsconfig: option({
|
|
75
|
-
long: "tsconfig",
|
|
76
|
-
short: "t",
|
|
77
|
-
defaultValue: () => "tsconfig.json",
|
|
78
|
-
defaultValueIsSerializable: true,
|
|
79
|
-
type: string,
|
|
80
|
-
description: "Path to the tsconfig.json file, defaults to './tsconfig.json'.",
|
|
81
|
-
}),
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export function generateVersionTsCmd(): ReturnType<typeof command> {
|
|
85
|
-
return command({
|
|
86
|
-
name: "fireproof build cli",
|
|
87
|
-
description: "helps to build fp",
|
|
88
|
-
version: "1.0.0",
|
|
89
|
-
args: versionArgs,
|
|
90
|
-
handler: (args) => {
|
|
91
|
-
const options = readTSConfig(args.tsconfig);
|
|
92
|
-
const host = createCompilerHost(options, args.version);
|
|
93
|
-
const program = ts.createProgram([args.versionFile], options, host);
|
|
94
|
-
program.emit();
|
|
95
|
-
},
|
|
96
|
-
}) as ReturnType<typeof command>;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function getVersion(iversion?: string): string {
|
|
100
|
-
const ghref = iversion || process.env.GITHUB_REF || versionFromPackageJson() || "a/v0.0.0-smoke";
|
|
101
|
-
let lastPart = ghref.split("/").slice(-1)[0];
|
|
102
|
-
if (iversion) {
|
|
103
|
-
return iversion.replace(/^[vdsp]/, "");
|
|
104
|
-
}
|
|
105
|
-
const short = $.sync`git rev-parse --short HEAD`.stdout.trim();
|
|
106
|
-
if (process.env.GITHUB_REF) {
|
|
107
|
-
lastPart = lastPart.replace(/^[vdsp]/, "");
|
|
108
|
-
if (lastPart.match(/^\d+\.\d+\.\d+/)) {
|
|
109
|
-
return lastPart;
|
|
110
|
-
}
|
|
111
|
-
return `0.0.0-dev-ci-${short}`;
|
|
112
|
-
}
|
|
113
|
-
return `0.0.0-dev-local-${Date.now()}`;
|
|
114
|
-
}
|
|
4
|
+
import { getVersion } from "./utils.js";
|
|
115
5
|
|
|
116
6
|
export function patchVersionCmd(): ReturnType<typeof command> {
|
|
117
7
|
return command({
|
|
@@ -145,181 +35,3 @@ export function patchVersionCmd(): ReturnType<typeof command> {
|
|
|
145
35
|
},
|
|
146
36
|
}) as ReturnType<typeof command>;
|
|
147
37
|
}
|
|
148
|
-
|
|
149
|
-
// node ./setup-jsr-json.cjs ./pubdir/deno.json
|
|
150
|
-
function setupDenoJson(packageJsonFile: string, jsrJsonFile: string): void {
|
|
151
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonFile).toString()) as { dependencies: Record<string, string> };
|
|
152
|
-
const jsrJson = JSON.parse(fs.readFileSync(jsrJsonFile).toString()) as {
|
|
153
|
-
name: string;
|
|
154
|
-
exports: Record<string, string>;
|
|
155
|
-
imports: Record<string, string>;
|
|
156
|
-
};
|
|
157
|
-
// self imports
|
|
158
|
-
const jsrJsonImports = Object.fromEntries(Object.entries(jsrJson.exports ?? {}).map(([k, v]) => [path.join(jsrJson.name, k), v]));
|
|
159
|
-
const nodeJsonImports = Object.fromEntries(
|
|
160
|
-
Array.from(Object.entries(packageJson.dependencies ?? {})).map(([k, v]) => [k, `npm:${k}@${v.replace(/^npm:/, "")}`]),
|
|
161
|
-
);
|
|
162
|
-
jsrJson.imports = { ...jsrJson.imports, ...jsrJsonImports, ...nodeJsonImports };
|
|
163
|
-
fs.writeFileSync(jsrJsonFile, JSON.stringify(jsrJson, undefined, 2) + "\n");
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export function setUpDenoJsonCmd(): ReturnType<typeof command> {
|
|
167
|
-
return command({
|
|
168
|
-
name: "setup-deno-json",
|
|
169
|
-
description: "setup deno.json",
|
|
170
|
-
version: "1.0.0",
|
|
171
|
-
args: {
|
|
172
|
-
packageJson: option({
|
|
173
|
-
long: "packageJson",
|
|
174
|
-
short: "p",
|
|
175
|
-
defaultValue: () => "package.json",
|
|
176
|
-
defaultValueIsSerializable: true,
|
|
177
|
-
type: string,
|
|
178
|
-
description: "Path to the package.json file, defaults to './package.json'.",
|
|
179
|
-
}),
|
|
180
|
-
jsrJson: option({
|
|
181
|
-
long: "jsrJson",
|
|
182
|
-
short: "j",
|
|
183
|
-
defaultValue: () => "deno.json",
|
|
184
|
-
defaultValueIsSerializable: true,
|
|
185
|
-
type: string,
|
|
186
|
-
description: "Path to the deno.json file, defaults to './deno.json'.",
|
|
187
|
-
}),
|
|
188
|
-
},
|
|
189
|
-
handler: (args) => {
|
|
190
|
-
// eslint-disable-next-line no-console
|
|
191
|
-
console.log(`Setup deno.json ${args.jsrJson} from ${args.packageJson}`);
|
|
192
|
-
setupDenoJson(args.packageJson, args.jsrJson);
|
|
193
|
-
},
|
|
194
|
-
}) as ReturnType<typeof command>;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export async function preparePubdir(pubdir: string, version: string, baseDir: string, srcDir: string): Promise<void> {
|
|
198
|
-
// Set shell options equivalent to 'set -ex'
|
|
199
|
-
$.verbose = true;
|
|
200
|
-
|
|
201
|
-
// Build if not in CI
|
|
202
|
-
if (process.env.IN_CI !== "in_ci") {
|
|
203
|
-
await $`pnpm run build`;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Clean and create pubdir
|
|
207
|
-
await $`rm -rf ${pubdir}`;
|
|
208
|
-
await $`mkdir -p ${pubdir}`;
|
|
209
|
-
|
|
210
|
-
// Copy files to pubdir
|
|
211
|
-
await $`cp -pr ${path.join(baseDir, ".gitignore")} ${path.join(baseDir, "README.md")} ${path.join(baseDir, "LICENSE")} ./dist/ts/ ${pubdir}/`;
|
|
212
|
-
|
|
213
|
-
// Copy from dist/pkg
|
|
214
|
-
cd("dist/pkg");
|
|
215
|
-
await $`cp -pr . ../../${pubdir}/`;
|
|
216
|
-
cd("../..");
|
|
217
|
-
|
|
218
|
-
// Copy from src
|
|
219
|
-
cd(srcDir);
|
|
220
|
-
await $`cp -pr . ../${pubdir}/${srcDir}/`;
|
|
221
|
-
cd("..");
|
|
222
|
-
|
|
223
|
-
// Rename .js files to .cjs in pubdir/cjs
|
|
224
|
-
const jsFiles = await glob(`${pubdir}/cjs/**/*.js`);
|
|
225
|
-
for (const file of jsFiles) {
|
|
226
|
-
const newFile = file.replace(/\.js$/, ".cjs");
|
|
227
|
-
await $`mv ${file} ${newFile}`;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Rename .js.map files to .cjs.map in pubdir/cjs
|
|
231
|
-
const mapFiles = await glob(`${pubdir}/cjs/**/*.js.map`);
|
|
232
|
-
for (const file of mapFiles) {
|
|
233
|
-
const newFile = file.replace(/\.js\.map$/, ".cjs.map");
|
|
234
|
-
await $`mv ${file} ${newFile}`;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Run jscodeshift on .cjs files
|
|
238
|
-
const cjsFiles = await glob(`${pubdir}/cjs/**/*.cjs`);
|
|
239
|
-
if (cjsFiles.length > 0) {
|
|
240
|
-
await $`pnpm exec jscodeshift --parser=babel -t=./to-cjs.js ${cjsFiles}`;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Copy package.json
|
|
244
|
-
await $`cp package.json ${pubdir}/`;
|
|
245
|
-
|
|
246
|
-
// Clean up test files in pubdir/src
|
|
247
|
-
cd(`${pubdir}/${srcDir}`);
|
|
248
|
-
await $`rm -f test/test-exit-handler.* ./utils/stream-test-helper.ts`.catch(() => {
|
|
249
|
-
// Ignore errors if files don't exist
|
|
250
|
-
});
|
|
251
|
-
cd("../..");
|
|
252
|
-
|
|
253
|
-
// Remove __screenshots__ directories
|
|
254
|
-
const screenshotDirs = await glob(`${pubdir}/${srcDir}/**/__screenshots__`);
|
|
255
|
-
for (const dir of screenshotDirs) {
|
|
256
|
-
await $`rm -rf ${dir}`;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Remove test files
|
|
260
|
-
const testFiles = await glob(`${pubdir}/${srcDir}/**/*.test.ts`);
|
|
261
|
-
for (const file of testFiles) {
|
|
262
|
-
await $`rm -f ${file}`;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// Copy deno.json
|
|
266
|
-
await $`cp ./deno.json ./${pubdir}/`;
|
|
267
|
-
|
|
268
|
-
// Patch version in package.json and deno.json
|
|
269
|
-
await patchVersionCmd().handler({ version, files: [`${pubdir}/package.json`, `${pubdir}/deno.json`] });
|
|
270
|
-
// await $`sh src/cli/run.sh patchVersion ./pubdir/package.json ./pubdir/deno.json`;
|
|
271
|
-
|
|
272
|
-
// Setup JSR JSON
|
|
273
|
-
await setUpDenoJsonCmd().handler({ packageJson: `${pubdir}/package.json`, jsrJson: `${pubdir}/deno.json` });
|
|
274
|
-
// await $`node ./setup-jsr-json.cjs ./pubdir/deno.json`;
|
|
275
|
-
|
|
276
|
-
// Pack and publish
|
|
277
|
-
cd("pubdir");
|
|
278
|
-
await $`pnpm pack`;
|
|
279
|
-
await $`deno publish --dry-run --unstable-sloppy-imports --allow-dirty`;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export function preparePubdirCmd(): ReturnType<typeof command> {
|
|
283
|
-
return command({
|
|
284
|
-
name: "prepare-pubdir",
|
|
285
|
-
description: "prepare pubdir",
|
|
286
|
-
version: "1.0.0",
|
|
287
|
-
args: {
|
|
288
|
-
pubdir: option({
|
|
289
|
-
long: "pubdir",
|
|
290
|
-
short: "p",
|
|
291
|
-
defaultValue: () => "pubdir",
|
|
292
|
-
defaultValueIsSerializable: true,
|
|
293
|
-
type: string,
|
|
294
|
-
description: "Path to the pubdir, defaults to './pubdir'.",
|
|
295
|
-
}),
|
|
296
|
-
srcDir: option({
|
|
297
|
-
long: "srcDir",
|
|
298
|
-
short: "s",
|
|
299
|
-
defaultValue: () => "src",
|
|
300
|
-
defaultValueIsSerializable: true,
|
|
301
|
-
type: string,
|
|
302
|
-
description: "Path to the src directory, defaults to './src'.",
|
|
303
|
-
}),
|
|
304
|
-
baseDir: option({
|
|
305
|
-
long: "baseDir",
|
|
306
|
-
short: "b",
|
|
307
|
-
defaultValue: () => "../",
|
|
308
|
-
defaultValueIsSerializable: true,
|
|
309
|
-
type: string,
|
|
310
|
-
description: "Path to the base directory of the project, defaults to '../'.",
|
|
311
|
-
}),
|
|
312
|
-
version: option({
|
|
313
|
-
long: "version",
|
|
314
|
-
short: "v",
|
|
315
|
-
defaultValue: () => getVersion(),
|
|
316
|
-
defaultValueIsSerializable: true,
|
|
317
|
-
type: string,
|
|
318
|
-
description: "Version to patch in, defaults to reading from package.json.",
|
|
319
|
-
}),
|
|
320
|
-
},
|
|
321
|
-
handler: async (args) => {
|
|
322
|
-
await preparePubdir(args.pubdir, args.version, args.baseDir, args.srcDir);
|
|
323
|
-
},
|
|
324
|
-
}) as ReturnType<typeof command>;
|
|
325
|
-
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { command, option, string } from "cmd-ts";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import * as process from "node:process";
|
|
4
|
+
import { $, cd, glob } from "zx";
|
|
5
|
+
import { getVersion } from "./utils.js";
|
|
6
|
+
import { setUpDenoJsonCmd } from "./setup-deno-json-cmd.js";
|
|
7
|
+
import { patchVersionCmd } from "./patch-version-cmd.js";
|
|
8
|
+
|
|
9
|
+
function disableVerbose(fn: () => Promise<void>): Promise<void> {
|
|
10
|
+
const verbose = $.verbose;
|
|
11
|
+
$.verbose = false;
|
|
12
|
+
return fn().finally(() => {
|
|
13
|
+
$.verbose = verbose;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function preparePubdir(pubdir: string, version: string, baseDir: string, srcDir: string): Promise<void> {
|
|
18
|
+
// Set shell options equivalent to 'set -ex'
|
|
19
|
+
$.verbose = true;
|
|
20
|
+
|
|
21
|
+
// Build if not in CI
|
|
22
|
+
if (process.env.IN_CI !== "in_ci") {
|
|
23
|
+
await $`pnpm run build`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Clean and create pubdir
|
|
27
|
+
await $`rm -rf ${pubdir}`;
|
|
28
|
+
await $`mkdir -p ${pubdir}`;
|
|
29
|
+
|
|
30
|
+
// Copy files to pubdir
|
|
31
|
+
await $`cp -pr ${path.join(baseDir, ".gitignore")} ${path.join(baseDir, "README.md")} ${path.join(baseDir, "LICENSE")} ./dist/ts/ ${pubdir}/`;
|
|
32
|
+
|
|
33
|
+
// Copy from dist/pkg
|
|
34
|
+
cd("dist/pkg");
|
|
35
|
+
await $`cp -pr . ../../${pubdir}/`;
|
|
36
|
+
cd("../..");
|
|
37
|
+
|
|
38
|
+
// Copy from src
|
|
39
|
+
cd(srcDir);
|
|
40
|
+
await $`cp -pr . ../${pubdir}/${srcDir}/`;
|
|
41
|
+
cd("..");
|
|
42
|
+
|
|
43
|
+
// Rename .js files to .cjs in pubdir/cjs
|
|
44
|
+
const jsFiles = await glob(`${pubdir}/cjs/**/*.js`);
|
|
45
|
+
|
|
46
|
+
await disableVerbose(async () => {
|
|
47
|
+
for (const file of jsFiles) {
|
|
48
|
+
const newFile = file.replace(/\.js$/, ".cjs");
|
|
49
|
+
await $`mv ${file} ${newFile}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Rename .js.map files to .cjs.map in pubdir/cjs
|
|
53
|
+
const mapFiles = await glob(`${pubdir}/cjs/**/*.js.map`);
|
|
54
|
+
for (const file of mapFiles) {
|
|
55
|
+
const newFile = file.replace(/\.js\.map$/, ".cjs.map");
|
|
56
|
+
await $`mv ${file} ${newFile}`;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Run jscodeshift on .cjs files
|
|
61
|
+
const cjsFiles = await glob(`${pubdir}/cjs/**/*.cjs`);
|
|
62
|
+
if (cjsFiles.length > 0) {
|
|
63
|
+
await $`pnpm exec jscodeshift -s --parser=babel -t=./to-cjs.js ${cjsFiles}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Copy package.json
|
|
67
|
+
await $`cp package.json ${pubdir}/`;
|
|
68
|
+
|
|
69
|
+
// Clean up test files in pubdir/src
|
|
70
|
+
cd(`${pubdir}/${srcDir}`);
|
|
71
|
+
await $`rm -f test/test-exit-handler.* ./utils/stream-test-helper.ts`.catch(() => {
|
|
72
|
+
// Ignore errors if files don't exist
|
|
73
|
+
});
|
|
74
|
+
cd("../..");
|
|
75
|
+
|
|
76
|
+
// Remove __screenshots__ directories
|
|
77
|
+
const screenshotDirs = await glob(`${pubdir}/${srcDir}/**/__screenshots__`);
|
|
78
|
+
for (const dir of screenshotDirs) {
|
|
79
|
+
await $`rm -rf ${dir}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Remove test files
|
|
83
|
+
await disableVerbose(async () => {
|
|
84
|
+
const testFiles = await glob(`${pubdir}/${srcDir}/**/*.test.ts`);
|
|
85
|
+
for (const file of testFiles) {
|
|
86
|
+
await $`rm -f ${file}`;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Copy tsconfig.json
|
|
91
|
+
await $`cp ./tsconfig.json ./${pubdir}/`;
|
|
92
|
+
|
|
93
|
+
// Copy deno.json
|
|
94
|
+
await $`cp ./deno.json ./${pubdir}/`;
|
|
95
|
+
|
|
96
|
+
// Patch version in package.json and deno.json
|
|
97
|
+
await patchVersionCmd().handler({ version, files: [`${pubdir}/package.json`, `${pubdir}/deno.json`] });
|
|
98
|
+
// await $`sh src/cli/run.sh patchVersion ./pubdir/package.json ./pubdir/deno.json`;
|
|
99
|
+
|
|
100
|
+
// Setup JSR JSON
|
|
101
|
+
await setUpDenoJsonCmd().handler({ packageJson: `${pubdir}/package.json`, jsrJson: `${pubdir}/deno.json` });
|
|
102
|
+
// await $`node ./setup-jsr-json.cjs ./pubdir/deno.json`;
|
|
103
|
+
|
|
104
|
+
// Pack and publish
|
|
105
|
+
cd("pubdir");
|
|
106
|
+
await $`pnpm pack 2>&1 | head -10 && echo "..."`;
|
|
107
|
+
await $`deno publish --dry-run --unstable-sloppy-imports --allow-dirty --quiet`;
|
|
108
|
+
|
|
109
|
+
// eslint-disable-next-line no-console
|
|
110
|
+
console.log(`Prepared ${pubdir} for version ${version}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function preparePubdirCmd(): ReturnType<typeof command> {
|
|
114
|
+
return command({
|
|
115
|
+
name: "prepare-pubdir",
|
|
116
|
+
description: "prepare pubdir",
|
|
117
|
+
version: "1.0.0",
|
|
118
|
+
args: {
|
|
119
|
+
pubdir: option({
|
|
120
|
+
long: "pubdir",
|
|
121
|
+
short: "p",
|
|
122
|
+
defaultValue: () => "pubdir",
|
|
123
|
+
defaultValueIsSerializable: true,
|
|
124
|
+
type: string,
|
|
125
|
+
description: "Path to the pubdir, defaults to './pubdir'.",
|
|
126
|
+
}),
|
|
127
|
+
srcDir: option({
|
|
128
|
+
long: "srcDir",
|
|
129
|
+
short: "s",
|
|
130
|
+
defaultValue: () => "src",
|
|
131
|
+
defaultValueIsSerializable: true,
|
|
132
|
+
type: string,
|
|
133
|
+
description: "Path to the src directory, defaults to './src'.",
|
|
134
|
+
}),
|
|
135
|
+
baseDir: option({
|
|
136
|
+
long: "baseDir",
|
|
137
|
+
short: "b",
|
|
138
|
+
defaultValue: () => "../",
|
|
139
|
+
defaultValueIsSerializable: true,
|
|
140
|
+
type: string,
|
|
141
|
+
description: "Path to the base directory of the project, defaults to '../'.",
|
|
142
|
+
}),
|
|
143
|
+
version: option({
|
|
144
|
+
long: "version",
|
|
145
|
+
short: "v",
|
|
146
|
+
defaultValue: () => getVersion(),
|
|
147
|
+
defaultValueIsSerializable: true,
|
|
148
|
+
type: string,
|
|
149
|
+
description: "Version to patch in, defaults to reading from package.json.",
|
|
150
|
+
}),
|
|
151
|
+
},
|
|
152
|
+
handler: async (args) => {
|
|
153
|
+
await preparePubdir(args.pubdir, args.version, args.baseDir, args.srcDir);
|
|
154
|
+
},
|
|
155
|
+
}) as ReturnType<typeof command>;
|
|
156
|
+
}
|