@knotx/cli 0.0.1 → 0.0.2
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/index.cjs +46 -17
- package/dist/index.mjs +46 -17
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
const node_child_process = require('node:child_process');
|
|
4
5
|
const path = require('node:path');
|
|
5
6
|
const process = require('node:process');
|
|
6
7
|
const chalk = require('chalk');
|
|
@@ -70,25 +71,24 @@ program.command("create-plugin").description("\u521B\u5EFA\u4E00\u4E2A\u65B0\u76
|
|
|
70
71
|
console.log(chalk__default.red(`\u274C \u9519\u8BEF: \u76EE\u5F55 ${fullPluginName} \u5DF2\u5B58\u5728`));
|
|
71
72
|
return;
|
|
72
73
|
}
|
|
73
|
-
|
|
74
|
+
let spinner = ora__default("\u{1F4C2} \u521B\u5EFA\u63D2\u4EF6\u76EE\u5F55...").start();
|
|
74
75
|
try {
|
|
75
76
|
yield fs__default.ensureDir(targetDir);
|
|
76
77
|
yield fs__default.ensureDir(path__default.join(targetDir, "src"));
|
|
77
78
|
spinner.succeed("\u{1F4C2} \u63D2\u4EF6\u76EE\u5F55\u521B\u5EFA\u6210\u529F");
|
|
78
|
-
spinner
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
spinner = ora__default("\u{1F50D} \u83B7\u53D6 @knotx \u5305\u7684\u6700\u65B0\u7248\u672C...").start();
|
|
80
|
+
const knotxVersions = yield getKnotxPackageVersions();
|
|
81
|
+
spinner.succeed("\u{1F50D} @knotx \u5305\u7248\u672C\u4FE1\u606F\u83B7\u53D6\u6210\u529F");
|
|
82
|
+
spinner = ora__default("\u{1F4C4} \u521B\u5EFA package.json...").start();
|
|
83
|
+
yield createPackageJson(targetDir, pluginName, environment, knotxVersions);
|
|
81
84
|
spinner.succeed("\u{1F4C4} package.json \u521B\u5EFA\u6210\u529F");
|
|
82
|
-
spinner
|
|
83
|
-
spinner.start();
|
|
85
|
+
spinner = ora__default("\u{1F4C4} \u521B\u5EFA\u914D\u7F6E\u6587\u4EF6...").start();
|
|
84
86
|
yield createConfigFiles(targetDir);
|
|
85
87
|
spinner.succeed("\u{1F4C4} \u914D\u7F6E\u6587\u4EF6\u521B\u5EFA\u6210\u529F");
|
|
86
|
-
spinner
|
|
87
|
-
spinner.start();
|
|
88
|
+
spinner = ora__default("\u{1F4C4} \u521B\u5EFA\u6E90\u4EE3\u7801\u6587\u4EF6...").start();
|
|
88
89
|
yield createSourceFiles(targetDir, pluginName, environment);
|
|
89
90
|
spinner.succeed("\u{1F4C4} \u6E90\u4EE3\u7801\u6587\u4EF6\u521B\u5EFA\u6210\u529F");
|
|
90
|
-
spinner
|
|
91
|
-
spinner.start();
|
|
91
|
+
spinner = ora__default("\u{1F4C4} \u521B\u5EFA README.md...").start();
|
|
92
92
|
yield createReadme(targetDir, pluginName);
|
|
93
93
|
spinner.succeed("\u{1F4C4} README.md \u521B\u5EFA\u6210\u529F");
|
|
94
94
|
console.log(chalk__default.green(`
|
|
@@ -106,7 +106,36 @@ program.command("create-plugin").description("\u521B\u5EFA\u4E00\u4E2A\u65B0\u76
|
|
|
106
106
|
console.error(chalk__default.red(error));
|
|
107
107
|
}
|
|
108
108
|
}));
|
|
109
|
-
function
|
|
109
|
+
function getKnotxPackageVersions() {
|
|
110
|
+
return __async(this, null, function* () {
|
|
111
|
+
const knotxVersions = {};
|
|
112
|
+
try {
|
|
113
|
+
const packages = ["@knotx/core", "@knotx/decorators", "@knotx/jsx", "@knotx/build-config", "@knotx/eslint-config", "@knotx/typescript-config"];
|
|
114
|
+
const npmRegistry = "https://registry.npmjs.org";
|
|
115
|
+
for (const pkg of packages) {
|
|
116
|
+
try {
|
|
117
|
+
const version = node_child_process.execSync(`npm view ${pkg} version --registry=${npmRegistry}`, { encoding: "utf8" }).trim();
|
|
118
|
+
knotxVersions[pkg] = `^${version}`;
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.warn(chalk__default.yellow(`\u26A0\uFE0F \u65E0\u6CD5\u83B7\u53D6 ${pkg} \u7684\u6700\u65B0\u7248\u672C\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u7248\u672C`));
|
|
121
|
+
knotxVersions[pkg] = "^0.0.1";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return knotxVersions;
|
|
125
|
+
} catch (e) {
|
|
126
|
+
console.warn(chalk__default.yellow("\u26A0\uFE0F \u83B7\u53D6 @knotx \u5305\u7248\u672C\u5931\u8D25\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u7248\u672C"));
|
|
127
|
+
return {
|
|
128
|
+
"@knotx/core": "^0.0.1",
|
|
129
|
+
"@knotx/decorators": "^0.0.1",
|
|
130
|
+
"@knotx/jsx": "^0.0.1",
|
|
131
|
+
"@knotx/build-config": "^0.0.1",
|
|
132
|
+
"@knotx/eslint-config": "^0.0.1",
|
|
133
|
+
"@knotx/typescript-config": "^0.0.1"
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function createPackageJson(targetDir, pluginName, environment, knotxVersions) {
|
|
110
139
|
return __async(this, null, function* () {
|
|
111
140
|
const packageJson = {
|
|
112
141
|
name: `@knotx/plugins-${pluginName}`,
|
|
@@ -139,14 +168,14 @@ function createPackageJson(targetDir, pluginName, environment) {
|
|
|
139
168
|
},
|
|
140
169
|
peerDependencies: {},
|
|
141
170
|
dependencies: {
|
|
142
|
-
"@knotx/core": "
|
|
143
|
-
"@knotx/decorators": "
|
|
144
|
-
"@knotx/jsx": "
|
|
171
|
+
"@knotx/core": knotxVersions["@knotx/core"],
|
|
172
|
+
"@knotx/decorators": knotxVersions["@knotx/decorators"],
|
|
173
|
+
"@knotx/jsx": knotxVersions["@knotx/jsx"]
|
|
145
174
|
},
|
|
146
175
|
devDependencies: {
|
|
147
|
-
"@knotx/build-config": "
|
|
148
|
-
"@knotx/eslint-config": "
|
|
149
|
-
"@knotx/typescript-config": "
|
|
176
|
+
"@knotx/build-config": knotxVersions["@knotx/build-config"],
|
|
177
|
+
"@knotx/eslint-config": knotxVersions["@knotx/eslint-config"],
|
|
178
|
+
"@knotx/typescript-config": knotxVersions["@knotx/typescript-config"],
|
|
150
179
|
"@types/node": "^22.13.5",
|
|
151
180
|
"eslint": "^9.23.0",
|
|
152
181
|
"typescript": "^5.7.3",
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { execSync } from 'node:child_process';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import process from 'node:process';
|
|
4
5
|
import chalk from 'chalk';
|
|
@@ -59,25 +60,24 @@ program.command("create-plugin").description("\u521B\u5EFA\u4E00\u4E2A\u65B0\u76
|
|
|
59
60
|
console.log(chalk.red(`\u274C \u9519\u8BEF: \u76EE\u5F55 ${fullPluginName} \u5DF2\u5B58\u5728`));
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
+
let spinner = ora("\u{1F4C2} \u521B\u5EFA\u63D2\u4EF6\u76EE\u5F55...").start();
|
|
63
64
|
try {
|
|
64
65
|
yield fs.ensureDir(targetDir);
|
|
65
66
|
yield fs.ensureDir(path.join(targetDir, "src"));
|
|
66
67
|
spinner.succeed("\u{1F4C2} \u63D2\u4EF6\u76EE\u5F55\u521B\u5EFA\u6210\u529F");
|
|
67
|
-
spinner
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
spinner = ora("\u{1F50D} \u83B7\u53D6 @knotx \u5305\u7684\u6700\u65B0\u7248\u672C...").start();
|
|
69
|
+
const knotxVersions = yield getKnotxPackageVersions();
|
|
70
|
+
spinner.succeed("\u{1F50D} @knotx \u5305\u7248\u672C\u4FE1\u606F\u83B7\u53D6\u6210\u529F");
|
|
71
|
+
spinner = ora("\u{1F4C4} \u521B\u5EFA package.json...").start();
|
|
72
|
+
yield createPackageJson(targetDir, pluginName, environment, knotxVersions);
|
|
70
73
|
spinner.succeed("\u{1F4C4} package.json \u521B\u5EFA\u6210\u529F");
|
|
71
|
-
spinner
|
|
72
|
-
spinner.start();
|
|
74
|
+
spinner = ora("\u{1F4C4} \u521B\u5EFA\u914D\u7F6E\u6587\u4EF6...").start();
|
|
73
75
|
yield createConfigFiles(targetDir);
|
|
74
76
|
spinner.succeed("\u{1F4C4} \u914D\u7F6E\u6587\u4EF6\u521B\u5EFA\u6210\u529F");
|
|
75
|
-
spinner
|
|
76
|
-
spinner.start();
|
|
77
|
+
spinner = ora("\u{1F4C4} \u521B\u5EFA\u6E90\u4EE3\u7801\u6587\u4EF6...").start();
|
|
77
78
|
yield createSourceFiles(targetDir, pluginName, environment);
|
|
78
79
|
spinner.succeed("\u{1F4C4} \u6E90\u4EE3\u7801\u6587\u4EF6\u521B\u5EFA\u6210\u529F");
|
|
79
|
-
spinner
|
|
80
|
-
spinner.start();
|
|
80
|
+
spinner = ora("\u{1F4C4} \u521B\u5EFA README.md...").start();
|
|
81
81
|
yield createReadme(targetDir, pluginName);
|
|
82
82
|
spinner.succeed("\u{1F4C4} README.md \u521B\u5EFA\u6210\u529F");
|
|
83
83
|
console.log(chalk.green(`
|
|
@@ -95,7 +95,36 @@ program.command("create-plugin").description("\u521B\u5EFA\u4E00\u4E2A\u65B0\u76
|
|
|
95
95
|
console.error(chalk.red(error));
|
|
96
96
|
}
|
|
97
97
|
}));
|
|
98
|
-
function
|
|
98
|
+
function getKnotxPackageVersions() {
|
|
99
|
+
return __async(this, null, function* () {
|
|
100
|
+
const knotxVersions = {};
|
|
101
|
+
try {
|
|
102
|
+
const packages = ["@knotx/core", "@knotx/decorators", "@knotx/jsx", "@knotx/build-config", "@knotx/eslint-config", "@knotx/typescript-config"];
|
|
103
|
+
const npmRegistry = "https://registry.npmjs.org";
|
|
104
|
+
for (const pkg of packages) {
|
|
105
|
+
try {
|
|
106
|
+
const version = execSync(`npm view ${pkg} version --registry=${npmRegistry}`, { encoding: "utf8" }).trim();
|
|
107
|
+
knotxVersions[pkg] = `^${version}`;
|
|
108
|
+
} catch (e) {
|
|
109
|
+
console.warn(chalk.yellow(`\u26A0\uFE0F \u65E0\u6CD5\u83B7\u53D6 ${pkg} \u7684\u6700\u65B0\u7248\u672C\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u7248\u672C`));
|
|
110
|
+
knotxVersions[pkg] = "^0.0.1";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return knotxVersions;
|
|
114
|
+
} catch (e) {
|
|
115
|
+
console.warn(chalk.yellow("\u26A0\uFE0F \u83B7\u53D6 @knotx \u5305\u7248\u672C\u5931\u8D25\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u7248\u672C"));
|
|
116
|
+
return {
|
|
117
|
+
"@knotx/core": "^0.0.1",
|
|
118
|
+
"@knotx/decorators": "^0.0.1",
|
|
119
|
+
"@knotx/jsx": "^0.0.1",
|
|
120
|
+
"@knotx/build-config": "^0.0.1",
|
|
121
|
+
"@knotx/eslint-config": "^0.0.1",
|
|
122
|
+
"@knotx/typescript-config": "^0.0.1"
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function createPackageJson(targetDir, pluginName, environment, knotxVersions) {
|
|
99
128
|
return __async(this, null, function* () {
|
|
100
129
|
const packageJson = {
|
|
101
130
|
name: `@knotx/plugins-${pluginName}`,
|
|
@@ -128,14 +157,14 @@ function createPackageJson(targetDir, pluginName, environment) {
|
|
|
128
157
|
},
|
|
129
158
|
peerDependencies: {},
|
|
130
159
|
dependencies: {
|
|
131
|
-
"@knotx/core": "
|
|
132
|
-
"@knotx/decorators": "
|
|
133
|
-
"@knotx/jsx": "
|
|
160
|
+
"@knotx/core": knotxVersions["@knotx/core"],
|
|
161
|
+
"@knotx/decorators": knotxVersions["@knotx/decorators"],
|
|
162
|
+
"@knotx/jsx": knotxVersions["@knotx/jsx"]
|
|
134
163
|
},
|
|
135
164
|
devDependencies: {
|
|
136
|
-
"@knotx/build-config": "
|
|
137
|
-
"@knotx/eslint-config": "
|
|
138
|
-
"@knotx/typescript-config": "
|
|
165
|
+
"@knotx/build-config": knotxVersions["@knotx/build-config"],
|
|
166
|
+
"@knotx/eslint-config": knotxVersions["@knotx/eslint-config"],
|
|
167
|
+
"@knotx/typescript-config": knotxVersions["@knotx/typescript-config"],
|
|
139
168
|
"@types/node": "^22.13.5",
|
|
140
169
|
"eslint": "^9.23.0",
|
|
141
170
|
"typescript": "^5.7.3",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "CLI tool for Knotx",
|
|
5
5
|
"author": "boenfu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/fs-extra": "^11.0.4",
|
|
42
42
|
"@types/inquirer": "^9.0.7",
|
|
43
|
-
"@knotx/build-config": "0.0.1",
|
|
44
43
|
"@knotx/eslint-config": "0.0.1",
|
|
45
|
-
"@knotx/typescript-config": "0.0.1"
|
|
44
|
+
"@knotx/typescript-config": "0.0.1",
|
|
45
|
+
"@knotx/build-config": "0.0.1"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "unbuild --failOnWarn=false",
|