generator-mico-cli 0.1.2 → 0.1.5
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/bin/mico.js +3 -1
- package/generators/subapp-react/index.js +38 -23
- package/package.json +3 -2
package/bin/mico.js
CHANGED
|
@@ -52,6 +52,7 @@ function printVersion() {
|
|
|
52
52
|
async function checkForUpdate() {
|
|
53
53
|
try {
|
|
54
54
|
const updateNotifier = (await import('update-notifier')).default;
|
|
55
|
+
const semver = (await import('semver')).default;
|
|
55
56
|
const notifier = updateNotifier({
|
|
56
57
|
pkg,
|
|
57
58
|
updateCheckInterval: 0 // 每次都检查
|
|
@@ -60,7 +61,8 @@ async function checkForUpdate() {
|
|
|
60
61
|
// 等待检查完成
|
|
61
62
|
await notifier.fetchInfo();
|
|
62
63
|
|
|
63
|
-
|
|
64
|
+
// 使用 semver 比较,确保 latest > current
|
|
65
|
+
if (notifier.update && semver.gt(notifier.update.latest, pkg.version)) {
|
|
64
66
|
return {
|
|
65
67
|
current: pkg.version,
|
|
66
68
|
latest: notifier.update.latest,
|
|
@@ -48,6 +48,39 @@ const TEMPLATE_EXTENSIONS = new Set([
|
|
|
48
48
|
]);
|
|
49
49
|
|
|
50
50
|
module.exports = class extends Generator {
|
|
51
|
+
/**
|
|
52
|
+
* 初始化阶段:检查运行环境
|
|
53
|
+
*/
|
|
54
|
+
initializing() {
|
|
55
|
+
// 使用当前工作目录,而不是 Yeoman 的 destinationRoot
|
|
56
|
+
this.monorepoRoot = process.cwd();
|
|
57
|
+
const appsDir = path.join(this.monorepoRoot, 'apps');
|
|
58
|
+
const workspaceFile = path.join(this.monorepoRoot, 'pnpm-workspace.yaml');
|
|
59
|
+
|
|
60
|
+
// 检查是否在 monorepo 中
|
|
61
|
+
if (!fs.existsSync(appsDir)) {
|
|
62
|
+
this.log('');
|
|
63
|
+
this.log('❌ Error: apps directory not found.');
|
|
64
|
+
this.log('');
|
|
65
|
+
this.log(' This generator must be run from a monorepo root that contains an "apps" directory.');
|
|
66
|
+
this.log(` Current directory: ${this.monorepoRoot}`);
|
|
67
|
+
this.log('');
|
|
68
|
+
this.log(' Usage:');
|
|
69
|
+
this.log(' cd /path/to/your-monorepo');
|
|
70
|
+
this.log(' mico create subapp-react');
|
|
71
|
+
this.log('');
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 警告:检查是否是 pnpm workspace
|
|
76
|
+
if (!fs.existsSync(workspaceFile)) {
|
|
77
|
+
this.log('');
|
|
78
|
+
this.log('⚠️ Warning: pnpm-workspace.yaml not found.');
|
|
79
|
+
this.log(' Make sure you are in the correct monorepo.');
|
|
80
|
+
this.log('');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
51
84
|
async prompting() {
|
|
52
85
|
this.answers = await this.prompt([
|
|
53
86
|
{
|
|
@@ -59,12 +92,16 @@ module.exports = class extends Generator {
|
|
|
59
92
|
validate: (input) => {
|
|
60
93
|
const value = toKebab(input);
|
|
61
94
|
if (!value) return 'App name is required';
|
|
95
|
+
// 检查目标目录是否已存在
|
|
96
|
+
const destDir = path.join(this.monorepoRoot, 'apps', value);
|
|
97
|
+
if (fs.existsSync(destDir)) {
|
|
98
|
+
return `Target already exists: apps/${value}`;
|
|
99
|
+
}
|
|
62
100
|
return true;
|
|
63
101
|
}
|
|
64
102
|
}
|
|
65
103
|
]);
|
|
66
104
|
|
|
67
|
-
this.monorepoRoot = this.destinationRoot();
|
|
68
105
|
this.appName = toKebab(this.answers.appName);
|
|
69
106
|
this.appNamePascal = toPascal(this.appName);
|
|
70
107
|
this.templateDir = this.templatePath('homepage');
|
|
@@ -72,28 +109,6 @@ module.exports = class extends Generator {
|
|
|
72
109
|
}
|
|
73
110
|
|
|
74
111
|
writing() {
|
|
75
|
-
const appsDir = path.join(this.monorepoRoot, 'apps');
|
|
76
|
-
const workspaceFile = path.join(this.monorepoRoot, 'pnpm-workspace.yaml');
|
|
77
|
-
|
|
78
|
-
// 检查是否在 monorepo 中
|
|
79
|
-
if (!fs.existsSync(appsDir)) {
|
|
80
|
-
this.env.error(
|
|
81
|
-
`apps directory not found in ${this.monorepoRoot}. Run this generator from the monorepo root.`
|
|
82
|
-
);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// 警告:检查是否是 pnpm workspace
|
|
87
|
-
if (!fs.existsSync(workspaceFile)) {
|
|
88
|
-
this.log.warning(
|
|
89
|
-
'pnpm-workspace.yaml not found. Make sure you are in the correct monorepo.'
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (fs.existsSync(this.destDir)) {
|
|
94
|
-
this.env.error(`Target already exists: ${this.destDir}`);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
112
|
|
|
98
113
|
// 模板数据
|
|
99
114
|
const templateData = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generator-mico-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Yeoman generator for Mico CLI projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yeoman-generator",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"cli"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"main": "generators/
|
|
11
|
+
"main": "generators/subapp-react/index.js",
|
|
12
12
|
"bin": {
|
|
13
13
|
"mico": "bin/mico.js"
|
|
14
14
|
},
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"node": ">=18"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"semver": "^7.6.3",
|
|
27
28
|
"update-notifier": "^7.3.1",
|
|
28
29
|
"yeoman-generator": "^5.9.0"
|
|
29
30
|
}
|