@widget-js/cli 1.2.7 → 1.2.8
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/lib/{chunk-36QWOCKO.js → chunk-YHUBPHJK.js} +14 -6
- package/lib/{createWidget-UCZL7NIF.js → createWidget-SD5E5C5P.js} +1 -1
- package/lib/index.js +2 -2
- package/lib/{init-2NOIC3PQ.js → init-AO2J5DEO.js} +22 -7
- package/package.json +5 -3
- package/src/init/init.ts +93 -76
- package/src/utils/EJSUtils.ts +17 -25
- package/src/utils/PrettierUtils.ts +11 -0
- package/template/WidgetPackage.ejs +0 -2
- package/vite.config.ts +15 -0
- package/widget.package.ts +20 -23
|
@@ -1,23 +1,31 @@
|
|
|
1
|
+
// src/utils/PrettierUtils.ts
|
|
2
|
+
import prettier from "prettier";
|
|
3
|
+
var PrettierUtils = class {
|
|
4
|
+
static format(code, parser) {
|
|
5
|
+
return prettier.format(code, {
|
|
6
|
+
parser,
|
|
7
|
+
tabWidth: 2,
|
|
8
|
+
singleQuote: true
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
1
13
|
// src/utils/EJSUtils.ts
|
|
2
14
|
import path from "path";
|
|
3
15
|
import fs from "fs";
|
|
4
16
|
import ejs from "ejs";
|
|
5
|
-
import prettier from "prettier";
|
|
6
17
|
import { dirname } from "dirname-filename-esm";
|
|
7
18
|
var EJSUtils = class {
|
|
8
19
|
static renderToFile(templateFile, outputFile, parser, renderOptions) {
|
|
9
20
|
const defineTemplatePath = path.join(dirname(import.meta), "../template", templateFile);
|
|
10
21
|
let defineTemplate = fs.readFileSync(defineTemplatePath, "utf8");
|
|
11
22
|
let code = ejs.render(defineTemplate, renderOptions);
|
|
12
|
-
const formattedEJSCode =
|
|
13
|
-
parser,
|
|
14
|
-
tabWidth: 2,
|
|
15
|
-
singleQuote: true
|
|
16
|
-
});
|
|
23
|
+
const formattedEJSCode = PrettierUtils.format(code, parser);
|
|
17
24
|
fs.writeFileSync(outputFile, formattedEJSCode);
|
|
18
25
|
}
|
|
19
26
|
};
|
|
20
27
|
|
|
21
28
|
export {
|
|
29
|
+
PrettierUtils,
|
|
22
30
|
EJSUtils
|
|
23
31
|
};
|
package/lib/index.js
CHANGED
|
@@ -11,7 +11,7 @@ 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-SD5E5C5P.js");
|
|
15
15
|
await createWidget.default();
|
|
16
16
|
});
|
|
17
17
|
var dependenciesOption = new Option("-t, --type <type>").choices(["remote", "local"]);
|
|
@@ -20,7 +20,7 @@ program.command("dependencies").description("Set @widget-js dependencies to loca
|
|
|
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-AO2J5DEO.js");
|
|
24
24
|
await init.init();
|
|
25
25
|
});
|
|
26
26
|
var typeOption = new Option("-t, --type <type>").choices(["ftp", "oss"]);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
EJSUtils
|
|
3
|
-
|
|
2
|
+
EJSUtils,
|
|
3
|
+
PrettierUtils
|
|
4
|
+
} from "./chunk-YHUBPHJK.js";
|
|
4
5
|
import {
|
|
5
6
|
promptChecker_default
|
|
6
7
|
} from "./chunk-3GPAHQ6O.js";
|
|
@@ -25,23 +26,24 @@ async function addWidgetTs() {
|
|
|
25
26
|
{
|
|
26
27
|
type: "input",
|
|
27
28
|
name: "name",
|
|
28
|
-
message: chalk.blue("\
|
|
29
|
+
message: chalk.blue("\u7EC4\u4EF6\u5305\u540D \uFF08\u793A\u4F8B cn.widget.countdown\uFF09\uFF1A")
|
|
29
30
|
},
|
|
30
31
|
(answer) => {
|
|
31
32
|
const name2 = answer.name;
|
|
32
33
|
if (name2 == null || name2 === "") {
|
|
33
|
-
consola.log(chalk.red(
|
|
34
|
+
consola.log(chalk.red(`\u7EC4\u4EF6\u5305\u540D\u4E0D\u80FD\u4E3A\u7A7A`));
|
|
34
35
|
return false;
|
|
35
36
|
}
|
|
36
37
|
return true;
|
|
37
38
|
}
|
|
38
39
|
);
|
|
39
|
-
let widgetTs = path.join(process.cwd(), "widget.ts");
|
|
40
|
+
let widgetTs = path.join(process.cwd(), "widget.package.ts");
|
|
40
41
|
if (!fs.existsSync(widgetTs)) {
|
|
41
|
-
spinner.info("creating widget.ts");
|
|
42
|
+
spinner.info("creating widget.package.ts");
|
|
42
43
|
EJSUtils.renderToFile("WidgetPackage.ejs", widgetTs, "typescript", { name });
|
|
43
|
-
spinner.succeed("Done! Be sure to replace the contents of widget.ts with your own.");
|
|
44
44
|
}
|
|
45
|
+
addVitePlugin();
|
|
46
|
+
spinner.succeed("Done! Be sure to replace the contents of widget.package.ts with your own.");
|
|
45
47
|
}
|
|
46
48
|
async function addDependencies() {
|
|
47
49
|
spinner.info("Adding dependencies");
|
|
@@ -61,6 +63,19 @@ async function addDependencies() {
|
|
|
61
63
|
packageJson["devDependencies"] = devDependencies;
|
|
62
64
|
fs.writeFileSync(Utils.getPackagePath(), JSON.stringify(packageJson, null, 2));
|
|
63
65
|
}
|
|
66
|
+
async function addVitePlugin() {
|
|
67
|
+
spinner.info("Adding vite plugin");
|
|
68
|
+
const viteConfigPath = path.join(process.cwd(), "vite.config.ts");
|
|
69
|
+
if (!fs.existsSync(viteConfigPath)) {
|
|
70
|
+
spinner.warn("vite.config.ts not exists");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
let viteConfig = fs.readFileSync(viteConfigPath).toString();
|
|
74
|
+
viteConfig = viteConfig.replace("import", `import widget from '@widget-js/vite-plugin-widget'
|
|
75
|
+
import`);
|
|
76
|
+
viteConfig = viteConfig.replace("vue()", `vue(),widget()`);
|
|
77
|
+
fs.writeFileSync(viteConfigPath, PrettierUtils.format(viteConfig, "typescript"));
|
|
78
|
+
}
|
|
64
79
|
async function addDependency(packageName, dependencies) {
|
|
65
80
|
spinner.info(`Adding dependencies ${packageName}`);
|
|
66
81
|
if (dependencies[packageName]) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widget-js/cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"author": "Neo Fu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"shelljs": "^0.8.5",
|
|
40
40
|
"ssh2-sftp-client": "^9.1.0",
|
|
41
41
|
"ws": "^8.11.0",
|
|
42
|
+
"@widget-js/core": "^0.11.20",
|
|
42
43
|
"@widget-js/utils": "0.10.21"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
@@ -63,8 +64,9 @@
|
|
|
63
64
|
"vue-router": "^4.2.5",
|
|
64
65
|
"webpack": "^5.75.0",
|
|
65
66
|
"webpack-cli": "^5.0.0",
|
|
66
|
-
"@widget-js/
|
|
67
|
-
"@widget-js/core": "0.11.
|
|
67
|
+
"@widget-js/vite-plugin-widget": "^1.2.8",
|
|
68
|
+
"@widget-js/core": "0.11.21",
|
|
69
|
+
"@widget-js/vue3": "^0.11.20"
|
|
68
70
|
},
|
|
69
71
|
"scripts": {
|
|
70
72
|
"build": "rimraf ./lib/ && tsup-node src/index.ts --format esm",
|
package/src/init/init.ts
CHANGED
|
@@ -1,76 +1,93 @@
|
|
|
1
|
-
import {Utils} from
|
|
2
|
-
import path from
|
|
3
|
-
import process from
|
|
4
|
-
import fs from
|
|
5
|
-
import consola from
|
|
6
|
-
import promptChecker from
|
|
7
|
-
import chalk from
|
|
8
|
-
import {EJSUtils} from
|
|
9
|
-
import ora from
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
1
|
+
import {Utils} from '../utils'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import process from 'process'
|
|
4
|
+
import fs from 'fs'
|
|
5
|
+
import consola from 'consola'
|
|
6
|
+
import promptChecker from '../promts/promptChecker'
|
|
7
|
+
import chalk from 'chalk'
|
|
8
|
+
import {EJSUtils} from '../utils/EJSUtils'
|
|
9
|
+
import ora from 'ora'
|
|
10
|
+
import {vi} from 'vitest'
|
|
11
|
+
import {PrettierUtils} from '../utils/PrettierUtils'
|
|
12
|
+
|
|
13
|
+
const spinner = ora('Loading')
|
|
14
|
+
|
|
15
|
+
export async function init() {
|
|
16
|
+
await addDependencies()
|
|
17
|
+
await addWidgetTs()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function addWidgetTs() {
|
|
21
|
+
let name = await promptChecker(
|
|
22
|
+
{
|
|
23
|
+
type: 'input',
|
|
24
|
+
name: 'name',
|
|
25
|
+
message: chalk.blue('组件包名 (示例 cn.widget.countdown):'),
|
|
26
|
+
},
|
|
27
|
+
answer => {
|
|
28
|
+
const name = answer.name
|
|
29
|
+
if (name == null || name === '') {
|
|
30
|
+
consola.log(chalk.red(`组件包名不能为空`))
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
return true
|
|
34
|
+
},
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
let widgetTs = path.join(process.cwd(), 'widget.package.ts')
|
|
38
|
+
if (!fs.existsSync(widgetTs)) {
|
|
39
|
+
spinner.info('creating widget.package.ts')
|
|
40
|
+
EJSUtils.renderToFile('WidgetPackage.ejs', widgetTs, 'typescript', {name})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
addVitePlugin()
|
|
44
|
+
|
|
45
|
+
spinner.succeed('Done! Be sure to replace the contents of widget.package.ts with your own.')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 增加widget-js依赖
|
|
50
|
+
*/
|
|
51
|
+
async function addDependencies() {
|
|
52
|
+
spinner.info('Adding dependencies')
|
|
53
|
+
const packageJson = Utils.getPackageJson()
|
|
54
|
+
let dependencies = packageJson['dependencies']
|
|
55
|
+
let devDependencies = packageJson['devDependencies']
|
|
56
|
+
if (!dependencies) {
|
|
57
|
+
dependencies = {}
|
|
58
|
+
}
|
|
59
|
+
if (!devDependencies) {
|
|
60
|
+
packageJson['devDependencies'] = {}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
await addDependency('@widget-js/core', dependencies)
|
|
64
|
+
await addDependency('@widget-js/vue3', dependencies)
|
|
65
|
+
await addDependency('@widget-js/vite-plugin-widget', devDependencies)
|
|
66
|
+
|
|
67
|
+
packageJson['dependencies'] = dependencies
|
|
68
|
+
packageJson['devDependencies'] = devDependencies
|
|
69
|
+
|
|
70
|
+
fs.writeFileSync(Utils.getPackagePath(), JSON.stringify(packageJson, null, 2))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function addVitePlugin() {
|
|
74
|
+
spinner.info('Adding vite plugin')
|
|
75
|
+
const viteConfigPath = path.join(process.cwd(), 'vite.config.ts')
|
|
76
|
+
if (!fs.existsSync(viteConfigPath)) {
|
|
77
|
+
spinner.warn('vite.config.ts not exists')
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
let viteConfig = fs.readFileSync(viteConfigPath).toString()
|
|
81
|
+
viteConfig = viteConfig.replace('import', `import widget from '@widget-js/vite-plugin-widget'\nimport`)
|
|
82
|
+
viteConfig = viteConfig.replace('vue()', `vue(),widget()`)
|
|
83
|
+
fs.writeFileSync(viteConfigPath, PrettierUtils.format(viteConfig, 'typescript'))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function addDependency(packageName: string, dependencies: any) {
|
|
87
|
+
spinner.info(`Adding dependencies ${packageName}`)
|
|
88
|
+
if (dependencies[packageName]) {
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
const remoteVersion = await Utils.getRemoteVersion(packageName)
|
|
92
|
+
dependencies[packageName] = `^${remoteVersion}`
|
|
93
|
+
}
|
package/src/utils/EJSUtils.ts
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import fs from
|
|
3
|
-
import ejs, {Data} from
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const formattedEJSCode = prettier.format(code, {
|
|
19
|
-
parser: parser,
|
|
20
|
-
tabWidth: 2,
|
|
21
|
-
singleQuote: true,
|
|
22
|
-
})
|
|
23
|
-
fs.writeFileSync(outputFile, formattedEJSCode)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import ejs, {Data} from 'ejs'
|
|
4
|
+
import {BuiltInParserName} from 'prettier'
|
|
5
|
+
import {dirname} from 'dirname-filename-esm'
|
|
6
|
+
import {PrettierUtils} from './PrettierUtils'
|
|
7
|
+
|
|
8
|
+
export class EJSUtils {
|
|
9
|
+
static renderToFile(templateFile: string, outputFile: string, parser: BuiltInParserName, renderOptions: Data) {
|
|
10
|
+
const defineTemplatePath = path.join(dirname(import.meta), '../template', templateFile)
|
|
11
|
+
let defineTemplate = fs.readFileSync(defineTemplatePath, 'utf8')
|
|
12
|
+
// Format the EJS code using Prettier
|
|
13
|
+
let code = ejs.render(defineTemplate, renderOptions)
|
|
14
|
+
const formattedEJSCode = PrettierUtils.format(code,parser)
|
|
15
|
+
fs.writeFileSync(outputFile, formattedEJSCode)
|
|
16
|
+
}
|
|
17
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import widget from '@widget-js/vite-plugin-widget';
|
|
2
|
+
import { fileURLToPath, URL } from 'node:url';
|
|
3
|
+
|
|
4
|
+
import { defineConfig } from 'vite';
|
|
5
|
+
import vue from '@vitejs/plugin-vue';
|
|
6
|
+
|
|
7
|
+
// https://vitejs.dev/config/
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
plugins: [vue(), widget()],
|
|
10
|
+
resolve: {
|
|
11
|
+
alias: {
|
|
12
|
+
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
});
|
package/widget.package.ts
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import {WidgetPackage} from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
devUrl: "http://localhost:5173/hotspot"
|
|
22
|
-
}
|
|
23
|
-
});
|
|
1
|
+
import { WidgetPackage } from '@widget-js/core';
|
|
2
|
+
|
|
3
|
+
//TODO 完善组件包信息
|
|
4
|
+
export default new WidgetPackage({
|
|
5
|
+
author: '修改成你的信息',
|
|
6
|
+
description: {
|
|
7
|
+
'zh-CN': '修改成你的组件描述',
|
|
8
|
+
},
|
|
9
|
+
entry: 'index.html',
|
|
10
|
+
hash: true,
|
|
11
|
+
homepage: '',
|
|
12
|
+
name: 'cn.te',
|
|
13
|
+
title: {
|
|
14
|
+
'zh-CN': '修改成你的组件标题',
|
|
15
|
+
},
|
|
16
|
+
version: '1.0.0',
|
|
17
|
+
devOptions: {
|
|
18
|
+
folder: './src/widgets/',
|
|
19
|
+
},
|
|
20
|
+
});
|