@widget-js/cli 1.2.11 → 24.1.1-beta.10
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/.idea/codeStyles/Project.xml +60 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/misc.xml +5 -7
- package/jest.config.js +3 -3
- package/lib/{chunk-RAXJBANW.js → chunk-I4ZBPB2S.js} +6 -6
- package/lib/{chunk-IJH6LXRT.js → chunk-RDJH7Z4C.js} +5 -5
- package/lib/{chunk-3GPAHQ6O.js → chunk-XPJ33Y5L.js} +2 -2
- package/lib/{createWidget-UFW26NP6.js → createWidget-4LQ6PVEM.js} +16 -16
- package/lib/{dependencies-MRJDJJ6Q.js → dependencies-AVNHKRF3.js} +18 -18
- package/lib/index.js +13 -8
- package/lib/{init-MQONV3N3.js → init-HCEGKTNF.js} +15 -15
- package/lib/publish-C52GHJWG.js +50 -0
- package/lib/{release-XUYU5WNC.js → release-5GS34BAJ.js} +52 -48
- package/package.json +29 -18
- package/src/build/build.ts +8 -8
- package/src/createWidget.ts +232 -226
- package/src/dependencies/index.ts +6 -5
- package/src/dependencies/localDependencies.ts +17 -18
- package/src/dependencies/remoteDependencies.ts +22 -25
- package/src/index.ts +47 -38
- package/src/init/init.ts +121 -119
- package/src/promts/promptChecker.ts +10 -8
- package/src/publish/index.ts +60 -0
- package/src/release/ftp.ts +31 -27
- package/src/release/oss.ts +41 -38
- package/src/release/release.ts +17 -24
- package/src/release/update-zip.ts +18 -14
- package/src/utils/EJSUtils.ts +18 -17
- package/src/utils/PrettierUtils.ts +12 -11
- package/src/utils/WidgetPackageUtils.ts +13 -13
- package/src/utils.ts +31 -27
- package/template/WidgetConfig.ejs +7 -6
- package/template/WidgetDefine.ejs +6 -18
- package/template/widget-router.ts +4 -3
- package/test/index.test.ts +7 -7
- package/tsconfig.json +25 -25
- package/tsup.config.ts +4 -4
- package/vite.config.ts +15 -15
- package/.editorconfig +0 -16
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jpa-buddy.xml +0 -6
- package/.idea/prettier.xml +0 -6
- package/release-xyy.json +0 -7
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<component name="ProjectCodeStyleConfiguration">
|
|
2
|
+
<code_scheme name="Project" version="173">
|
|
3
|
+
<option name="LINE_SEPARATOR" value=" " />
|
|
4
|
+
<HTMLCodeStyleSettings>
|
|
5
|
+
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
|
6
|
+
</HTMLCodeStyleSettings>
|
|
7
|
+
<JSCodeStyleSettings version="0">
|
|
8
|
+
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
|
|
9
|
+
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
10
|
+
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
11
|
+
<option name="USE_DOUBLE_QUOTES" value="false" />
|
|
12
|
+
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
13
|
+
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
|
|
14
|
+
<option name="SPACES_WITHIN_OBJECT_TYPE_BRACES" value="false" />
|
|
15
|
+
</JSCodeStyleSettings>
|
|
16
|
+
<TypeScriptCodeStyleSettings version="0">
|
|
17
|
+
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
|
|
18
|
+
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
19
|
+
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
20
|
+
<option name="USE_DOUBLE_QUOTES" value="false" />
|
|
21
|
+
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
22
|
+
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
|
|
23
|
+
<option name="SPACES_WITHIN_OBJECT_TYPE_BRACES" value="false" />
|
|
24
|
+
</TypeScriptCodeStyleSettings>
|
|
25
|
+
<VueCodeStyleSettings>
|
|
26
|
+
<option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
|
|
27
|
+
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
|
|
28
|
+
</VueCodeStyleSettings>
|
|
29
|
+
<codeStyleSettings language="HTML">
|
|
30
|
+
<option name="SOFT_MARGINS" value="120" />
|
|
31
|
+
<indentOptions>
|
|
32
|
+
<option name="INDENT_SIZE" value="2" />
|
|
33
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
34
|
+
<option name="TAB_SIZE" value="2" />
|
|
35
|
+
</indentOptions>
|
|
36
|
+
</codeStyleSettings>
|
|
37
|
+
<codeStyleSettings language="JavaScript">
|
|
38
|
+
<option name="SOFT_MARGINS" value="120" />
|
|
39
|
+
<indentOptions>
|
|
40
|
+
<option name="INDENT_SIZE" value="2" />
|
|
41
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
42
|
+
<option name="TAB_SIZE" value="2" />
|
|
43
|
+
</indentOptions>
|
|
44
|
+
</codeStyleSettings>
|
|
45
|
+
<codeStyleSettings language="TypeScript">
|
|
46
|
+
<option name="SOFT_MARGINS" value="120" />
|
|
47
|
+
<indentOptions>
|
|
48
|
+
<option name="INDENT_SIZE" value="2" />
|
|
49
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
50
|
+
<option name="TAB_SIZE" value="2" />
|
|
51
|
+
</indentOptions>
|
|
52
|
+
</codeStyleSettings>
|
|
53
|
+
<codeStyleSettings language="Vue">
|
|
54
|
+
<option name="SOFT_MARGINS" value="120" />
|
|
55
|
+
<indentOptions>
|
|
56
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
57
|
+
</indentOptions>
|
|
58
|
+
</codeStyleSettings>
|
|
59
|
+
</code_scheme>
|
|
60
|
+
</component>
|
package/.idea/misc.xml
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
<option name="id" value="jpab" />
|
|
7
|
-
</component>
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectRootManager">
|
|
4
|
+
<output url="file://$PROJECT_DIR$/out" />
|
|
5
|
+
</component>
|
|
8
6
|
</project>
|
package/jest.config.js
CHANGED
|
@@ -5,10 +5,10 @@ module.exports = {
|
|
|
5
5
|
'**/?(*.)+(spec|test).+(ts|tsx|js)',
|
|
6
6
|
],
|
|
7
7
|
transform: {
|
|
8
|
-
'^.+\\.(ts|tsx)$': ['ts-jest',{
|
|
9
|
-
tsconfig: 'tsconfig.json'
|
|
8
|
+
'^.+\\.(ts|tsx)$': ['ts-jest', {
|
|
9
|
+
tsconfig: 'tsconfig.json',
|
|
10
10
|
}],
|
|
11
11
|
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
|
|
12
12
|
'./config/fileTransformer.js',
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
14
|
}
|
|
@@ -11,23 +11,23 @@ var PrettierUtils = class {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
// src/utils/EJSUtils.ts
|
|
14
|
-
import path from "path";
|
|
15
|
-
import fs from "fs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import fs from "node:fs";
|
|
16
16
|
import ejs from "ejs";
|
|
17
17
|
import { dirname } from "dirname-filename-esm";
|
|
18
18
|
var EJSUtils = class {
|
|
19
19
|
static async renderToFile(templateFile, outputFile, parser, renderOptions) {
|
|
20
20
|
const defineTemplatePath = path.join(dirname(import.meta), "../template", templateFile);
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const defineTemplate = fs.readFileSync(defineTemplatePath, "utf8");
|
|
22
|
+
const code = ejs.render(defineTemplate, renderOptions);
|
|
23
23
|
const formattedEJSCode = await PrettierUtils.format(code, parser);
|
|
24
24
|
fs.writeFileSync(outputFile, formattedEJSCode);
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
// src/utils/WidgetPackageUtils.ts
|
|
29
|
-
import path2 from "path";
|
|
30
|
-
import fs2 from "fs";
|
|
29
|
+
import path2 from "node:path";
|
|
30
|
+
import fs2 from "node:fs";
|
|
31
31
|
var WidgetPackageUtils = class {
|
|
32
32
|
static getRootDir(widgetPackage) {
|
|
33
33
|
const widgetRootDir = path2.join(process.cwd(), widgetPackage.devOptions?.folder ?? "./src/widgets");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/utils.ts
|
|
2
|
-
import path from "path";
|
|
3
|
-
import process from "process";
|
|
4
|
-
import fs from "fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import fs from "node:fs";
|
|
5
5
|
import packageJson from "package-json";
|
|
6
6
|
var widgetPackages = {
|
|
7
7
|
"@widget-js/core": "",
|
|
@@ -23,7 +23,7 @@ function getPackagePath() {
|
|
|
23
23
|
var Utils = class {
|
|
24
24
|
static async getRemoteVersion(packageName) {
|
|
25
25
|
const metadata = await packageJson(packageName);
|
|
26
|
-
|
|
26
|
+
const version = metadata.version;
|
|
27
27
|
return version;
|
|
28
28
|
}
|
|
29
29
|
static getPackagePath() {
|
|
@@ -33,7 +33,7 @@ var Utils = class {
|
|
|
33
33
|
return JSON.parse(fs.readFileSync(this.getPackagePath()).toString());
|
|
34
34
|
}
|
|
35
35
|
static getPackageVersion() {
|
|
36
|
-
return this.getPackageJson()
|
|
36
|
+
return this.getPackageJson().version;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* 检查包名是否合法,包名格式一般为 倒置域名与java包类似
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/promts/promptChecker.ts
|
|
2
2
|
import inquirer from "inquirer";
|
|
3
|
-
|
|
3
|
+
async function promptChecker(prompt, checker) {
|
|
4
4
|
const answer = await inquirer.prompt([prompt]);
|
|
5
5
|
if (checker) {
|
|
6
6
|
if (checker(answer)) {
|
|
@@ -10,7 +10,7 @@ var promptChecker = async (prompt, checker) => {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
return answer[prompt.name];
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
14
|
var promptChecker_default = promptChecker;
|
|
15
15
|
|
|
16
16
|
export {
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EJSUtils,
|
|
3
3
|
WidgetPackageUtils
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-I4ZBPB2S.js";
|
|
5
5
|
import {
|
|
6
6
|
promptChecker_default
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-XPJ33Y5L.js";
|
|
8
8
|
import {
|
|
9
9
|
exit
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-RDJH7Z4C.js";
|
|
11
11
|
|
|
12
12
|
// src/createWidget.ts
|
|
13
|
-
import path from "path";
|
|
14
|
-
import fs from "fs";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import fs from "node:fs";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
15
16
|
import consola from "consola";
|
|
16
17
|
import { paramCase, snakeCase } from "change-case";
|
|
17
18
|
import inquirer from "inquirer";
|
|
18
19
|
import shell from "shelljs";
|
|
19
20
|
import chalk from "chalk";
|
|
20
21
|
import { scanWidgetPackage } from "@widget-js/utils";
|
|
21
|
-
import { fileURLToPath } from "url";
|
|
22
22
|
var __filename = fileURLToPath(import.meta.url);
|
|
23
23
|
var __dirname = path.dirname(__filename);
|
|
24
24
|
async function createWidget() {
|
|
25
|
-
|
|
25
|
+
const widgetPackage = await scanWidgetPackage();
|
|
26
26
|
if (!widgetPackage) {
|
|
27
27
|
consola.error("widget.ts or widget.json not found");
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
const widgetRootDir = WidgetPackageUtils.getRootDir(widgetPackage);
|
|
31
31
|
if (widgetPackage.devOptions && widgetPackage.devOptions.folder) {
|
|
32
32
|
consola.info(`\u7EC4\u4EF6\u8DEF\u5F84\uFF1A${widgetRootDir}`);
|
|
33
33
|
} else {
|
|
@@ -45,7 +45,7 @@ async function createWidget() {
|
|
|
45
45
|
return sum - max - min;
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
-
|
|
48
|
+
const name = await promptChecker_default(
|
|
49
49
|
{
|
|
50
50
|
type: "input",
|
|
51
51
|
name: "name",
|
|
@@ -61,13 +61,13 @@ async function createWidget() {
|
|
|
61
61
|
}
|
|
62
62
|
);
|
|
63
63
|
consola.log(chalk.green(name));
|
|
64
|
-
|
|
64
|
+
const title = await promptChecker_default({
|
|
65
65
|
type: "input",
|
|
66
66
|
name: "title",
|
|
67
67
|
message: chalk.blue("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u6807\u9898\uFF0C\u5982\uFF1A\u5012\u8BA1\u65F6")
|
|
68
68
|
});
|
|
69
69
|
consola.log(chalk.green(title));
|
|
70
|
-
|
|
70
|
+
const answerW = await promptChecker_default(
|
|
71
71
|
{
|
|
72
72
|
type: "checkbox",
|
|
73
73
|
name: "w",
|
|
@@ -89,7 +89,7 @@ async function createWidget() {
|
|
|
89
89
|
}
|
|
90
90
|
);
|
|
91
91
|
consola.log(chalk.green(answerW));
|
|
92
|
-
|
|
92
|
+
const answerH = await promptChecker_default(
|
|
93
93
|
{
|
|
94
94
|
type: "checkbox",
|
|
95
95
|
name: "h",
|
|
@@ -111,7 +111,7 @@ async function createWidget() {
|
|
|
111
111
|
}
|
|
112
112
|
);
|
|
113
113
|
consola.log(chalk.green(answerH));
|
|
114
|
-
|
|
114
|
+
const configurable = await promptChecker_default({
|
|
115
115
|
type: "confirm",
|
|
116
116
|
name: "configurable",
|
|
117
117
|
message: chalk.blue("\u7EC4\u4EF6\u662F\u5426\u53EF\u914D\u7F6E\uFF0C\u4F8B\u5982\u4FEE\u6539\u80CC\u666F\u989C\u8272\uFF0C\u5B57\u4F53\u5927\u5C0F\u7B49")
|
|
@@ -125,12 +125,12 @@ async function createWidget() {
|
|
|
125
125
|
const maxHeight = Math.max(...answerH);
|
|
126
126
|
const snakeCaseName = snakeCase(name);
|
|
127
127
|
const paramCaseName = paramCase(name);
|
|
128
|
-
const widgetName = widgetPackage.name
|
|
128
|
+
const widgetName = `${widgetPackage.name}.${snakeCaseName}`;
|
|
129
129
|
const widgetDir = path.join(widgetRootDir, paramCaseName);
|
|
130
130
|
if (!fs.existsSync(widgetDir)) {
|
|
131
131
|
fs.mkdirSync(widgetDir);
|
|
132
132
|
} else {
|
|
133
|
-
|
|
133
|
+
const answer = await inquirer.prompt([
|
|
134
134
|
{
|
|
135
135
|
type: "confirm",
|
|
136
136
|
name: "override",
|
|
@@ -188,7 +188,7 @@ async function createWidget() {
|
|
|
188
188
|
//FBI WANING! ROUTE PLACE`);
|
|
189
189
|
}
|
|
190
190
|
fs.writeFileSync(routeFile, routeContent);
|
|
191
|
-
|
|
191
|
+
const gitAdd = `git add ${widgetDir}`;
|
|
192
192
|
consola.info(chalk.grey(gitAdd));
|
|
193
193
|
shell.exec(gitAdd);
|
|
194
194
|
consola.log("=================");
|
|
@@ -2,20 +2,20 @@ import {
|
|
|
2
2
|
Utils,
|
|
3
3
|
getPackagePath,
|
|
4
4
|
widgetPackages
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-RDJH7Z4C.js";
|
|
6
6
|
|
|
7
7
|
// src/dependencies/remoteDependencies.ts
|
|
8
|
+
import fs from "node:fs";
|
|
8
9
|
import ora from "ora";
|
|
9
|
-
import fs from "fs";
|
|
10
10
|
var spinner = ora("Connecting");
|
|
11
11
|
var RemoteDependencies;
|
|
12
12
|
((RemoteDependencies2) => {
|
|
13
13
|
async function start() {
|
|
14
14
|
spinner.start();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const json = Utils.getPackageJson();
|
|
16
|
+
const packageNames = Object.keys(widgetPackages);
|
|
17
|
+
const dependencies = json.dependencies;
|
|
18
|
+
const devDependencies = json.devDependencies;
|
|
19
19
|
await upgradePackage(dependencies, packageNames);
|
|
20
20
|
await upgradePackage(devDependencies, packageNames);
|
|
21
21
|
fs.writeFileSync(getPackagePath(), JSON.stringify(json, null, 2));
|
|
@@ -23,9 +23,9 @@ var RemoteDependencies;
|
|
|
23
23
|
}
|
|
24
24
|
RemoteDependencies2.start = start;
|
|
25
25
|
async function upgradePackage(dependencies, packageNames) {
|
|
26
|
-
|
|
27
|
-
for (
|
|
28
|
-
if (packageNames.
|
|
26
|
+
const localPackages = Object.keys(dependencies);
|
|
27
|
+
for (const localPackage of localPackages) {
|
|
28
|
+
if (packageNames.includes(localPackage)) {
|
|
29
29
|
let packageVersion = widgetPackages[localPackage];
|
|
30
30
|
if (!packageVersion) {
|
|
31
31
|
spinner.info(`Fetching package version:${localPackage}`);
|
|
@@ -40,17 +40,17 @@ var RemoteDependencies;
|
|
|
40
40
|
})(RemoteDependencies || (RemoteDependencies = {}));
|
|
41
41
|
|
|
42
42
|
// src/dependencies/localDependencies.ts
|
|
43
|
+
import fs2 from "node:fs";
|
|
43
44
|
import ora2 from "ora";
|
|
44
|
-
import fs2 from "fs";
|
|
45
45
|
var spinner2 = ora2("Connecting");
|
|
46
46
|
var LocalDependencies;
|
|
47
47
|
((LocalDependencies2) => {
|
|
48
48
|
async function start() {
|
|
49
49
|
spinner2.start();
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
const json = Utils.getPackageJson();
|
|
51
|
+
const packageNames = Object.keys(widgetPackages);
|
|
52
|
+
const dependencies = json.dependencies;
|
|
53
|
+
const devDependencies = json.devDependencies;
|
|
54
54
|
await setWorkspaceVersion(dependencies, packageNames);
|
|
55
55
|
await setWorkspaceVersion(devDependencies, packageNames);
|
|
56
56
|
fs2.writeFileSync(getPackagePath(), JSON.stringify(json, null, 2));
|
|
@@ -58,9 +58,9 @@ var LocalDependencies;
|
|
|
58
58
|
}
|
|
59
59
|
LocalDependencies2.start = start;
|
|
60
60
|
async function setWorkspaceVersion(dependencies, packageNames) {
|
|
61
|
-
|
|
62
|
-
for (
|
|
63
|
-
if (packageNames.
|
|
61
|
+
const localPackages = Object.keys(dependencies);
|
|
62
|
+
for (const localPackage of localPackages) {
|
|
63
|
+
if (packageNames.includes(localPackage)) {
|
|
64
64
|
dependencies[localPackage] = `workspace:*`;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -69,7 +69,7 @@ var LocalDependencies;
|
|
|
69
69
|
|
|
70
70
|
// src/dependencies/index.ts
|
|
71
71
|
async function dependencies_default(options) {
|
|
72
|
-
|
|
72
|
+
const type = options.type;
|
|
73
73
|
if (type == "remote") {
|
|
74
74
|
await RemoteDependencies.start();
|
|
75
75
|
} else {
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import * as process from "node:process";
|
|
2
5
|
import { Option, program } from "commander";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import * as process from "process";
|
|
6
6
|
import figlet from "figlet";
|
|
7
7
|
import gradient from "gradient-string";
|
|
8
8
|
import { dirname } from "dirname-filename-esm";
|
|
@@ -11,22 +11,27 @@ var cliPackage = JSON.parse(fs.readFileSync(packageJsonPath).toString());
|
|
|
11
11
|
console.log(gradient.pastel.multiline(figlet.textSync("widget-cli", { horizontalLayout: "full" })));
|
|
12
12
|
program.version(`@widget-js/cli ${cliPackage.version}`).usage("<command> [options]");
|
|
13
13
|
program.command("create").description("Create new widget").action(async () => {
|
|
14
|
-
const createWidget = await import("./createWidget-
|
|
14
|
+
const createWidget = await import("./createWidget-4LQ6PVEM.js");
|
|
15
15
|
await createWidget.default();
|
|
16
16
|
});
|
|
17
17
|
var dependenciesOption = new Option("-t, --type <type>").choices(["remote", "local"]);
|
|
18
18
|
program.command("dependencies").description("Set @widget-js dependencies to local(workspace:*) or remote(^1.0.0 etc)").addOption(dependenciesOption).action(async (options) => {
|
|
19
|
-
|
|
19
|
+
const dependencies = await import("./dependencies-AVNHKRF3.js");
|
|
20
20
|
await dependencies.default(options);
|
|
21
21
|
});
|
|
22
22
|
program.command("init").description("Initialize widget-js project").action(async () => {
|
|
23
|
-
const init = await import("./init-
|
|
23
|
+
const init = await import("./init-HCEGKTNF.js");
|
|
24
24
|
await init.init();
|
|
25
25
|
});
|
|
26
|
+
var keyOption = new Option("-k, --key <key>");
|
|
27
|
+
program.command("publish").description("Publish widget package with developer key").addOption(keyOption).action(async (options) => {
|
|
28
|
+
const publishImport = await import("./publish-C52GHJWG.js");
|
|
29
|
+
await publishImport.publish(options);
|
|
30
|
+
});
|
|
26
31
|
var typeOption = new Option("-t, --type <type>").choices(["ftp", "oss"]);
|
|
27
32
|
var fileOption = new Option("-f, --file <file>");
|
|
28
|
-
program.command("release").description("\u901A\u8FC7FTP/OSS\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").addOption(typeOption).addOption(fileOption).action(async (options
|
|
29
|
-
|
|
33
|
+
program.command("release").description("\u901A\u8FC7FTP/OSS\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").addOption(typeOption).addOption(fileOption).action(async (options) => {
|
|
34
|
+
const release = await import("./release-5GS34BAJ.js");
|
|
30
35
|
await release.default(options);
|
|
31
36
|
});
|
|
32
37
|
program.parse(process.argv);
|
|
@@ -2,23 +2,23 @@ import {
|
|
|
2
2
|
EJSUtils,
|
|
3
3
|
PrettierUtils,
|
|
4
4
|
WidgetPackageUtils
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-I4ZBPB2S.js";
|
|
6
6
|
import {
|
|
7
7
|
promptChecker_default
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-XPJ33Y5L.js";
|
|
9
9
|
import {
|
|
10
10
|
Utils
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-RDJH7Z4C.js";
|
|
12
12
|
|
|
13
13
|
// src/init/init.ts
|
|
14
|
-
import path from "path";
|
|
15
|
-
import process from "process";
|
|
16
|
-
import fs from "fs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import process from "node:process";
|
|
16
|
+
import fs from "node:fs";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
17
18
|
import consola from "consola";
|
|
18
19
|
import chalk from "chalk";
|
|
19
20
|
import ora from "ora";
|
|
20
21
|
import { scanWidgetPackage } from "@widget-js/utils";
|
|
21
|
-
import { fileURLToPath } from "url";
|
|
22
22
|
var __filename = fileURLToPath(import.meta.url);
|
|
23
23
|
var __dirname = path.dirname(__filename);
|
|
24
24
|
var spinner = ora("Loading");
|
|
@@ -27,7 +27,7 @@ async function init() {
|
|
|
27
27
|
await addWidgetTs();
|
|
28
28
|
}
|
|
29
29
|
async function addWidgetTs() {
|
|
30
|
-
|
|
30
|
+
const name = await promptChecker_default(
|
|
31
31
|
{
|
|
32
32
|
type: "input",
|
|
33
33
|
name: "name",
|
|
@@ -42,7 +42,7 @@ async function addWidgetTs() {
|
|
|
42
42
|
return true;
|
|
43
43
|
}
|
|
44
44
|
);
|
|
45
|
-
|
|
45
|
+
const widgetPackageTs = path.join(process.cwd(), "widget.package.ts");
|
|
46
46
|
if (fs.existsSync(widgetPackageTs)) {
|
|
47
47
|
spinner.info("widget.package.ts\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
48
48
|
} else {
|
|
@@ -55,19 +55,19 @@ async function addWidgetTs() {
|
|
|
55
55
|
}
|
|
56
56
|
async function addDependencies() {
|
|
57
57
|
const packageJson = Utils.getPackageJson();
|
|
58
|
-
let dependencies = packageJson
|
|
59
|
-
|
|
58
|
+
let dependencies = packageJson.dependencies;
|
|
59
|
+
const devDependencies = packageJson.devDependencies;
|
|
60
60
|
if (!dependencies) {
|
|
61
61
|
dependencies = {};
|
|
62
62
|
}
|
|
63
63
|
if (!devDependencies) {
|
|
64
|
-
packageJson
|
|
64
|
+
packageJson.devDependencies = {};
|
|
65
65
|
}
|
|
66
66
|
await addDependency("@widget-js/core", dependencies);
|
|
67
67
|
await addDependency("@widget-js/vue3", dependencies);
|
|
68
68
|
await addDependency("@widget-js/vite-plugin-widget", devDependencies);
|
|
69
|
-
packageJson
|
|
70
|
-
packageJson
|
|
69
|
+
packageJson.dependencies = dependencies;
|
|
70
|
+
packageJson.devDependencies = devDependencies;
|
|
71
71
|
fs.writeFileSync(Utils.getPackagePath(), JSON.stringify(packageJson, null, 2));
|
|
72
72
|
}
|
|
73
73
|
async function addVitePlugin() {
|
|
@@ -79,7 +79,7 @@ async function addVitePlugin() {
|
|
|
79
79
|
}
|
|
80
80
|
let viteConfig = fs.readFileSync(viteConfigPath).toString();
|
|
81
81
|
viteConfig = `import widget from '@widget-js/vite-plugin-widget'
|
|
82
|
-
|
|
82
|
+
${viteConfig}`;
|
|
83
83
|
viteConfig = viteConfig.replace("vue()", `vue(),widget()`);
|
|
84
84
|
fs.writeFileSync(viteConfigPath, await PrettierUtils.format(viteConfig, "typescript"));
|
|
85
85
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// src/publish/index.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import fastGlob from "fast-glob";
|
|
4
|
+
import axios from "axios";
|
|
5
|
+
import consola from "consola";
|
|
6
|
+
import ora from "ora";
|
|
7
|
+
async function publish(options) {
|
|
8
|
+
if (!options.key) {
|
|
9
|
+
consola.error("Please provide a developer key with -k or --key option.");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const spinner = ora("Search widget.json").start();
|
|
13
|
+
try {
|
|
14
|
+
const files = await fastGlob("**/widget.json", { onlyFiles: true, ignore: ["node_modules/**"], absolute: true });
|
|
15
|
+
if (files.length === 0) {
|
|
16
|
+
spinner.fail("No widget.json file found.");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
spinner.succeed(`Widget.json found: ${files[0]}`);
|
|
20
|
+
const widgetPath = files[0];
|
|
21
|
+
const widgetContent = fs.readFileSync(widgetPath, "utf-8");
|
|
22
|
+
const json = JSON.parse(widgetContent);
|
|
23
|
+
consola.info(`Package name:${json.name}`);
|
|
24
|
+
const widgets = json.widgets;
|
|
25
|
+
consola.info(`Widget size:${widgets?.length ?? 0}`);
|
|
26
|
+
spinner.start("Publishing widget package...");
|
|
27
|
+
const response = await axios.post("https://widgetjs.cn/api/v1/widget/package", json, {
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/json",
|
|
30
|
+
"Key": options.key
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
if (response.data) {
|
|
34
|
+
if (response.data.code == 200) {
|
|
35
|
+
spinner.succeed("Widget published successfully.");
|
|
36
|
+
} else {
|
|
37
|
+
spinner.fail("Failed to publish widget.");
|
|
38
|
+
consola.error(response.data.msg);
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
spinner.fail("Empty Response");
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
spinner.fail("Failed to publish widget.");
|
|
45
|
+
consola.error(error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
publish
|
|
50
|
+
};
|