@modern-js/new-action 2.47.0 → 2.48.0
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/cjs/run.js +35 -0
- package/dist/cjs/utils/index.js +26 -0
- package/dist/esm/run.js +34 -0
- package/dist/esm/utils/index.js +25 -0
- package/dist/types/run.d.ts +2 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/package.json +12 -8
package/dist/cjs/run.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var import_commander = require("@modern-js/utils/commander");
|
|
4
|
+
var import_mwa = require("./mwa");
|
|
5
|
+
var import_module = require("./module");
|
|
6
|
+
var import_monorepo = require("./monorepo");
|
|
7
|
+
var import_utils = require("./utils");
|
|
8
|
+
const main = async () => {
|
|
9
|
+
const program = new import_commander.Command();
|
|
10
|
+
program.option("--solution <solution>", "solution", "").option("--config <config>", "config", "{}").option("--root-path <rootPath>", "project root path", "").action(async (params) => {
|
|
11
|
+
if (!params.solution) {
|
|
12
|
+
params.solution = (0, import_utils.getSolutionByDependance)();
|
|
13
|
+
}
|
|
14
|
+
const { solution, config: configStr, rootPath } = params;
|
|
15
|
+
const config = JSON.parse(configStr);
|
|
16
|
+
if (rootPath) {
|
|
17
|
+
config.cwd = rootPath;
|
|
18
|
+
}
|
|
19
|
+
switch (solution) {
|
|
20
|
+
case "mwa":
|
|
21
|
+
(0, import_mwa.MWANewAction)(config);
|
|
22
|
+
break;
|
|
23
|
+
case "module":
|
|
24
|
+
(0, import_module.ModuleNewAction)(config);
|
|
25
|
+
break;
|
|
26
|
+
case "monorepo":
|
|
27
|
+
(0, import_monorepo.MonorepoNewAction)(config);
|
|
28
|
+
break;
|
|
29
|
+
default:
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
program.parse(process.argv);
|
|
34
|
+
};
|
|
35
|
+
main();
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -30,6 +30,7 @@ var utils_exports = {};
|
|
|
30
30
|
__export(utils_exports, {
|
|
31
31
|
alreadyRepo: () => alreadyRepo,
|
|
32
32
|
getGeneratorPath: () => getGeneratorPath,
|
|
33
|
+
getSolutionByDependance: () => getSolutionByDependance,
|
|
33
34
|
hasEnabledFunction: () => hasEnabledFunction,
|
|
34
35
|
readJson: () => readJson,
|
|
35
36
|
usePluginNameExport: () => usePluginNameExport
|
|
@@ -39,6 +40,13 @@ var import_path = __toESM(require("path"));
|
|
|
39
40
|
var import_utils = require("@modern-js/utils");
|
|
40
41
|
var import_generator_common = require("@modern-js/generator-common");
|
|
41
42
|
var import_generator_utils = require("@modern-js/generator-utils");
|
|
43
|
+
const swap = (obj) => {
|
|
44
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
45
|
+
acc[obj[key]] = key;
|
|
46
|
+
return acc;
|
|
47
|
+
}, {});
|
|
48
|
+
};
|
|
49
|
+
const dependenceToSolution = swap(import_generator_common.SolutionToolsMap);
|
|
42
50
|
function alreadyRepo(cwd = process.cwd()) {
|
|
43
51
|
try {
|
|
44
52
|
return import_generator_utils.fs.existsSync(import_path.default.resolve(cwd, "package.json"));
|
|
@@ -94,10 +102,28 @@ async function usePluginNameExport(solution, options) {
|
|
|
94
102
|
}
|
|
95
103
|
return true;
|
|
96
104
|
}
|
|
105
|
+
const getSolutionByDependance = (jsonPath) => {
|
|
106
|
+
const packageJsonPath = jsonPath !== null && jsonPath !== void 0 ? jsonPath : import_path.default.normalize(`${process.cwd()}/package.json`);
|
|
107
|
+
const packageJson = readJson(packageJsonPath);
|
|
108
|
+
const solutions = Object.keys(dependenceToSolution).map((i) => {
|
|
109
|
+
var _packageJson_dependencies, _packageJson_devDependencies;
|
|
110
|
+
if (((_packageJson_dependencies = packageJson.dependencies) === null || _packageJson_dependencies === void 0 ? void 0 : _packageJson_dependencies[i]) || ((_packageJson_devDependencies = packageJson.devDependencies) === null || _packageJson_devDependencies === void 0 ? void 0 : _packageJson_devDependencies[i])) {
|
|
111
|
+
return dependenceToSolution[i];
|
|
112
|
+
}
|
|
113
|
+
return "";
|
|
114
|
+
}).filter(Boolean);
|
|
115
|
+
if (solutions.length === 0) {
|
|
116
|
+
throw new Error("No solution found. Please check your package.json.");
|
|
117
|
+
} else if (solutions.length > 1) {
|
|
118
|
+
throw new Error(`Multiple solutions found: ${solutions.join(",")}`);
|
|
119
|
+
}
|
|
120
|
+
return solutions[0];
|
|
121
|
+
};
|
|
97
122
|
// Annotate the CommonJS export names for ESM import in node:
|
|
98
123
|
0 && (module.exports = {
|
|
99
124
|
alreadyRepo,
|
|
100
125
|
getGeneratorPath,
|
|
126
|
+
getSolutionByDependance,
|
|
101
127
|
hasEnabledFunction,
|
|
102
128
|
readJson,
|
|
103
129
|
usePluginNameExport
|
package/dist/esm/run.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "@modern-js/utils/commander";
|
|
3
|
+
import { MWANewAction } from "./mwa";
|
|
4
|
+
import { ModuleNewAction } from "./module";
|
|
5
|
+
import { MonorepoNewAction } from "./monorepo";
|
|
6
|
+
import { getSolutionByDependance } from "./utils";
|
|
7
|
+
const main = async () => {
|
|
8
|
+
const program = new Command();
|
|
9
|
+
program.option("--solution <solution>", "solution", "").option("--config <config>", "config", "{}").option("--root-path <rootPath>", "project root path", "").action(async (params) => {
|
|
10
|
+
if (!params.solution) {
|
|
11
|
+
params.solution = getSolutionByDependance();
|
|
12
|
+
}
|
|
13
|
+
const { solution, config: configStr, rootPath } = params;
|
|
14
|
+
const config = JSON.parse(configStr);
|
|
15
|
+
if (rootPath) {
|
|
16
|
+
config.cwd = rootPath;
|
|
17
|
+
}
|
|
18
|
+
switch (solution) {
|
|
19
|
+
case "mwa":
|
|
20
|
+
MWANewAction(config);
|
|
21
|
+
break;
|
|
22
|
+
case "module":
|
|
23
|
+
ModuleNewAction(config);
|
|
24
|
+
break;
|
|
25
|
+
case "monorepo":
|
|
26
|
+
MonorepoNewAction(config);
|
|
27
|
+
break;
|
|
28
|
+
default:
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
program.parse(process.argv);
|
|
33
|
+
};
|
|
34
|
+
main();
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -2,6 +2,13 @@ import path from "path";
|
|
|
2
2
|
import { json5, semver } from "@modern-js/utils";
|
|
3
3
|
import { Solution, SolutionToolsMap } from "@modern-js/generator-common";
|
|
4
4
|
import { fs, getModernPluginVersion } from "@modern-js/generator-utils";
|
|
5
|
+
const swap = (obj) => {
|
|
6
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
7
|
+
acc[obj[key]] = key;
|
|
8
|
+
return acc;
|
|
9
|
+
}, {});
|
|
10
|
+
};
|
|
11
|
+
const dependenceToSolution = swap(SolutionToolsMap);
|
|
5
12
|
function alreadyRepo(cwd = process.cwd()) {
|
|
6
13
|
try {
|
|
7
14
|
return fs.existsSync(path.resolve(cwd, "package.json"));
|
|
@@ -57,9 +64,27 @@ async function usePluginNameExport(solution, options) {
|
|
|
57
64
|
}
|
|
58
65
|
return true;
|
|
59
66
|
}
|
|
67
|
+
const getSolutionByDependance = (jsonPath) => {
|
|
68
|
+
const packageJsonPath = jsonPath !== null && jsonPath !== void 0 ? jsonPath : path.normalize(`${process.cwd()}/package.json`);
|
|
69
|
+
const packageJson = readJson(packageJsonPath);
|
|
70
|
+
const solutions = Object.keys(dependenceToSolution).map((i) => {
|
|
71
|
+
var _packageJson_dependencies, _packageJson_devDependencies;
|
|
72
|
+
if (((_packageJson_dependencies = packageJson.dependencies) === null || _packageJson_dependencies === void 0 ? void 0 : _packageJson_dependencies[i]) || ((_packageJson_devDependencies = packageJson.devDependencies) === null || _packageJson_devDependencies === void 0 ? void 0 : _packageJson_devDependencies[i])) {
|
|
73
|
+
return dependenceToSolution[i];
|
|
74
|
+
}
|
|
75
|
+
return "";
|
|
76
|
+
}).filter(Boolean);
|
|
77
|
+
if (solutions.length === 0) {
|
|
78
|
+
throw new Error("No solution found. Please check your package.json.");
|
|
79
|
+
} else if (solutions.length > 1) {
|
|
80
|
+
throw new Error(`Multiple solutions found: ${solutions.join(",")}`);
|
|
81
|
+
}
|
|
82
|
+
return solutions[0];
|
|
83
|
+
};
|
|
60
84
|
export {
|
|
61
85
|
alreadyRepo,
|
|
62
86
|
getGeneratorPath,
|
|
87
|
+
getSolutionByDependance,
|
|
63
88
|
hasEnabledFunction,
|
|
64
89
|
readJson,
|
|
65
90
|
usePluginNameExport
|
|
@@ -4,3 +4,4 @@ export declare const readJson: (jsonPath: string) => any;
|
|
|
4
4
|
export declare function hasEnabledFunction(action: ActionFunction | ActionRefactor, dependencies: Record<string, string>, devDependencies: Record<string, string>, peerDependencies: Record<string, string>, cwd: string): any;
|
|
5
5
|
export declare function getGeneratorPath(generator: string, distTag: string): string;
|
|
6
6
|
export declare function usePluginNameExport(solution: Solution, options: Record<string, string>): Promise<boolean>;
|
|
7
|
+
export declare const getSolutionByDependance: (jsonPath?: string) => string | undefined;
|
package/package.json
CHANGED
|
@@ -15,10 +15,13 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.48.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
22
|
+
"bin": {
|
|
23
|
+
"run": "./dist/cjs/run.js"
|
|
24
|
+
},
|
|
22
25
|
"exports": {
|
|
23
26
|
".": {
|
|
24
27
|
"node": {
|
|
@@ -30,20 +33,21 @@
|
|
|
30
33
|
}
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
|
-
"@modern-js/codesmith": "2.3.
|
|
34
|
-
"@modern-js/codesmith-formily": "2.3.
|
|
36
|
+
"@modern-js/codesmith": "2.3.5",
|
|
37
|
+
"@modern-js/codesmith-formily": "2.3.5",
|
|
35
38
|
"@swc/helpers": "0.5.3",
|
|
36
|
-
"@modern-js/generator-
|
|
37
|
-
"@modern-js/
|
|
38
|
-
"@modern-js/utils": "
|
|
39
|
+
"@modern-js/generator-common": "3.3.11",
|
|
40
|
+
"@modern-js/utils": "2.48.0",
|
|
41
|
+
"@modern-js/generator-utils": "3.3.11"
|
|
39
42
|
},
|
|
40
43
|
"devDependencies": {
|
|
41
44
|
"@types/jest": "^29",
|
|
42
45
|
"@types/node": "^14",
|
|
43
46
|
"jest": "^29",
|
|
47
|
+
"ts-node": "^10.9.1",
|
|
44
48
|
"typescript": "^5",
|
|
45
|
-
"@scripts/build": "2.
|
|
46
|
-
"@scripts/jest-config": "2.
|
|
49
|
+
"@scripts/build": "2.48.0",
|
|
50
|
+
"@scripts/jest-config": "2.48.0"
|
|
47
51
|
},
|
|
48
52
|
"sideEffects": false,
|
|
49
53
|
"publishConfig": {
|