@xylabs/ts-scripts-yarn3 2.20.0-rc.1 → 3.0.0-rc.1
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/dist/actions/build.mjs +133 -0
- package/dist/actions/build.mjs.map +1 -0
- package/dist/actions/clean-docs.mjs +29 -0
- package/dist/actions/clean-docs.mjs.map +1 -0
- package/dist/actions/clean-eslint.mjs +15 -0
- package/dist/actions/clean-eslint.mjs.map +1 -0
- package/dist/actions/clean-jest.mjs +100 -0
- package/dist/actions/clean-jest.mjs.map +1 -0
- package/dist/actions/clean.mjs +210 -0
- package/dist/actions/clean.mjs.map +1 -0
- package/dist/actions/compile.mjs +124 -0
- package/dist/actions/compile.mjs.map +1 -0
- package/dist/actions/copy-assets.mjs +71 -0
- package/dist/actions/copy-assets.mjs.map +1 -0
- package/dist/actions/cycle.mjs +100 -0
- package/dist/actions/cycle.mjs.map +1 -0
- package/dist/actions/dead.mjs +99 -0
- package/dist/actions/dead.mjs.map +1 -0
- package/dist/actions/deploy-major.mjs +106 -0
- package/dist/actions/deploy-major.mjs.map +1 -0
- package/dist/actions/deploy-minor.mjs +106 -0
- package/dist/actions/deploy-minor.mjs.map +1 -0
- package/dist/actions/deploy-next.mjs +106 -0
- package/dist/actions/deploy-next.mjs.map +1 -0
- package/dist/actions/deploy.mjs +107 -0
- package/dist/actions/deploy.mjs.map +1 -0
- package/dist/actions/deps.mjs +121 -0
- package/dist/actions/deps.mjs.map +1 -0
- package/dist/actions/dupdeps.mjs +181 -0
- package/dist/actions/dupdeps.mjs.map +1 -0
- package/dist/actions/fix.mjs +99 -0
- package/dist/actions/fix.mjs.map +1 -0
- package/dist/actions/gen-docs.mjs +110 -0
- package/dist/actions/gen-docs.mjs.map +1 -0
- package/dist/actions/gitignore-gen.mjs +87 -0
- package/dist/actions/gitignore-gen.mjs.map +1 -0
- package/dist/actions/gitlint-fix.mjs +27 -0
- package/dist/actions/gitlint-fix.mjs.map +1 -0
- package/dist/actions/gitlint.mjs +48 -0
- package/dist/actions/gitlint.mjs.map +1 -0
- package/dist/actions/index.mjs +1405 -0
- package/dist/actions/index.mjs.map +1 -0
- package/dist/actions/license.mjs +87 -0
- package/dist/actions/license.mjs.map +1 -0
- package/dist/actions/lint-clean.mjs +147 -0
- package/dist/actions/lint-clean.mjs.map +1 -0
- package/dist/actions/lint-profile.mjs +99 -0
- package/dist/actions/lint-profile.mjs.map +1 -0
- package/dist/actions/lint.mjs +137 -0
- package/dist/actions/lint.mjs.map +1 -0
- package/dist/actions/npmignore-gen.mjs +87 -0
- package/dist/actions/npmignore-gen.mjs.map +1 -0
- package/dist/actions/package/clean-outputs.mjs +18 -0
- package/dist/actions/package/clean-outputs.mjs.map +1 -0
- package/dist/actions/package/clean-typescript.mjs +18 -0
- package/dist/actions/package/clean-typescript.mjs.map +1 -0
- package/dist/actions/package/clean.mjs +38 -0
- package/dist/actions/package/clean.mjs.map +1 -0
- package/dist/actions/package/compile.mjs +63 -0
- package/dist/actions/package/compile.mjs.map +1 -0
- package/dist/actions/package/copy-assets.mjs +43 -0
- package/dist/actions/package/copy-assets.mjs.map +1 -0
- package/dist/actions/package/deps.mjs +96 -0
- package/dist/actions/package/deps.mjs.map +1 -0
- package/dist/actions/package/gen-docs.mjs +112 -0
- package/dist/actions/package/gen-docs.mjs.map +1 -0
- package/dist/actions/package/index.mjs +400 -0
- package/dist/actions/package/index.mjs.map +1 -0
- package/dist/actions/package/publint.mjs +21 -0
- package/dist/actions/package/publint.mjs.map +1 -0
- package/dist/actions/package/recompile.mjs +103 -0
- package/dist/actions/package/recompile.mjs.map +1 -0
- package/dist/actions/package/tsup.mjs +31 -0
- package/dist/actions/package/tsup.mjs.map +1 -0
- package/dist/actions/package/types.d.js +2 -0
- package/dist/actions/package/types.d.js.map +1 -0
- package/dist/actions/package/types.d.mjs +1 -0
- package/dist/actions/package/types.d.mjs.map +1 -0
- package/dist/actions/publint.mjs +168 -0
- package/dist/actions/publint.mjs.map +1 -0
- package/dist/actions/rebuild.mjs +102 -0
- package/dist/actions/rebuild.mjs.map +1 -0
- package/dist/actions/recompile.mjs +140 -0
- package/dist/actions/recompile.mjs.map +1 -0
- package/dist/actions/reinstall.mjs +130 -0
- package/dist/actions/reinstall.mjs.map +1 -0
- package/dist/actions/relint.mjs +128 -0
- package/dist/actions/relint.mjs.map +1 -0
- package/dist/actions/retest.mjs +102 -0
- package/dist/actions/retest.mjs.map +1 -0
- package/dist/actions/sonar.mjs +99 -0
- package/dist/actions/sonar.mjs.map +1 -0
- package/dist/actions/statics.mjs +181 -0
- package/dist/actions/statics.mjs.map +1 -0
- package/dist/actions/test.mjs +99 -0
- package/dist/actions/test.mjs.map +1 -0
- package/dist/actions/up.mjs +99 -0
- package/dist/actions/up.mjs.map +1 -0
- package/dist/actions/updo.mjs +103 -0
- package/dist/actions/updo.mjs.map +1 -0
- package/dist/actions/upplug.mjs +104 -0
- package/dist/actions/upplug.mjs.map +1 -0
- package/dist/actions/upyarn.mjs +99 -0
- package/dist/actions/upyarn.mjs.map +1 -0
- package/dist/actions/yarn3only.mjs +60 -0
- package/dist/actions/yarn3only.mjs.map +1 -0
- package/dist/bin/build.mjs +13 -0
- package/dist/bin/build.mjs.map +1 -0
- package/dist/bin/clean.mjs +13 -0
- package/dist/bin/clean.mjs.map +1 -0
- package/dist/bin/compile.mjs +13 -0
- package/dist/bin/compile.mjs.map +1 -0
- package/dist/bin/cycle.mjs +13 -0
- package/dist/bin/cycle.mjs.map +1 -0
- package/dist/bin/dead.mjs +13 -0
- package/dist/bin/dead.mjs.map +1 -0
- package/dist/bin/deploy-major.mjs +13 -0
- package/dist/bin/deploy-major.mjs.map +1 -0
- package/dist/bin/deploy-minor.mjs +13 -0
- package/dist/bin/deploy-minor.mjs.map +1 -0
- package/dist/bin/deploy-next.mjs +13 -0
- package/dist/bin/deploy-next.mjs.map +1 -0
- package/dist/bin/deploy.mjs +13 -0
- package/dist/bin/deploy.mjs.map +1 -0
- package/dist/bin/deps.mjs +13 -0
- package/dist/bin/deps.mjs.map +1 -0
- package/dist/bin/fix.mjs +13 -0
- package/dist/bin/fix.mjs.map +1 -0
- package/dist/bin/gen-docs.mjs +13 -0
- package/dist/bin/gen-docs.mjs.map +1 -0
- package/dist/bin/gitlint-fix.mjs +13 -0
- package/dist/bin/gitlint-fix.mjs.map +1 -0
- package/dist/bin/gitlint.mjs +13 -0
- package/dist/bin/gitlint.mjs.map +1 -0
- package/dist/bin/license.mjs +13 -0
- package/dist/bin/license.mjs.map +1 -0
- package/dist/bin/lint-clean.mjs +13 -0
- package/dist/bin/lint-clean.mjs.map +1 -0
- package/dist/bin/lint-fast.mjs +13 -0
- package/dist/bin/lint-fast.mjs.map +1 -0
- package/dist/bin/lint-profile.mjs +13 -0
- package/dist/bin/lint-profile.mjs.map +1 -0
- package/dist/bin/lint.mjs +13 -0
- package/dist/bin/lint.mjs.map +1 -0
- package/dist/bin/package/clean-outputs.mjs +20 -0
- package/dist/bin/package/clean-outputs.mjs.map +1 -0
- package/dist/bin/package/clean-typescript.mjs +20 -0
- package/dist/bin/package/clean-typescript.mjs.map +1 -0
- package/dist/bin/package/clean.mjs +40 -0
- package/dist/bin/package/clean.mjs.map +1 -0
- package/dist/bin/package/compile.mjs +71 -0
- package/dist/bin/package/compile.mjs.map +1 -0
- package/dist/bin/package/copy-assets-cjs.mjs +51 -0
- package/dist/bin/package/copy-assets-cjs.mjs.map +1 -0
- package/dist/bin/package/copy-assets-esm.mjs +51 -0
- package/dist/bin/package/copy-assets-esm.mjs.map +1 -0
- package/dist/bin/package/deps.mjs +102 -0
- package/dist/bin/package/deps.mjs.map +1 -0
- package/dist/bin/package/gen-docs.mjs +114 -0
- package/dist/bin/package/gen-docs.mjs.map +1 -0
- package/dist/bin/package/publint.mjs +29 -0
- package/dist/bin/package/publint.mjs.map +1 -0
- package/dist/bin/package/recompile.mjs +111 -0
- package/dist/bin/package/recompile.mjs.map +1 -0
- package/dist/bin/package/tsup.mjs +39 -0
- package/dist/bin/package/tsup.mjs.map +1 -0
- package/dist/bin/publint.mjs +13 -0
- package/dist/bin/publint.mjs.map +1 -0
- package/dist/bin/rebuild.mjs +13 -0
- package/dist/bin/rebuild.mjs.map +1 -0
- package/dist/bin/recompile.mjs +13 -0
- package/dist/bin/recompile.mjs.map +1 -0
- package/dist/bin/reinstall.mjs +13 -0
- package/dist/bin/reinstall.mjs.map +1 -0
- package/dist/bin/relint.mjs +13 -0
- package/dist/bin/relint.mjs.map +1 -0
- package/dist/bin/sonar.mjs +13 -0
- package/dist/bin/sonar.mjs.map +1 -0
- package/dist/bin/test.mjs +13 -0
- package/dist/bin/test.mjs.map +1 -0
- package/dist/bin/tsconfig-gen-clean.mjs +13 -0
- package/dist/bin/tsconfig-gen-clean.mjs.map +1 -0
- package/dist/bin/tsconfig-gen.mjs +13 -0
- package/dist/bin/tsconfig-gen.mjs.map +1 -0
- package/dist/bin/up.mjs +13 -0
- package/dist/bin/up.mjs.map +1 -0
- package/dist/bin/updo.mjs +13 -0
- package/dist/bin/updo.mjs.map +1 -0
- package/dist/bin/upplug.mjs +13 -0
- package/dist/bin/upplug.mjs.map +1 -0
- package/dist/bin/upyarn.mjs +13 -0
- package/dist/bin/upyarn.mjs.map +1 -0
- package/dist/bin/xy-ts.mjs +1465 -0
- package/dist/bin/xy-ts.mjs.map +1 -0
- package/dist/bin/xy.mjs +1465 -0
- package/dist/bin/xy.mjs.map +1 -0
- package/dist/bin/yarn3only.mjs +13 -0
- package/dist/bin/yarn3only.mjs.map +1 -0
- package/dist/index.d.mts +299 -0
- package/dist/index.mjs +2024 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/checkResult.mjs +16 -0
- package/dist/lib/checkResult.mjs.map +1 -0
- package/dist/lib/createBuildConfig.mjs +45 -0
- package/dist/lib/createBuildConfig.mjs.map +1 -0
- package/dist/lib/defaultBuildConfig.mjs +13 -0
- package/dist/lib/defaultBuildConfig.mjs.map +1 -0
- package/dist/lib/dependencies/DuplicateDetector.mjs +77 -0
- package/dist/lib/dependencies/DuplicateDetector.mjs.map +1 -0
- package/dist/lib/dependencies/detectDuplicateDependencies.mjs +162 -0
- package/dist/lib/dependencies/detectDuplicateDependencies.mjs.map +1 -0
- package/dist/lib/dependencies/index.mjs +163 -0
- package/dist/lib/dependencies/index.mjs.map +1 -0
- package/dist/lib/file/ReadFileSyncOptions.mjs +6 -0
- package/dist/lib/file/ReadFileSyncOptions.mjs.map +1 -0
- package/dist/lib/file/constants.mjs +8 -0
- package/dist/lib/file/constants.mjs.map +1 -0
- package/dist/lib/file/fileLines.mjs +29 -0
- package/dist/lib/file/fileLines.mjs.map +1 -0
- package/dist/lib/file/index.mjs +39 -0
- package/dist/lib/file/index.mjs.map +1 -0
- package/dist/lib/file/tryReadFileSync.mjs +14 -0
- package/dist/lib/file/tryReadFileSync.mjs.map +1 -0
- package/dist/lib/generateIgnoreFiles.mjs +83 -0
- package/dist/lib/generateIgnoreFiles.mjs.map +1 -0
- package/dist/lib/index.mjs +1562 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/lib/jsonFormatters.mjs +11 -0
- package/dist/lib/jsonFormatters.mjs.map +1 -0
- package/dist/lib/parsedPackageJSON.mjs +11 -0
- package/dist/lib/parsedPackageJSON.mjs.map +1 -0
- package/dist/lib/processEx.mjs +36 -0
- package/dist/lib/processEx.mjs.map +1 -0
- package/dist/lib/runSteps.mjs +96 -0
- package/dist/lib/runSteps.mjs.map +1 -0
- package/dist/lib/runStepsAsync.mjs +113 -0
- package/dist/lib/runStepsAsync.mjs.map +1 -0
- package/dist/lib/runXy.mjs +101 -0
- package/dist/lib/runXy.mjs.map +1 -0
- package/dist/lib/runXyWithWarning.mjs +11 -0
- package/dist/lib/runXyWithWarning.mjs.map +1 -0
- package/dist/lib/safeExit.mjs +61 -0
- package/dist/lib/safeExit.mjs.map +1 -0
- package/dist/lib/string/empty.mjs +8 -0
- package/dist/lib/string/empty.mjs.map +1 -0
- package/dist/lib/string/index.mjs +12 -0
- package/dist/lib/string/index.mjs.map +1 -0
- package/dist/lib/string/union.mjs +6 -0
- package/dist/lib/string/union.mjs.map +1 -0
- package/dist/lib/withErrnoException.mjs +13 -0
- package/dist/lib/withErrnoException.mjs.map +1 -0
- package/dist/lib/withError.mjs +8 -0
- package/dist/lib/withError.mjs.map +1 -0
- package/dist/lib/xy/index.mjs +1471 -0
- package/dist/lib/xy/index.mjs.map +1 -0
- package/dist/lib/xy/xy.mjs +1465 -0
- package/dist/lib/xy/xy.mjs.map +1 -0
- package/dist/lib/xy/xyBuildCommands.mjs +393 -0
- package/dist/lib/xy/xyBuildCommands.mjs.map +1 -0
- package/dist/lib/xy/xyCommonCommands.mjs +579 -0
- package/dist/lib/xy/xyCommonCommands.mjs.map +1 -0
- package/dist/lib/xy/xyDeployCommands.mjs +192 -0
- package/dist/lib/xy/xyDeployCommands.mjs.map +1 -0
- package/dist/lib/xy/xyInstallCommands.mjs +459 -0
- package/dist/lib/xy/xyInstallCommands.mjs.map +1 -0
- package/dist/lib/xy/xyLintCommands.mjs +334 -0
- package/dist/lib/xy/xyLintCommands.mjs.map +1 -0
- package/dist/lib/xy/xyParseOptions.mjs +45 -0
- package/dist/lib/xy/xyParseOptions.mjs.map +1 -0
- package/dist/lib/yarn/index.mjs +49 -0
- package/dist/lib/yarn/index.mjs.map +1 -0
- package/dist/lib/yarn/isYarnVersionOrGreater.mjs +18 -0
- package/dist/lib/yarn/isYarnVersionOrGreater.mjs.map +1 -0
- package/dist/lib/yarn/workspace/Workspace.mjs +1 -0
- package/dist/lib/yarn/workspace/Workspace.mjs.map +1 -0
- package/dist/lib/yarn/workspace/index.mjs +25 -0
- package/dist/lib/yarn/workspace/index.mjs.map +1 -0
- package/dist/lib/yarn/workspace/yarnWorkspace.mjs +24 -0
- package/dist/lib/yarn/workspace/yarnWorkspace.mjs.map +1 -0
- package/dist/lib/yarn/workspace/yarnWorkspaces.mjs +16 -0
- package/dist/lib/yarn/workspace/yarnWorkspaces.mjs.map +1 -0
- package/dist/lib/yarn/yarnInitCwd.mjs +10 -0
- package/dist/lib/yarn/yarnInitCwd.mjs.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// src/actions/compile.ts
|
|
2
|
+
import chalk4 from "chalk";
|
|
3
|
+
|
|
4
|
+
// src/lib/checkResult.ts
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
var checkResult = (name, result, level = "error", exitOnFail = false) => {
|
|
7
|
+
if (result) {
|
|
8
|
+
const exiting = exitOnFail ? "[Exiting Process]" : "[Continuing]";
|
|
9
|
+
const chalkFunc = level === "error" ? chalk.red : chalk.yellow;
|
|
10
|
+
console[level](chalkFunc(`${name} had ${result} failures ${exiting}`));
|
|
11
|
+
if (exitOnFail) {
|
|
12
|
+
process.exit(result);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/lib/processEx.ts
|
|
18
|
+
import chalk2 from "chalk";
|
|
19
|
+
|
|
20
|
+
// src/lib/withError.ts
|
|
21
|
+
var withError = (ex, closure, predicate = (ex2) => ex2.name !== void 0 && ex2.message !== void 0) => {
|
|
22
|
+
return predicate(ex) ? closure(ex) : void 0;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// src/lib/withErrnoException.ts
|
|
26
|
+
var withErrnoException = (ex, closure) => {
|
|
27
|
+
return withError(ex, closure, (ex2) => ex2.errno !== void 0);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// src/lib/processEx.ts
|
|
31
|
+
var processEx = (ex) => {
|
|
32
|
+
const error = typeof ex === "string" ? Error(ex) : ex;
|
|
33
|
+
const exitCode = withErrnoException(error, (error2) => {
|
|
34
|
+
if (error2.code === "ENOENT") {
|
|
35
|
+
console.error(chalk2.red(`'${error2.path}' not found.`));
|
|
36
|
+
} else {
|
|
37
|
+
console.error(chalk2.red(`Errno: ${error2.code}`));
|
|
38
|
+
}
|
|
39
|
+
return error2.errno ?? -1;
|
|
40
|
+
}) ?? withError(error, (error2) => {
|
|
41
|
+
console.error(chalk2.red(`${error2.name}: ${error2.message}`));
|
|
42
|
+
return -1;
|
|
43
|
+
}) ?? (() => {
|
|
44
|
+
console.error(chalk2.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`));
|
|
45
|
+
return -1;
|
|
46
|
+
})();
|
|
47
|
+
process.exit(process.exitCode ?? exitCode);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/lib/safeExit.ts
|
|
51
|
+
var safeExit = (func, exitOnFail = true) => {
|
|
52
|
+
try {
|
|
53
|
+
const result = func();
|
|
54
|
+
if (result && exitOnFail) {
|
|
55
|
+
process.exit(result);
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
} catch (ex) {
|
|
59
|
+
return processEx(ex);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/lib/runSteps.ts
|
|
64
|
+
import chalk3 from "chalk";
|
|
65
|
+
import { spawnSync } from "child_process";
|
|
66
|
+
import { existsSync } from "fs";
|
|
67
|
+
var runSteps = (name, steps, exitOnFail = true, messages) => {
|
|
68
|
+
return safeExit(() => {
|
|
69
|
+
const pkgName = process.env.npm_package_name;
|
|
70
|
+
console.log(chalk3.green(`${name} [${pkgName}]`));
|
|
71
|
+
let totalStatus = 0;
|
|
72
|
+
for (let i = 0; i < steps.length; i++) {
|
|
73
|
+
const [command, args, config] = steps[i];
|
|
74
|
+
if (messages?.[i]) {
|
|
75
|
+
console.log(chalk3.gray(messages?.[i]));
|
|
76
|
+
}
|
|
77
|
+
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
78
|
+
if (command === "node" && !existsSync(argList[0])) {
|
|
79
|
+
throw Error(`File not found [${argList[0]}]`);
|
|
80
|
+
}
|
|
81
|
+
const status = spawnSync(command, Array.isArray(args) ? args : args.split(" "), {
|
|
82
|
+
...config,
|
|
83
|
+
encoding: "utf8",
|
|
84
|
+
env: { FORCE_COLOR: "3", ...process.env },
|
|
85
|
+
shell: true,
|
|
86
|
+
stdio: "inherit"
|
|
87
|
+
}).status ?? 0;
|
|
88
|
+
checkResult(name, status, "error", exitOnFail);
|
|
89
|
+
totalStatus += status ?? 0;
|
|
90
|
+
}
|
|
91
|
+
return totalStatus;
|
|
92
|
+
}, !!exitOnFail);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/actions/compile.ts
|
|
96
|
+
var compile = ({ verbose, target, pkg, incremental }) => {
|
|
97
|
+
return pkg ? compilePackage({ pkg, target, verbose }) : compileAll({ incremental, target, verbose });
|
|
98
|
+
};
|
|
99
|
+
var compilePackage = ({ verbose, target, pkg }) => {
|
|
100
|
+
const verboseOptions = verbose ? ["-v"] : [];
|
|
101
|
+
const targetOptions = target ? ["-t", target] : [];
|
|
102
|
+
return runSteps(`Compile [${pkg}]`, [["yarn", ["workspace", pkg, "run", "package-compile", ...verboseOptions, ...targetOptions]]]);
|
|
103
|
+
};
|
|
104
|
+
var compileAll = ({ jobs, verbose, target, incremental }) => {
|
|
105
|
+
const start = Date.now();
|
|
106
|
+
const verboseOptions = verbose ? ["-v"] : [];
|
|
107
|
+
const targetOptions = target ? ["-t", target] : [];
|
|
108
|
+
const incrementalOptions = incremental ? ["--since", "-ptA"] : ["-ptA"];
|
|
109
|
+
const jobsOptions = jobs ? ["-j", `${jobs}`] : [];
|
|
110
|
+
if (jobs) {
|
|
111
|
+
console.log(chalk4.blue(`Jobs set to [${jobs}]`));
|
|
112
|
+
}
|
|
113
|
+
const result = runSteps(`Compile${incremental ? "-Incremental" : ""} [All]`, [
|
|
114
|
+
["yarn", ["workspaces", "foreach", ...incrementalOptions, ...jobsOptions, "run", "package-compile", ...verboseOptions, ...targetOptions]]
|
|
115
|
+
]);
|
|
116
|
+
console.log(`${chalk4.gray("Compiled in")} [${chalk4.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk4.gray("seconds")}`);
|
|
117
|
+
return result;
|
|
118
|
+
};
|
|
119
|
+
export {
|
|
120
|
+
compile,
|
|
121
|
+
compileAll,
|
|
122
|
+
compilePackage
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=compile.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/actions/compile.ts","../../src/lib/checkResult.ts","../../src/lib/processEx.ts","../../src/lib/withError.ts","../../src/lib/withErrnoException.ts","../../src/lib/safeExit.ts","../../src/lib/runSteps.ts"],"sourcesContent":["import chalk from 'chalk'\n\nimport { runSteps } from '../lib'\n\nexport interface CompileParams {\n incremental?: boolean\n jobs?: number\n pkg?: string\n target?: 'esm' | 'cjs'\n verbose?: boolean\n}\n\nexport interface CompilePackageParams {\n pkg: string\n target?: 'esm' | 'cjs'\n verbose?: boolean\n}\n\nexport const compile = ({ verbose, target, pkg, incremental }: CompileParams) => {\n return pkg ? compilePackage({ pkg, target, verbose }) : compileAll({ incremental, target, verbose })\n}\n\nexport const compilePackage = ({ verbose, target, pkg }: CompilePackageParams) => {\n const verboseOptions = verbose ? ['-v'] : []\n const targetOptions = target ? ['-t', target] : []\n\n return runSteps(`Compile [${pkg}]`, [['yarn', ['workspace', pkg, 'run', 'package-compile', ...verboseOptions, ...targetOptions]]])\n}\n\nexport const compileAll = ({ jobs, verbose, target, incremental }: CompileParams) => {\n const start = Date.now()\n const verboseOptions = verbose ? ['-v'] : []\n const targetOptions = target ? ['-t', target] : []\n const incrementalOptions = incremental ? ['--since', '-ptA'] : ['-ptA']\n const jobsOptions = jobs ? ['-j', `${jobs}`] : []\n if (jobs) {\n console.log(chalk.blue(`Jobs set to [${jobs}]`))\n }\n\n const result = runSteps(`Compile${incremental ? '-Incremental' : ''} [All]`, [\n ['yarn', ['workspaces', 'foreach', ...incrementalOptions, ...jobsOptions, 'run', 'package-compile', ...verboseOptions, ...targetOptions]],\n ])\n console.log(`${chalk.gray('Compiled in')} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`)\n return result\n}\n","import chalk from 'chalk'\n\nexport const checkResult = (name: string, result: number, level: 'error' | 'warn' = 'error', exitOnFail = false) => {\n if (result) {\n const exiting = exitOnFail ? '[Exiting Process]' : '[Continuing]'\n const chalkFunc = level === 'error' ? chalk.red : chalk.yellow\n console[level](chalkFunc(`${name} had ${result} failures ${exiting}`))\n if (exitOnFail) {\n process.exit(result)\n }\n }\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException'\nimport { withError } from './withError'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const processEx = (ex: any) => {\n const error = typeof ex === 'string' ? Error(ex) : ex\n const exitCode =\n withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n }) ??\n withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n }) ??\n (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n //This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => ex.name !== undefined && ex.message !== undefined,\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { withError } from './withError'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(ex: any, closure: (error: T) => number) => {\n return withError<T>(ex, closure, (ex: any) => ex.errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import chalk from 'chalk'\nimport { spawnSync, SpawnSyncOptionsWithBufferEncoding } from 'child_process'\nimport { existsSync } from 'fs'\n\nimport { checkResult } from './checkResult'\nimport { safeExit } from './safeExit'\n\nexport type ScriptStep =\n | [/*command*/ 'yarn' | 'node' | 'ts-node-script' | 'tsc' | 'jest', /*arg*/ string | string[]]\n | [/*command*/ string, /*arg*/ string | string[], /*config*/ SpawnSyncOptionsWithBufferEncoding]\n\nexport const runSteps = (name: string, steps: ScriptStep[], exitOnFail = true, messages?: string[]): number => {\n return safeExit(() => {\n const pkgName = process.env.npm_package_name\n console.log(chalk.green(`${name} [${pkgName}]`))\n let totalStatus = 0\n for (let i = 0; i < steps.length; i++) {\n const [command, args, config] = steps[i]\n if (messages?.[i]) {\n console.log(chalk.gray(messages?.[i]))\n }\n const argList = Array.isArray(args) ? args : args.split(' ')\n if (command === 'node' && !existsSync(argList[0])) {\n throw Error(`File not found [${argList[0]}]`)\n }\n const status =\n spawnSync(command, Array.isArray(args) ? args : args.split(' '), {\n ...config,\n encoding: 'utf8',\n env: { FORCE_COLOR: '3', ...process.env },\n shell: true,\n stdio: 'inherit',\n }).status ?? 0\n checkResult(name, status, 'error', exitOnFail)\n totalStatus += status ?? 0\n }\n return totalStatus\n }, !!exitOnFail)\n}\n"],"mappings":";AAAA,OAAOA,YAAW;;;ACAlB,OAAO,WAAW;AAEX,IAAM,cAAc,CAAC,MAAc,QAAgB,QAA0B,SAAS,aAAa,UAAU;AAClH,MAAI,QAAQ;AACV,UAAM,UAAU,aAAa,sBAAsB;AACnD,UAAM,YAAY,UAAU,UAAU,MAAM,MAAM,MAAM;AACxD,YAAQ,KAAK,EAAE,UAAU,GAAG,IAAI,QAAQ,MAAM,aAAa,OAAO,EAAE,CAAC;AACrE,QAAI,YAAY;AACd,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QAAQ,IAAI,MAA4B;AAChF,QAAM,iBAAiB,UAAU,CAAC,IAAI,IAAI,CAAC;AAC3C,QAAM,gBAAgB,SAAS,CAAC,MAAM,MAAM,IAAI,CAAC;AAEjD,SAAO,SAAS,YAAY,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,aAAa,KAAK,OAAO,mBAAmB,GAAG,gBAAgB,GAAG,aAAa,CAAC,CAAC,CAAC;AACnI;AAEO,IAAM,aAAa,CAAC,EAAE,MAAM,SAAS,QAAQ,YAAY,MAAqB;AACnF,QAAM,QAAQ,KAAK,IAAI;AACvB,QAAM,iBAAiB,UAAU,CAAC,IAAI,IAAI,CAAC;AAC3C,QAAM,gBAAgB,SAAS,CAAC,MAAM,MAAM,IAAI,CAAC;AACjD,QAAM,qBAAqB,cAAc,CAAC,WAAW,MAAM,IAAI,CAAC,MAAM;AACtE,QAAM,cAAc,OAAO,CAAC,MAAM,GAAG,IAAI,EAAE,IAAI,CAAC;AAChD,MAAI,MAAM;AACR,YAAQ,IAAIC,OAAM,KAAK,gBAAgB,IAAI,GAAG,CAAC;AAAA,EACjD;AAEA,QAAM,SAAS,SAAS,UAAU,cAAc,iBAAiB,EAAE,UAAU;AAAA,IAC3E,CAAC,QAAQ,CAAC,cAAc,WAAW,GAAG,oBAAoB,GAAG,aAAa,OAAO,mBAAmB,GAAG,gBAAgB,GAAG,aAAa,CAAC;AAAA,EAC1I,CAAC;AACD,UAAQ,IAAI,GAAGA,OAAM,KAAK,aAAa,CAAC,KAAKA,OAAM,UAAU,KAAK,IAAI,IAAI,SAAS,KAAM,QAAQ,CAAC,CAAC,CAAC,KAAKA,OAAM,KAAK,SAAS,CAAC,EAAE;AAChI,SAAO;AACT;","names":["chalk","chalk","ex","ex","error","chalk","chalk","chalk","chalk"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/actions/copy-assets.ts
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import cpy from "cpy";
|
|
4
|
+
import path from "path/posix";
|
|
5
|
+
|
|
6
|
+
// src/lib/yarn/workspace/yarnWorkspaces.ts
|
|
7
|
+
import { spawnSync } from "child_process";
|
|
8
|
+
var yarnWorkspaces = () => {
|
|
9
|
+
const result = spawnSync("yarn", ["workspaces", "list", "--json", "--recursive"], { encoding: "utf8", shell: true });
|
|
10
|
+
if (result.error) {
|
|
11
|
+
throw result.error;
|
|
12
|
+
}
|
|
13
|
+
const list = result.stdout.toString().split("\n").slice(0, -1).map((item) => {
|
|
14
|
+
return JSON.parse(item);
|
|
15
|
+
});
|
|
16
|
+
return list;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// src/actions/copy-assets.ts
|
|
20
|
+
var copyPackageTargetAssets = async (target, name, location) => {
|
|
21
|
+
try {
|
|
22
|
+
const values = await cpy(
|
|
23
|
+
["**/*.jpg", "**/*.png", "**/*.gif", "**/*.svg", "**/*.webp", "**/*.sass", "**/*.scss", "**/*.gif", "**/*.css"],
|
|
24
|
+
`../dist/${target}`,
|
|
25
|
+
{
|
|
26
|
+
cwd: path.join(process.cwd(), location, "src"),
|
|
27
|
+
parents: true
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
values.forEach((value) => {
|
|
31
|
+
console.log(`${value.split("/").pop()} => ./dist/${target}`);
|
|
32
|
+
});
|
|
33
|
+
return 0;
|
|
34
|
+
} catch (reason) {
|
|
35
|
+
console.log(`Copy Failed: ${name}: ${reason}`);
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var copyTargetAssets = async (target, pkg) => {
|
|
40
|
+
const workspaces = yarnWorkspaces();
|
|
41
|
+
console.log(chalk.green(`Copying Assets [${target.toUpperCase()}]`));
|
|
42
|
+
const workspaceList = workspaces.filter(({ name }) => {
|
|
43
|
+
return pkg === void 0 || name === pkg;
|
|
44
|
+
});
|
|
45
|
+
if (workspaceList.length === 0) {
|
|
46
|
+
console.error(`Package not found [${pkg}]`);
|
|
47
|
+
} else {
|
|
48
|
+
const results = await Promise.all(
|
|
49
|
+
workspaceList.map(async (workspace) => {
|
|
50
|
+
const { location, name } = workspace;
|
|
51
|
+
return await copyPackageTargetAssets(target, name, location);
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
return results.reduce((prev, result) => prev || result, 0);
|
|
55
|
+
}
|
|
56
|
+
return 0;
|
|
57
|
+
};
|
|
58
|
+
var copyAssets = async ({ target, pkg }) => {
|
|
59
|
+
switch (target) {
|
|
60
|
+
case "esm":
|
|
61
|
+
return await copyTargetAssets("esm", pkg);
|
|
62
|
+
case "cjs":
|
|
63
|
+
return await copyTargetAssets("cjs", pkg);
|
|
64
|
+
default:
|
|
65
|
+
return await copyTargetAssets("esm", pkg) || await copyTargetAssets("cjs", pkg);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
export {
|
|
69
|
+
copyAssets
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=copy-assets.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/actions/copy-assets.ts","../../src/lib/yarn/workspace/yarnWorkspaces.ts"],"sourcesContent":["import chalk from 'chalk'\nimport cpy from 'cpy'\nimport path from 'path/posix'\n\nimport { yarnWorkspaces } from '../lib'\n\nexport interface CopyAssetsParams {\n pkg?: string\n target?: 'esm' | 'cjs'\n}\n\nconst copyPackageTargetAssets = async (target: 'esm' | 'cjs', name: string, location: string) => {\n try {\n const values = await cpy(\n ['**/*.jpg', '**/*.png', '**/*.gif', '**/*.svg', '**/*.webp', '**/*.sass', '**/*.scss', '**/*.gif', '**/*.css'],\n `../dist/${target}`,\n {\n cwd: path.join(process.cwd(), location, 'src'),\n parents: true,\n },\n )\n values.forEach((value) => {\n console.log(`${value.split('/').pop()} => ./dist/${target}`)\n })\n return 0\n } catch (reason) {\n console.log(`Copy Failed: ${name}: ${reason}`)\n return 1\n }\n}\n\nconst copyTargetAssets = async (target: 'esm' | 'cjs', pkg?: string) => {\n const workspaces = yarnWorkspaces()\n\n console.log(chalk.green(`Copying Assets [${target.toUpperCase()}]`))\n\n //finds the package or returns all if undefined\n const workspaceList = workspaces.filter(({ name }) => {\n return pkg === undefined || name === pkg\n })\n\n if (workspaceList.length === 0) {\n console.error(`Package not found [${pkg}]`)\n } else {\n const results = await Promise.all(\n workspaceList.map(async (workspace) => {\n const { location, name } = workspace\n return await copyPackageTargetAssets(target, name, location)\n }),\n )\n return results.reduce((prev, result) => prev || result, 0)\n }\n return 0\n}\n\nexport const copyAssets = async ({ target, pkg }: CopyAssetsParams) => {\n switch (target) {\n case 'esm':\n return await copyTargetAssets('esm', pkg)\n case 'cjs':\n return await copyTargetAssets('cjs', pkg)\n default:\n return (await copyTargetAssets('esm', pkg)) || (await copyTargetAssets('cjs', pkg))\n }\n}\n","import { spawnSync } from 'child_process'\n\nimport { Workspace } from './Workspace'\n\nexport const yarnWorkspaces = (): Workspace[] => {\n const result = spawnSync('yarn', ['workspaces', 'list', '--json', '--recursive'], { encoding: 'utf8', shell: true })\n if (result.error) {\n throw result.error\n }\n const list = result.stdout\n .toString()\n // NOTE: This probably doesn't work on Windows\n // TODO: Replace /r/n with /n first\n .split('\\n')\n .slice(0, -1)\n .map((item) => {\n return JSON.parse(item)\n })\n return list\n}\n"],"mappings":";AAAA,OAAO,WAAW;AAClB,OAAO,SAAS;AAChB,OAAO,UAAU;;;ACFjB,SAAS,iBAAiB;AAInB,IAAM,iBAAiB,MAAmB;AAC/C,QAAM,SAAS,UAAU,QAAQ,CAAC,cAAc,QAAQ,UAAU,aAAa,GAAG,EAAE,UAAU,QAAQ,OAAO,KAAK,CAAC;AACnH,MAAI,OAAO,OAAO;AAChB,UAAM,OAAO;AAAA,EACf;AACA,QAAM,OAAO,OAAO,OACjB,SAAS,EAGT,MAAM,IAAI,EACV,MAAM,GAAG,EAAE,EACX,IAAI,CAAC,SAAS;AACb,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,CAAC;AACH,SAAO;AACT;;;ADRA,IAAM,0BA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AAiB,OAAO,GAAG;AAAA,IAC1C,KAAK;AACH,aAAO,MAAM,iBAAiB,OAAO,GAAG;AAAA,IAC1C;AACE,aAAQ,MAAM,iBAAiB,OAAO,GAAG,KAAO,MAAM,iBAAiB,OAAO,GAAG;AAAA,EACrF;AACF;","names":[]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// src/lib/checkResult.ts
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
var checkResult = (name, result, level = "error", exitOnFail = false) => {
|
|
4
|
+
if (result) {
|
|
5
|
+
const exiting = exitOnFail ? "[Exiting Process]" : "[Continuing]";
|
|
6
|
+
const chalkFunc = level === "error" ? chalk.red : chalk.yellow;
|
|
7
|
+
console[level](chalkFunc(`${name} had ${result} failures ${exiting}`));
|
|
8
|
+
if (exitOnFail) {
|
|
9
|
+
process.exit(result);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/lib/processEx.ts
|
|
15
|
+
import chalk2 from "chalk";
|
|
16
|
+
|
|
17
|
+
// src/lib/withError.ts
|
|
18
|
+
var withError = (ex, closure, predicate = (ex2) => ex2.name !== void 0 && ex2.message !== void 0) => {
|
|
19
|
+
return predicate(ex) ? closure(ex) : void 0;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/lib/withErrnoException.ts
|
|
23
|
+
var withErrnoException = (ex, closure) => {
|
|
24
|
+
return withError(ex, closure, (ex2) => ex2.errno !== void 0);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/lib/processEx.ts
|
|
28
|
+
var processEx = (ex) => {
|
|
29
|
+
const error = typeof ex === "string" ? Error(ex) : ex;
|
|
30
|
+
const exitCode = withErrnoException(error, (error2) => {
|
|
31
|
+
if (error2.code === "ENOENT") {
|
|
32
|
+
console.error(chalk2.red(`'${error2.path}' not found.`));
|
|
33
|
+
} else {
|
|
34
|
+
console.error(chalk2.red(`Errno: ${error2.code}`));
|
|
35
|
+
}
|
|
36
|
+
return error2.errno ?? -1;
|
|
37
|
+
}) ?? withError(error, (error2) => {
|
|
38
|
+
console.error(chalk2.red(`${error2.name}: ${error2.message}`));
|
|
39
|
+
return -1;
|
|
40
|
+
}) ?? (() => {
|
|
41
|
+
console.error(chalk2.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`));
|
|
42
|
+
return -1;
|
|
43
|
+
})();
|
|
44
|
+
process.exit(process.exitCode ?? exitCode);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/lib/safeExit.ts
|
|
48
|
+
var safeExit = (func, exitOnFail = true) => {
|
|
49
|
+
try {
|
|
50
|
+
const result = func();
|
|
51
|
+
if (result && exitOnFail) {
|
|
52
|
+
process.exit(result);
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
} catch (ex) {
|
|
56
|
+
return processEx(ex);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/lib/runSteps.ts
|
|
61
|
+
import chalk3 from "chalk";
|
|
62
|
+
import { spawnSync } from "child_process";
|
|
63
|
+
import { existsSync } from "fs";
|
|
64
|
+
var runSteps = (name, steps, exitOnFail = true, messages) => {
|
|
65
|
+
return safeExit(() => {
|
|
66
|
+
const pkgName = process.env.npm_package_name;
|
|
67
|
+
console.log(chalk3.green(`${name} [${pkgName}]`));
|
|
68
|
+
let totalStatus = 0;
|
|
69
|
+
for (let i = 0; i < steps.length; i++) {
|
|
70
|
+
const [command, args, config] = steps[i];
|
|
71
|
+
if (messages?.[i]) {
|
|
72
|
+
console.log(chalk3.gray(messages?.[i]));
|
|
73
|
+
}
|
|
74
|
+
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
75
|
+
if (command === "node" && !existsSync(argList[0])) {
|
|
76
|
+
throw Error(`File not found [${argList[0]}]`);
|
|
77
|
+
}
|
|
78
|
+
const status = spawnSync(command, Array.isArray(args) ? args : args.split(" "), {
|
|
79
|
+
...config,
|
|
80
|
+
encoding: "utf8",
|
|
81
|
+
env: { FORCE_COLOR: "3", ...process.env },
|
|
82
|
+
shell: true,
|
|
83
|
+
stdio: "inherit"
|
|
84
|
+
}).status ?? 0;
|
|
85
|
+
checkResult(name, status, "error", exitOnFail);
|
|
86
|
+
totalStatus += status ?? 0;
|
|
87
|
+
}
|
|
88
|
+
return totalStatus;
|
|
89
|
+
}, !!exitOnFail);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// src/actions/cycle.ts
|
|
93
|
+
var cycle = () => {
|
|
94
|
+
const rules = [`"'import/no-cycle': [1, { maxDepth: 6 }]"`, `"'import/no-internal-modules': ['off']"`];
|
|
95
|
+
return runSteps("Cycle", [["yarn", ["eslint", ...rules.map((rule) => ["--rule", rule]).flat(), "--cache", "."]]]);
|
|
96
|
+
};
|
|
97
|
+
export {
|
|
98
|
+
cycle
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=cycle.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/checkResult.ts","../../src/lib/processEx.ts","../../src/lib/withError.ts","../../src/lib/withErrnoException.ts","../../src/lib/safeExit.ts","../../src/lib/runSteps.ts","../../src/actions/cycle.ts"],"sourcesContent":["import chalk from 'chalk'\n\nexport const checkResult = (name: string, result: number, level: 'error' | 'warn' = 'error', exitOnFail = false) => {\n if (result) {\n const exiting = exitOnFail ? '[Exiting Process]' : '[Continuing]'\n const chalkFunc = level === 'error' ? chalk.red : chalk.yellow\n console[level](chalkFunc(`${name} had ${result} failures ${exiting}`))\n if (exitOnFail) {\n process.exit(result)\n }\n }\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException'\nimport { withError } from './withError'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const processEx = (ex: any) => {\n const error = typeof ex === 'string' ? Error(ex) : ex\n const exitCode =\n withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n }) ??\n withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n }) ??\n (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n //This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => ex.name !== undefined && ex.message !== undefined,\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { withError } from './withError'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(ex: any, closure: (error: T) => number) => {\n return withError<T>(ex, closure, (ex: any) => ex.errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import chalk from 'chalk'\nimport { spawnSync, SpawnSyncOptionsWithBufferEncoding } from 'child_process'\nimport { existsSync } from 'fs'\n\nimport { checkResult } from './checkResult'\nimport { safeExit } from './safeExit'\n\nexport type ScriptStep =\n | [/*command*/ 'yarn' | 'node' | 'ts-node-script' | 'tsc' | 'jest', /*arg*/ string | string[]]\n | [/*command*/ string, /*arg*/ string | string[], /*config*/ SpawnSyncOptionsWithBufferEncoding]\n\nexport const runSteps = (name: string, steps: ScriptStep[], exitOnFail = true, messages?: string[]): number => {\n return safeExit(() => {\n const pkgName = process.env.npm_package_name\n console.log(chalk.green(`${name} [${pkgName}]`))\n let totalStatus = 0\n for (let i = 0; i < steps.length; i++) {\n const [command, args, config] = steps[i]\n if (messages?.[i]) {\n console.log(chalk.gray(messages?.[i]))\n }\n const argList = Array.isArray(args) ? args : args.split(' ')\n if (command === 'node' && !existsSync(argList[0])) {\n throw Error(`File not found [${argList[0]}]`)\n }\n const status =\n spawnSync(command, Array.isArray(args) ? args : args.split(' '), {\n ...config,\n encoding: 'utf8',\n env: { FORCE_COLOR: '3', ...process.env },\n shell: true,\n stdio: 'inherit',\n }).status ?? 0\n checkResult(name, status, 'error', exitOnFail)\n totalStatus += status ?? 0\n }\n return totalStatus\n }, !!exitOnFail)\n}\n","import { runSteps } from '../lib'\n\nexport const cycle = () => {\n const rules = ['\"\\'import/no-cycle\\': [1, { maxDepth: 6 }]\"', \"\\\"'import/no-internal-modules': ['off']\\\"\"]\n return runSteps('Cycle', [['yarn', ['eslint', ...rules.map((rule) => ['--rule', rule]).flat(), '--cache', '.']]])\n}\n"],"mappings":";AAAA,OAAO,WAAW;AAEX,IAAM,cAAc,CAAC,MAAc,QAAgB,QAA0B,SAAS,aAAa,UAAU;AAClH,MAAI,QAAQ;AACV,UAAM,UAAU,aAAa,sBAAsB;AACnD,UAAM,YAAY,UAAU,UAAU,MAAM,MAAM,MAAM;AACxD,YAAQ,KAAK,EAAE,UAAU,GAAG,IAAI,QAAQ,MAAM,aAAa,OAAO,EAAE,CAAC;AACrE,QAAI,YAAY;AACd,cAAQ,KAAK,MAAM;AAAA,IACrB;AAAA,EACF;AACF;;;ACXA,OAAOA,YAAW;;;ACAX,IAAM,YAAY,CAEvB,IACA,SACA,YAAY,CAACC,QAAUA,IAAG,SAAS,UAAaA,IAAG,YAAY,WAC5D;AACH,SAAO,UAAU,EAAO,IAAI,QAAQ,EAAO,IAAI;AACjD;;;ACJO,IAAM,qBAAqB,CAA0D,IAAS,YAAkC;AACrI,SAAO,UAAa,IAAI,SAAS,CAACC,QAAYA,IA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AK;AACrC,YAAM,CAAC,SAAS,MAAM,MAAM,IAAI,MAAM,CAAC;AACvC,UAAI,WAAW,CAAC,GAAG;AACjB,gBAAQ,IAAIA,OAAM,KAAK,WAAW,CAAC,CAAC,CAAC;AAAA,MACvC;AACA,YAAM,UAAU,MAAM,QAAQ,IAAI,IAAI,OAAO,KAAK,MAAM,GAAG;AAC3D,UAAI,YAAY,UAAU,CAAC,WAAW,QAAQ,CAAC,CAAC,GAAG;AACjD,cAAM,MAAM,mBAAmB,QAAQ,CAAC,CAAC,GAAG;AAAA,MAC9C;AACA,YAAM,SACJ,UAAU,SAAS,MAAM,QAAQ,IAAI,IAAI,OAAO,KAAK,MAAM,GAAG,GAAG;AAAA,QAC/D,GAAG;AAAA,QACH,UAAU;AAAA,QACV,KAAK,EAAE,aAAa,KAAK,GAAG,QAAQ,IAAI;AAAA,QACxC,OAAO;AAAA,QACP,OAAO;AAAA,MACT,CAAC,EAAE,UAAU;AACf,kBAAY,MAAM,QAAQ,SAAS,UAAU;AAC7C,qBAAe,UAAU;AAAA,IAC3B;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC,UAAU;AACjB;;;ACpCO,IAAM,QAAQ,MAAM;AACzB,QAAM,QAAQ,CAAC,6CAA+C,yCAA2C;AACzG,SAAO,SAAS,SAAS,CAAC,CAAC,QAAQ,CAAC,UAAU,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,UAAU,IAAI,CAAC,EAAE,KAAK,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC;AAClH;","names":["chalk","ex","ex","error","chalk","chalk","chalk"]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// src/lib/checkResult.ts
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
var checkResult = (name, result, level = "error", exitOnFail = false) => {
|
|
4
|
+
if (result) {
|
|
5
|
+
const exiting = exitOnFail ? "[Exiting Process]" : "[Continuing]";
|
|
6
|
+
const chalkFunc = level === "error" ? chalk.red : chalk.yellow;
|
|
7
|
+
console[level](chalkFunc(`${name} had ${result} failures ${exiting}`));
|
|
8
|
+
if (exitOnFail) {
|
|
9
|
+
process.exit(result);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/lib/processEx.ts
|
|
15
|
+
import chalk2 from "chalk";
|
|
16
|
+
|
|
17
|
+
// src/lib/withError.ts
|
|
18
|
+
var withError = (ex, closure, predicate = (ex2) => ex2.name !== void 0 && ex2.message !== void 0) => {
|
|
19
|
+
return predicate(ex) ? closure(ex) : void 0;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/lib/withErrnoException.ts
|
|
23
|
+
var withErrnoException = (ex, closure) => {
|
|
24
|
+
return withError(ex, closure, (ex2) => ex2.errno !== void 0);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/lib/processEx.ts
|
|
28
|
+
var processEx = (ex) => {
|
|
29
|
+
const error = typeof ex === "string" ? Error(ex) : ex;
|
|
30
|
+
const exitCode = withErrnoException(error, (error2) => {
|
|
31
|
+
if (error2.code === "ENOENT") {
|
|
32
|
+
console.error(chalk2.red(`'${error2.path}' not found.`));
|
|
33
|
+
} else {
|
|
34
|
+
console.error(chalk2.red(`Errno: ${error2.code}`));
|
|
35
|
+
}
|
|
36
|
+
return error2.errno ?? -1;
|
|
37
|
+
}) ?? withError(error, (error2) => {
|
|
38
|
+
console.error(chalk2.red(`${error2.name}: ${error2.message}`));
|
|
39
|
+
return -1;
|
|
40
|
+
}) ?? (() => {
|
|
41
|
+
console.error(chalk2.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`));
|
|
42
|
+
return -1;
|
|
43
|
+
})();
|
|
44
|
+
process.exit(process.exitCode ?? exitCode);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/lib/safeExit.ts
|
|
48
|
+
var safeExit = (func, exitOnFail = true) => {
|
|
49
|
+
try {
|
|
50
|
+
const result = func();
|
|
51
|
+
if (result && exitOnFail) {
|
|
52
|
+
process.exit(result);
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
} catch (ex) {
|
|
56
|
+
return processEx(ex);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/lib/runSteps.ts
|
|
61
|
+
import chalk3 from "chalk";
|
|
62
|
+
import { spawnSync } from "child_process";
|
|
63
|
+
import { existsSync } from "fs";
|
|
64
|
+
var runSteps = (name, steps, exitOnFail = true, messages) => {
|
|
65
|
+
return safeExit(() => {
|
|
66
|
+
const pkgName = process.env.npm_package_name;
|
|
67
|
+
console.log(chalk3.green(`${name} [${pkgName}]`));
|
|
68
|
+
let totalStatus = 0;
|
|
69
|
+
for (let i = 0; i < steps.length; i++) {
|
|
70
|
+
const [command, args, config] = steps[i];
|
|
71
|
+
if (messages?.[i]) {
|
|
72
|
+
console.log(chalk3.gray(messages?.[i]));
|
|
73
|
+
}
|
|
74
|
+
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
75
|
+
if (command === "node" && !existsSync(argList[0])) {
|
|
76
|
+
throw Error(`File not found [${argList[0]}]`);
|
|
77
|
+
}
|
|
78
|
+
const status = spawnSync(command, Array.isArray(args) ? args : args.split(" "), {
|
|
79
|
+
...config,
|
|
80
|
+
encoding: "utf8",
|
|
81
|
+
env: { FORCE_COLOR: "3", ...process.env },
|
|
82
|
+
shell: true,
|
|
83
|
+
stdio: "inherit"
|
|
84
|
+
}).status ?? 0;
|
|
85
|
+
checkResult(name, status, "error", exitOnFail);
|
|
86
|
+
totalStatus += status ?? 0;
|
|
87
|
+
}
|
|
88
|
+
return totalStatus;
|
|
89
|
+
}, !!exitOnFail);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// src/actions/dead.ts
|
|
93
|
+
var dead = () => {
|
|
94
|
+
return runSteps("Dead", [["yarn", ["ts-prune", "-p", "tsconfig.json"]]]);
|
|
95
|
+
};
|
|
96
|
+
export {
|
|
97
|
+
dead
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=dead.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/checkResult.ts","../../src/lib/processEx.ts","../../src/lib/withError.ts","../../src/lib/withErrnoException.ts","../../src/lib/safeExit.ts","../../src/lib/runSteps.ts","../../src/actions/dead.ts"],"sourcesContent":["import chalk from 'chalk'\n\nexport const checkResult = (name: string, result: number, level: 'error' | 'warn' = 'error', exitOnFail = false) => {\n if (result) {\n const exiting = exitOnFail ? '[Exiting Process]' : '[Continuing]'\n const chalkFunc = level === 'error' ? chalk.red : chalk.yellow\n console[level](chalkFunc(`${name} had ${result} failures ${exiting}`))\n if (exitOnFail) {\n process.exit(result)\n }\n }\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException'\nimport { withError } from './withError'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const processEx = (ex: any) => {\n const error = typeof ex === 'string' ? Error(ex) : ex\n const exitCode =\n withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n }) ??\n withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n }) ??\n (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n //This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => ex.name !== undefined && ex.message !== undefined,\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { withError } from './withError'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(ex: any, closure: (error: T) => number) => {\n return withError<T>(ex, closure, (ex: any) => ex.errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import chalk from 'chalk'\nimport { spawnSync, SpawnSyncOptionsWithBufferEncoding } from 'child_process'\nimport { existsSync } from 'fs'\n\nimport { checkResult } from './checkResult'\nimport { safeExit } from './safeExit'\n\nexport type ScriptStep =\n | [/*command*/ 'yarn' | 'node' | 'ts-node-script' | 'tsc' | 'jest', /*arg*/ string | string[]]\n | [/*command*/ string, /*arg*/ string | string[], /*config*/ SpawnSyncOptionsWithBufferEncoding]\n\nexport const runSteps = (name: string, steps: ScriptStep[], exitOnFail = true, messages?: string[]): number => {\n return safeExit(() => {\n const pkgName = process.env.npm_package_name\n console.log(chalk.green(`${name} [${pkgName}]`))\n let totalStatus = 0\n for (let i = 0; i < steps.length; i++) {\n const [command, args, config] = steps[i]\n if (messages?.[i]) {\n console.log(chalk.gray(messages?.[i]))\n }\n const argList = Array.isArray(args) ? args : args.split(' ')\n if (command === 'node' && !existsSync(argList[0])) {\n throw Error(`File not found [${argList[0]}]`)\n }\n const status =\n spawnSync(command, Array.isArray(args) ? args : args.split(' '), {\n ...config,\n encoding: 'utf8',\n env: { FORCE_COLOR: '3', ...process.env },\n shell: true,\n stdio: 'inherit',\n }).status ?? 0\n checkResult(name, status, 'error', exitOnFail)\n totalStatus += status ?? 0\n }\n return totalStatus\n }, !!exitOnFail)\n}\n","import { runSteps } from '../lib'\n\nexport const dead = () => {\n return runSteps('Dead', [['yarn', ['ts-prune', '-p', 'tsconfig.json']]])\n}\n"],"mappings":";A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AU;AAAA,IAC3B;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC,UAAU;AACjB;;;ACpCO,IAAM,OAAO,MAAM;AACxB,SAAO,SAAS,QAAQ,CAAC,CAAC,QAAQ,CAAC,YAAY,MAAM,eAAe,CAAC,CAAC,CAAC;AACzE;","names":["chalk","ex","ex","error","chalk","chalk","chalk"]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// src/lib/checkResult.ts
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
var checkResult = (name, result, level = "error", exitOnFail = false) => {
|
|
4
|
+
if (result) {
|
|
5
|
+
const exiting = exitOnFail ? "[Exiting Process]" : "[Continuing]";
|
|
6
|
+
const chalkFunc = level === "error" ? chalk.red : chalk.yellow;
|
|
7
|
+
console[level](chalkFunc(`${name} had ${result} failures ${exiting}`));
|
|
8
|
+
if (exitOnFail) {
|
|
9
|
+
process.exit(result);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/lib/processEx.ts
|
|
15
|
+
import chalk2 from "chalk";
|
|
16
|
+
|
|
17
|
+
// src/lib/withError.ts
|
|
18
|
+
var withError = (ex, closure, predicate = (ex2) => ex2.name !== void 0 && ex2.message !== void 0) => {
|
|
19
|
+
return predicate(ex) ? closure(ex) : void 0;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/lib/withErrnoException.ts
|
|
23
|
+
var withErrnoException = (ex, closure) => {
|
|
24
|
+
return withError(ex, closure, (ex2) => ex2.errno !== void 0);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/lib/processEx.ts
|
|
28
|
+
var processEx = (ex) => {
|
|
29
|
+
const error = typeof ex === "string" ? Error(ex) : ex;
|
|
30
|
+
const exitCode = withErrnoException(error, (error2) => {
|
|
31
|
+
if (error2.code === "ENOENT") {
|
|
32
|
+
console.error(chalk2.red(`'${error2.path}' not found.`));
|
|
33
|
+
} else {
|
|
34
|
+
console.error(chalk2.red(`Errno: ${error2.code}`));
|
|
35
|
+
}
|
|
36
|
+
return error2.errno ?? -1;
|
|
37
|
+
}) ?? withError(error, (error2) => {
|
|
38
|
+
console.error(chalk2.red(`${error2.name}: ${error2.message}`));
|
|
39
|
+
return -1;
|
|
40
|
+
}) ?? (() => {
|
|
41
|
+
console.error(chalk2.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`));
|
|
42
|
+
return -1;
|
|
43
|
+
})();
|
|
44
|
+
process.exit(process.exitCode ?? exitCode);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/lib/safeExit.ts
|
|
48
|
+
var safeExit = (func, exitOnFail = true) => {
|
|
49
|
+
try {
|
|
50
|
+
const result = func();
|
|
51
|
+
if (result && exitOnFail) {
|
|
52
|
+
process.exit(result);
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
} catch (ex) {
|
|
56
|
+
return processEx(ex);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/lib/runSteps.ts
|
|
61
|
+
import chalk3 from "chalk";
|
|
62
|
+
import { spawnSync } from "child_process";
|
|
63
|
+
import { existsSync } from "fs";
|
|
64
|
+
var runSteps = (name, steps, exitOnFail = true, messages) => {
|
|
65
|
+
return safeExit(() => {
|
|
66
|
+
const pkgName = process.env.npm_package_name;
|
|
67
|
+
console.log(chalk3.green(`${name} [${pkgName}]`));
|
|
68
|
+
let totalStatus = 0;
|
|
69
|
+
for (let i = 0; i < steps.length; i++) {
|
|
70
|
+
const [command, args, config] = steps[i];
|
|
71
|
+
if (messages?.[i]) {
|
|
72
|
+
console.log(chalk3.gray(messages?.[i]));
|
|
73
|
+
}
|
|
74
|
+
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
75
|
+
if (command === "node" && !existsSync(argList[0])) {
|
|
76
|
+
throw Error(`File not found [${argList[0]}]`);
|
|
77
|
+
}
|
|
78
|
+
const status = spawnSync(command, Array.isArray(args) ? args : args.split(" "), {
|
|
79
|
+
...config,
|
|
80
|
+
encoding: "utf8",
|
|
81
|
+
env: { FORCE_COLOR: "3", ...process.env },
|
|
82
|
+
shell: true,
|
|
83
|
+
stdio: "inherit"
|
|
84
|
+
}).status ?? 0;
|
|
85
|
+
checkResult(name, status, "error", exitOnFail);
|
|
86
|
+
totalStatus += status ?? 0;
|
|
87
|
+
}
|
|
88
|
+
return totalStatus;
|
|
89
|
+
}, !!exitOnFail);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// src/actions/deploy-major.ts
|
|
93
|
+
var deployMajor = () => {
|
|
94
|
+
return runSteps("Deploy [Major]", [
|
|
95
|
+
["yarn", "workspaces foreach --all version major --deferred"],
|
|
96
|
+
["yarn", "xy clean"],
|
|
97
|
+
["yarn", "xy build"],
|
|
98
|
+
["yarn", "xy cycle"],
|
|
99
|
+
["yarn", "version apply --all"],
|
|
100
|
+
["yarn", "workspaces foreach -pt npm publish"]
|
|
101
|
+
]);
|
|
102
|
+
};
|
|
103
|
+
export {
|
|
104
|
+
deployMajor
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=deploy-major.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/checkResult.ts","../../src/lib/processEx.ts","../../src/lib/withError.ts","../../src/lib/withErrnoException.ts","../../src/lib/safeExit.ts","../../src/lib/runSteps.ts","../../src/actions/deploy-major.ts"],"sourcesContent":["import chalk from 'chalk'\n\nexport const checkResult = (name: string, result: number, level: 'error' | 'warn' = 'error', exitOnFail = false) => {\n if (result) {\n const exiting = exitOnFail ? '[Exiting Process]' : '[Continuing]'\n const chalkFunc = level === 'error' ? chalk.red : chalk.yellow\n console[level](chalkFunc(`${name} had ${result} failures ${exiting}`))\n if (exitOnFail) {\n process.exit(result)\n }\n }\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException'\nimport { withError } from './withError'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const processEx = (ex: any) => {\n const error = typeof ex === 'string' ? Error(ex) : ex\n const exitCode =\n withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n }) ??\n withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n }) ??\n (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n //This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => ex.name !== undefined && ex.message !== undefined,\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { withError } from './withError'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(ex: any, closure: (error: T) => number) => {\n return withError<T>(ex, closure, (ex: any) => ex.errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import chalk from 'chalk'\nimport { spawnSync, SpawnSyncOptionsWithBufferEncoding } from 'child_process'\nimport { existsSync } from 'fs'\n\nimport { checkResult } from './checkResult'\nimport { safeExit } from './safeExit'\n\nexport type ScriptStep =\n | [/*command*/ 'yarn' | 'node' | 'ts-node-script' | 'tsc' | 'jest', /*arg*/ string | string[]]\n | [/*command*/ string, /*arg*/ string | string[], /*config*/ SpawnSyncOptionsWithBufferEncoding]\n\nexport const runSteps = (name: string, steps: ScriptStep[], exitOnFail = true, messages?: string[]): number => {\n return safeExit(() => {\n const pkgName = process.env.npm_package_name\n console.log(chalk.green(`${name} [${pkgName}]`))\n let totalStatus = 0\n for (let i = 0; i < steps.length; i++) {\n const [command, args, config] = steps[i]\n if (messages?.[i]) {\n console.log(chalk.gray(messages?.[i]))\n }\n const argList = Array.isArray(args) ? args : args.split(' ')\n if (command === 'node' && !existsSync(argList[0])) {\n throw Error(`File not found [${argList[0]}]`)\n }\n const status =\n spawnSync(command, Array.isArray(args) ? args : args.split(' '), {\n ...config,\n encoding: 'utf8',\n env: { FORCE_COLOR: '3', ...process.env },\n shell: true,\n stdio: 'inherit',\n }).status ?? 0\n checkResult(name, status, 'error', exitOnFail)\n totalStatus += status ?? 0\n }\n return totalStatus\n }, !!exitOnFail)\n}\n","import { runSteps } from '../lib'\n\nexport const deployMajor = () => {\n return runSteps('Deploy [Major]', [\n ['yarn', 'workspaces foreach --all version major --deferred'],\n ['yarn', 'xy clean'],\n ['yarn', 'xy build'],\n ['yarn', 'xy cycle'],\n ['yarn', 'version apply --all'],\n ['yarn', 'workspaces foreach -pt npm publish'],\n ])\n}\n"],"mappings":";AAAA,OAAO,WAAW;AAEX,IAAM,cAAc,CAAC,MAAc,QAAgB,QAA0B,SAAS,aAAa,UAAU;AAClH,MAAI,QAAQ;AACV,UAAM,UAAU,aAAa,sBAAsB;AACnD,UAAM,YAAY,UAAU,UAAU,MAAM,MAAM,MAAM;AACxD,YAAQ,KAAK,EAAE,UAAU,GAAG,IAAI,QAAQ,MAAM,aAAa,OAAO,EAAE,CAAC;AACrE,QAAI,YAAY;AACd,cAAQ,KAAK,MAAM;AAAA,IACrB;AAAA,EACF;AACF;;;ACXA,OAAOA,YAAW;;;ACAX,IAAM,YAAY,CAEvB,IACA,SACA,YAAY,CAACC,QAAUA,IAAG,SAAS,UAAaA,IAAG,YAAY,WA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