@widget-js/cli 1.2.11 → 24.1.1-beta.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/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 +7 -7
- package/lib/{init-MQONV3N3.js → init-HCEGKTNF.js} +15 -15
- package/lib/{release-XUYU5WNC.js → release-PIRAQ7A6.js} +47 -47
- package/package.json +17 -15
- package/src/build/build.ts +8 -8
- package/src/createWidget.ts +46 -40
- 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 +36 -36
- package/src/init/init.ts +23 -21
- package/src/promts/promptChecker.ts +10 -8
- 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 +14 -14
- package/src/utils/EJSUtils.ts +10 -9
- package/src/utils/PrettierUtils.ts +3 -2
- package/src/utils/WidgetPackageUtils.ts +5 -5
- package/src/utils.ts +31 -27
- package/template/WidgetConfig.ejs +7 -6
- package/template/widget-router.ts +5 -4
- package/test/index.test.ts +7 -7
- package/tsconfig.json +25 -25
- package/tsup.config.ts +4 -4
- package/vite.config.ts +5 -5
- package/release-xyy.json +0 -7
package/package.json
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widget-js/cli",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "24.1.1-beta.2",
|
|
5
|
+
"private": false,
|
|
5
6
|
"author": "Neo Fu",
|
|
6
7
|
"license": "MIT",
|
|
7
|
-
"
|
|
8
|
+
"main": "lib/index.js",
|
|
8
9
|
"bin": {
|
|
9
10
|
"widget": "lib/index.js"
|
|
10
11
|
},
|
|
11
|
-
"type": "module",
|
|
12
|
-
"publishConfig": {
|
|
13
|
-
"access": "public"
|
|
14
|
-
},
|
|
15
12
|
"engines": {
|
|
16
13
|
"node": "^12.0.0 || >= 14.0.0"
|
|
17
14
|
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@types/archiver": "^5.3.1",
|
|
20
20
|
"@types/gradient-string": "^1.1.2",
|
|
21
21
|
"@vue/cli-shared-utils": "^5.0.8",
|
|
22
22
|
"@widget-js/ssh-config": "^4.2.1",
|
|
23
|
+
"@widget-js/vue3": "^0.11.20",
|
|
23
24
|
"ali-oss": "^6.17.1",
|
|
24
25
|
"archiver": "^5.3.1",
|
|
25
26
|
"chalk": "^4.1.2",
|
|
@@ -29,19 +30,17 @@
|
|
|
29
30
|
"dirname-filename-esm": "^1.1.1",
|
|
30
31
|
"ejs": "^3.1.8",
|
|
31
32
|
"figlet": "^1.5.2",
|
|
32
|
-
"gradient-string": "^2.0.2",
|
|
33
33
|
"inquirer": "^8.0.0",
|
|
34
34
|
"minimatch": "^9.0.3",
|
|
35
35
|
"ora": "^6.2.0",
|
|
36
36
|
"package-json": "^8.1.0",
|
|
37
37
|
"prettier": "^3.1.1",
|
|
38
|
-
"semver": "^7.
|
|
38
|
+
"semver": "^7.5.2",
|
|
39
39
|
"shelljs": "^0.8.5",
|
|
40
40
|
"ssh2-sftp-client": "^9.1.0",
|
|
41
41
|
"ws": "^8.11.0",
|
|
42
|
-
"@widget-js/core": "
|
|
43
|
-
"@widget-js/
|
|
44
|
-
"@widget-js/utils": "0.10.21"
|
|
42
|
+
"@widget-js/core": "24.1.1-beta.2",
|
|
43
|
+
"@widget-js/utils": "24.1.1-beta.2"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
46
|
"@types/ali-oss": "^6.16.7",
|
|
@@ -49,10 +48,13 @@
|
|
|
49
48
|
"@types/figlet": "^1.5.5",
|
|
50
49
|
"@types/inquirer": "latest",
|
|
51
50
|
"@types/jest": "^29.2.3",
|
|
51
|
+
"@types/minimist": "^1.2.5",
|
|
52
52
|
"@types/node": "^18.11.13",
|
|
53
53
|
"@types/semver": "^7.5.0",
|
|
54
54
|
"@types/shelljs": "latest",
|
|
55
55
|
"@types/ssh2-sftp-client": "^9.0.1",
|
|
56
|
+
"@widget-js/vite-plugin-widget": "^1.2.8",
|
|
57
|
+
"gradient-string": "^2.0.2",
|
|
56
58
|
"jest": "^29.5.0",
|
|
57
59
|
"pinst": "^3.0.0",
|
|
58
60
|
"rimraf": "^4.4.1",
|
|
@@ -65,8 +67,7 @@
|
|
|
65
67
|
"vue-router": "^4.2.5",
|
|
66
68
|
"webpack": "^5.75.0",
|
|
67
69
|
"webpack-cli": "^5.0.0",
|
|
68
|
-
"@widget-js/
|
|
69
|
-
"@widget-js/core": "0.11.21",
|
|
70
|
+
"@widget-js/core": "24.1.1-beta.2",
|
|
70
71
|
"@widget-js/vue3": "^0.11.20"
|
|
71
72
|
},
|
|
72
73
|
"scripts": {
|
|
@@ -78,6 +79,7 @@
|
|
|
78
79
|
"widget:init": "node ./lib/index.js init",
|
|
79
80
|
"widget:create": "npm run build && node ./lib/index.js create",
|
|
80
81
|
"widget:local": "npm run build && node ./lib/index.js dependencies -t local",
|
|
81
|
-
"
|
|
82
|
+
"build:publish": "npm run build && npm run pnpm:publish",
|
|
83
|
+
"pnpm:publish": "pnpm publish --no-git-checks"
|
|
82
84
|
}
|
|
83
85
|
}
|
package/src/build/build.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
+
import { exec } from 'node:child_process'
|
|
1
2
|
import ora from 'ora'
|
|
2
|
-
import {exec} from 'child_process'
|
|
3
3
|
import consola from 'consola'
|
|
4
4
|
|
|
5
5
|
export function build() {
|
|
6
6
|
const preloadSpinner = ora('Preload').start()
|
|
7
7
|
const mainSpinner = ora('Main').start()
|
|
8
|
-
|
|
8
|
+
// @ts-expect-error
|
|
9
9
|
const build = exec('npm run build:preload').on('close', () => {
|
|
10
10
|
consola.success('done')
|
|
11
11
|
})
|
|
12
|
-
|
|
13
|
-
build.stdout.on('data', data => {
|
|
12
|
+
// @ts-expect-error
|
|
13
|
+
build.stdout.on('data', (data) => {
|
|
14
14
|
consola.log('data', data)
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
// @ts-expect-error
|
|
18
18
|
exec('npm run build:main', (error, stdout, stderr) => {
|
|
19
19
|
if (error) {
|
|
20
|
-
consola.error(
|
|
20
|
+
consola.error(`error: ${error}`)
|
|
21
21
|
return
|
|
22
22
|
}
|
|
23
|
-
consola.log(
|
|
24
|
-
consola.log(
|
|
23
|
+
consola.log(`stdout: ${stdout}`)
|
|
24
|
+
consola.log(`stderr: ${typeof stderr}`)
|
|
25
25
|
})
|
|
26
26
|
.on('message', () => {
|
|
27
27
|
consola.log('on-message')
|
package/src/createWidget.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import fs from 'fs'
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
3
4
|
import consola from 'consola'
|
|
4
|
-
import
|
|
5
|
-
import {paramCase, snakeCase} from 'change-case'
|
|
5
|
+
import { paramCase, snakeCase } from 'change-case'
|
|
6
6
|
import inquirer from 'inquirer'
|
|
7
7
|
import shell from 'shelljs'
|
|
8
|
-
import exit from './utils.js'
|
|
9
8
|
import chalk from 'chalk'
|
|
10
|
-
import {scanWidgetPackage} from '@widget-js/utils'
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
9
|
+
import { scanWidgetPackage } from '@widget-js/utils'
|
|
10
|
+
import exit from './utils.js'
|
|
11
|
+
import promptChecker from './promts/promptChecker'
|
|
12
|
+
import { EJSUtils } from './utils/EJSUtils'
|
|
13
|
+
import { WidgetPackageUtils } from './utils/WidgetPackageUtils'
|
|
14
|
+
|
|
14
15
|
// import vm from "vm";
|
|
15
16
|
const __filename = fileURLToPath(import.meta.url)
|
|
16
17
|
const __dirname = path.dirname(__filename)
|
|
@@ -32,24 +33,27 @@ interface RenderOptions {
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export default async function createWidget() {
|
|
35
|
-
|
|
36
|
+
const widgetPackage = await scanWidgetPackage()
|
|
36
37
|
if (!widgetPackage) {
|
|
37
38
|
consola.error('widget.ts or widget.json not found')
|
|
38
39
|
return
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
+
const widgetRootDir = WidgetPackageUtils.getRootDir(widgetPackage)
|
|
41
42
|
if (widgetPackage.devOptions && widgetPackage.devOptions.folder) {
|
|
42
43
|
consola.info(`组件路径:${widgetRootDir}`)
|
|
43
|
-
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
44
46
|
consola.info(`没有配置devOptions.folder,使用默认路径${widgetRootDir}`)
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
const getMiddleValue = (arr: number[]) => {
|
|
48
50
|
if (arr.length === 1) {
|
|
49
51
|
return arr[0]
|
|
50
|
-
}
|
|
52
|
+
}
|
|
53
|
+
else if (arr.length === 2) {
|
|
51
54
|
return Math.max(...arr)
|
|
52
|
-
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
53
57
|
const max = Math.max(...arr)
|
|
54
58
|
const min = Math.min(...arr)
|
|
55
59
|
const sum = arr[0] + arr[1] + arr[2]
|
|
@@ -57,13 +61,13 @@ export default async function createWidget() {
|
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
|
|
60
|
-
|
|
64
|
+
const name = await promptChecker(
|
|
61
65
|
{
|
|
62
66
|
type: 'input',
|
|
63
67
|
name: 'name',
|
|
64
68
|
message: chalk.blue('请输入组件名(大驼峰式),如:CountdownClock'),
|
|
65
69
|
},
|
|
66
|
-
answer => {
|
|
70
|
+
(answer) => {
|
|
67
71
|
const name = answer.name
|
|
68
72
|
if (name == null || name === '') {
|
|
69
73
|
consola.log(chalk.red('组件名不能为空'))
|
|
@@ -75,13 +79,13 @@ export default async function createWidget() {
|
|
|
75
79
|
|
|
76
80
|
consola.log(chalk.green(name))
|
|
77
81
|
|
|
78
|
-
|
|
82
|
+
const title = await promptChecker({
|
|
79
83
|
type: 'input',
|
|
80
84
|
name: 'title',
|
|
81
85
|
message: chalk.blue('请输入组件标题,如:倒计时'),
|
|
82
86
|
})
|
|
83
87
|
consola.log(chalk.green(title))
|
|
84
|
-
|
|
88
|
+
const answerW = await promptChecker(
|
|
85
89
|
{
|
|
86
90
|
type: 'checkbox',
|
|
87
91
|
name: 'w',
|
|
@@ -90,7 +94,7 @@ export default async function createWidget() {
|
|
|
90
94
|
),
|
|
91
95
|
choices: [1, 2, 3, 4, 5, 6],
|
|
92
96
|
},
|
|
93
|
-
answer => {
|
|
97
|
+
(answer) => {
|
|
94
98
|
if (answer.w.length === 0) {
|
|
95
99
|
consola.log(chalk.red('宽度必须选择'))
|
|
96
100
|
return false
|
|
@@ -105,7 +109,7 @@ export default async function createWidget() {
|
|
|
105
109
|
)
|
|
106
110
|
consola.log(chalk.green(answerW))
|
|
107
111
|
|
|
108
|
-
|
|
112
|
+
const answerH = await promptChecker(
|
|
109
113
|
{
|
|
110
114
|
type: 'checkbox',
|
|
111
115
|
name: 'h',
|
|
@@ -114,7 +118,7 @@ export default async function createWidget() {
|
|
|
114
118
|
),
|
|
115
119
|
choices: [1, 2, 3, 4, 5, 6],
|
|
116
120
|
},
|
|
117
|
-
answer => {
|
|
121
|
+
(answer) => {
|
|
118
122
|
if (answer.h.length === 0) {
|
|
119
123
|
consola.log(chalk.red('高度必须选择'))
|
|
120
124
|
return false
|
|
@@ -130,7 +134,7 @@ export default async function createWidget() {
|
|
|
130
134
|
|
|
131
135
|
consola.log(chalk.green(answerH))
|
|
132
136
|
|
|
133
|
-
|
|
137
|
+
const configurable = await promptChecker({
|
|
134
138
|
type: 'confirm',
|
|
135
139
|
name: 'configurable',
|
|
136
140
|
message: chalk.blue('组件是否可配置,例如修改背景颜色,字体大小等'),
|
|
@@ -147,13 +151,14 @@ export default async function createWidget() {
|
|
|
147
151
|
const snakeCaseName = snakeCase(name)
|
|
148
152
|
const paramCaseName = paramCase(name)
|
|
149
153
|
|
|
150
|
-
const widgetName = widgetPackage.name
|
|
154
|
+
const widgetName = `${widgetPackage.name}.${snakeCaseName}`
|
|
151
155
|
|
|
152
156
|
const widgetDir = path.join(widgetRootDir, paramCaseName)
|
|
153
157
|
if (!fs.existsSync(widgetDir)) {
|
|
154
158
|
fs.mkdirSync(widgetDir)
|
|
155
|
-
}
|
|
156
|
-
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
const answer = await inquirer.prompt([
|
|
157
162
|
{
|
|
158
163
|
type: 'confirm',
|
|
159
164
|
name: 'override',
|
|
@@ -166,19 +171,19 @@ export default async function createWidget() {
|
|
|
166
171
|
}
|
|
167
172
|
|
|
168
173
|
const renderOptions: RenderOptions = {
|
|
169
|
-
name
|
|
170
|
-
snakeCaseName
|
|
171
|
-
paramCaseName
|
|
174
|
+
name,
|
|
175
|
+
snakeCaseName,
|
|
176
|
+
paramCaseName,
|
|
172
177
|
packageName: widgetPackage.name,
|
|
173
|
-
widgetName
|
|
174
|
-
title
|
|
175
|
-
configurable
|
|
176
|
-
width
|
|
177
|
-
height
|
|
178
|
-
maxWidth
|
|
179
|
-
minHeight
|
|
180
|
-
maxHeight
|
|
181
|
-
minWidth
|
|
178
|
+
widgetName,
|
|
179
|
+
title,
|
|
180
|
+
configurable,
|
|
181
|
+
width,
|
|
182
|
+
height,
|
|
183
|
+
maxWidth,
|
|
184
|
+
minHeight,
|
|
185
|
+
maxHeight,
|
|
186
|
+
minWidth,
|
|
182
187
|
}
|
|
183
188
|
|
|
184
189
|
const widgetDefineFile = path.resolve(widgetDir, `${name}.widget.ts`)
|
|
@@ -199,7 +204,8 @@ export default async function createWidget() {
|
|
|
199
204
|
let routeContent
|
|
200
205
|
if (fs.existsSync(routeFile)) {
|
|
201
206
|
routeContent = fs.readFileSync(routeFile, 'utf8')
|
|
202
|
-
}
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
203
209
|
routeContent = fs.readFileSync(path.join(__dirname, '../template/widget-router.ts'), 'utf8')
|
|
204
210
|
}
|
|
205
211
|
const importRouteStr = `import ${name}WidgetRoutes from "./${paramCaseName}/${name}WidgetRoutes";`
|
|
@@ -216,8 +222,8 @@ export default async function createWidget() {
|
|
|
216
222
|
|
|
217
223
|
fs.writeFileSync(routeFile, routeContent)
|
|
218
224
|
|
|
219
|
-
|
|
220
|
-
|
|
225
|
+
// 添加到版本控制
|
|
226
|
+
const gitAdd = `git add ${widgetDir}`
|
|
221
227
|
consola.info(chalk.grey(gitAdd))
|
|
222
228
|
shell.exec(gitAdd)
|
|
223
229
|
consola.log('=================')
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {RemoteDependencies} from
|
|
2
|
-
import {LocalDependencies} from
|
|
1
|
+
import { RemoteDependencies } from './remoteDependencies'
|
|
2
|
+
import { LocalDependencies } from './localDependencies'
|
|
3
3
|
|
|
4
|
-
export type DependenciesOptions = 'remote' | 'local'
|
|
4
|
+
export type DependenciesOptions = 'remote' | 'local'
|
|
5
5
|
export default async function (options: any) {
|
|
6
|
-
|
|
6
|
+
const type = options.type as DependenciesOptions
|
|
7
7
|
if (type == 'remote') {
|
|
8
8
|
await RemoteDependencies.start()
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
10
11
|
await LocalDependencies.start()
|
|
11
12
|
}
|
|
12
13
|
}
|
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import ora from 'ora'
|
|
3
|
+
import { Utils, getPackagePath, widgetPackages } from '../utils'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const spinner = ora("Connecting");
|
|
5
|
+
const spinner = ora('Connecting')
|
|
7
6
|
|
|
8
7
|
export namespace LocalDependencies {
|
|
9
8
|
export async function start() {
|
|
10
|
-
spinner.start()
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
await setWorkspaceVersion(dependencies, packageNames)
|
|
16
|
-
await setWorkspaceVersion(devDependencies, packageNames)
|
|
17
|
-
fs.writeFileSync(getPackagePath(), JSON.stringify(json, null, 2))
|
|
18
|
-
spinner.succeed(
|
|
9
|
+
spinner.start()
|
|
10
|
+
const json = Utils.getPackageJson()
|
|
11
|
+
const packageNames = Object.keys(widgetPackages)
|
|
12
|
+
const dependencies = json.dependencies
|
|
13
|
+
const devDependencies = json.devDependencies
|
|
14
|
+
await setWorkspaceVersion(dependencies, packageNames)
|
|
15
|
+
await setWorkspaceVersion(devDependencies, packageNames)
|
|
16
|
+
fs.writeFileSync(getPackagePath(), JSON.stringify(json, null, 2))
|
|
17
|
+
spinner.succeed('Using local versions(workspace:*)!')
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
async function setWorkspaceVersion(dependencies: { [key: string]: string }, packageNames: string[]) {
|
|
22
|
-
|
|
23
|
-
for (
|
|
24
|
-
if (packageNames.
|
|
25
|
-
dependencies[localPackage] = `workspace
|
|
21
|
+
const localPackages = Object.keys(dependencies)
|
|
22
|
+
for (const localPackage of localPackages) {
|
|
23
|
+
if (packageNames.includes(localPackage)) {
|
|
24
|
+
dependencies[localPackage] = `workspace:*`
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
}
|
|
@@ -1,40 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import ora from
|
|
3
|
-
import {
|
|
4
|
-
import fs from "fs";
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import ora from 'ora'
|
|
3
|
+
import { Utils, getPackagePath, widgetPackages } from '../utils'
|
|
5
4
|
|
|
6
|
-
const spinner = ora(
|
|
5
|
+
const spinner = ora('Connecting')
|
|
7
6
|
|
|
8
7
|
export namespace RemoteDependencies {
|
|
9
8
|
|
|
10
9
|
export async function start() {
|
|
11
|
-
spinner.start()
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
await upgradePackage(dependencies, packageNames)
|
|
17
|
-
await upgradePackage(devDependencies, packageNames)
|
|
18
|
-
fs.writeFileSync(getPackagePath(), JSON.stringify(json, null, 2))
|
|
19
|
-
spinner.succeed(
|
|
10
|
+
spinner.start()
|
|
11
|
+
const json = Utils.getPackageJson()
|
|
12
|
+
const packageNames = Object.keys(widgetPackages)
|
|
13
|
+
const dependencies = json.dependencies
|
|
14
|
+
const devDependencies = json.devDependencies
|
|
15
|
+
await upgradePackage(dependencies, packageNames)
|
|
16
|
+
await upgradePackage(devDependencies, packageNames)
|
|
17
|
+
fs.writeFileSync(getPackagePath(), JSON.stringify(json, null, 2))
|
|
18
|
+
spinner.succeed('Using remote versions!')
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
|
|
23
21
|
async function upgradePackage(dependencies: { [key: string]: string }, packageNames: string[]) {
|
|
24
|
-
|
|
25
|
-
for (
|
|
26
|
-
if (packageNames.
|
|
27
|
-
let packageVersion = widgetPackages[localPackage]
|
|
22
|
+
const localPackages = Object.keys(dependencies)
|
|
23
|
+
for (const localPackage of localPackages) {
|
|
24
|
+
if (packageNames.includes(localPackage)) {
|
|
25
|
+
let packageVersion = widgetPackages[localPackage]
|
|
28
26
|
if (!packageVersion) {
|
|
29
|
-
spinner.info(`Fetching package version:${localPackage}`)
|
|
30
|
-
packageVersion = await Utils.getRemoteVersion(localPackage)
|
|
31
|
-
widgetPackages[localPackage] = packageVersion
|
|
32
|
-
spinner.info(`version:${packageVersion}`)
|
|
27
|
+
spinner.info(`Fetching package version:${localPackage}`)
|
|
28
|
+
packageVersion = await Utils.getRemoteVersion(localPackage)
|
|
29
|
+
widgetPackages[localPackage] = packageVersion
|
|
30
|
+
spinner.info(`version:${packageVersion}`)
|
|
33
31
|
}
|
|
34
|
-
dependencies[localPackage] = `^${packageVersion}
|
|
32
|
+
dependencies[localPackage] = `^${packageVersion}`
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
|
|
40
37
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import * as process from 'node:process'
|
|
4
|
+
import { Option, program } from 'commander'
|
|
5
5
|
|
|
6
|
-
import figlet from
|
|
7
|
-
import gradient from
|
|
8
|
-
import {dirname} from
|
|
6
|
+
import figlet from 'figlet'
|
|
7
|
+
import gradient from 'gradient-string'
|
|
8
|
+
import { dirname } from 'dirname-filename-esm'
|
|
9
9
|
|
|
10
10
|
//
|
|
11
|
-
const packageJsonPath = path.join(dirname(import.meta),
|
|
12
|
-
|
|
11
|
+
const packageJsonPath = path.join(dirname(import.meta), '../package.json')
|
|
12
|
+
const cliPackage = JSON.parse(fs.readFileSync(packageJsonPath).toString())
|
|
13
13
|
|
|
14
|
-
console.log(gradient.pastel.multiline(figlet.textSync(
|
|
15
|
-
program.version(`@widget-js/cli ${cliPackage.version}`).usage(
|
|
14
|
+
console.log(gradient.pastel.multiline(figlet.textSync('widget-cli', { horizontalLayout: 'full' })))
|
|
15
|
+
program.version(`@widget-js/cli ${cliPackage.version}`).usage('<command> [options]')
|
|
16
16
|
program
|
|
17
|
-
.command(
|
|
18
|
-
.description(
|
|
17
|
+
.command('create')
|
|
18
|
+
.description('Create new widget')
|
|
19
19
|
.action(async () => {
|
|
20
|
-
const createWidget = await import(
|
|
21
|
-
await createWidget.default()
|
|
22
|
-
})
|
|
20
|
+
const createWidget = await import('./createWidget')
|
|
21
|
+
await createWidget.default()
|
|
22
|
+
})
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
const dependenciesOption = new Option('-t, --type <type>').choices(['remote', 'local'])
|
|
25
25
|
|
|
26
26
|
program
|
|
27
|
-
.command(
|
|
28
|
-
.description(
|
|
27
|
+
.command('dependencies')
|
|
28
|
+
.description('Set @widget-js dependencies to local(workspace:*) or remote(^1.0.0 etc)')
|
|
29
29
|
.addOption(dependenciesOption)
|
|
30
30
|
.action(async (options) => {
|
|
31
|
-
|
|
32
|
-
await dependencies.default(options)
|
|
33
|
-
})
|
|
31
|
+
const dependencies = await import('./dependencies/index')
|
|
32
|
+
await dependencies.default(options)
|
|
33
|
+
})
|
|
34
34
|
|
|
35
35
|
program
|
|
36
|
-
.command(
|
|
37
|
-
.description(
|
|
36
|
+
.command('init')
|
|
37
|
+
.description('Initialize widget-js project')
|
|
38
38
|
.action(async () => {
|
|
39
|
-
const init = await import(
|
|
40
|
-
await init.init()
|
|
41
|
-
})
|
|
39
|
+
const init = await import('./init/init')
|
|
40
|
+
await init.init()
|
|
41
|
+
})
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const typeOption = new Option('-t, --type <type>').choices(['ftp', 'oss'])
|
|
44
|
+
const fileOption = new Option('-f, --file <file>')
|
|
45
45
|
program
|
|
46
|
-
.command(
|
|
47
|
-
.description(
|
|
46
|
+
.command('release')
|
|
47
|
+
.description('通过FTP/OSS发布文件,仅内部使用')
|
|
48
48
|
.addOption(typeOption)
|
|
49
49
|
.addOption(fileOption)
|
|
50
50
|
.action(async (options, command) => {
|
|
51
|
-
// @ts-
|
|
52
|
-
|
|
53
|
-
await release.default(options)
|
|
54
|
-
})
|
|
51
|
+
// @ts-expect-error
|
|
52
|
+
const release = await import('./release/release')
|
|
53
|
+
await release.default(options)
|
|
54
|
+
})
|
|
55
55
|
|
|
56
|
-
program.parse(process.argv)
|
|
56
|
+
program.parse(process.argv)
|
package/src/init/init.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import process from 'node:process'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
5
|
import consola from 'consola'
|
|
6
|
-
import promptChecker from '../promts/promptChecker'
|
|
7
6
|
import chalk from 'chalk'
|
|
8
|
-
import {EJSUtils} from '../utils/EJSUtils'
|
|
9
7
|
import ora from 'ora'
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
8
|
+
import { scanWidgetPackage } from '@widget-js/utils'
|
|
9
|
+
import { Utils } from '../utils'
|
|
10
|
+
import promptChecker from '../promts/promptChecker'
|
|
11
|
+
import { EJSUtils } from '../utils/EJSUtils'
|
|
12
|
+
import { PrettierUtils } from '../utils/PrettierUtils'
|
|
13
|
+
import { WidgetPackageUtils } from '../utils/WidgetPackageUtils'
|
|
14
|
+
|
|
14
15
|
const __filename = fileURLToPath(import.meta.url)
|
|
15
16
|
const __dirname = path.dirname(__filename)
|
|
16
17
|
const spinner = ora('Loading')
|
|
@@ -21,13 +22,13 @@ export async function init() {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
async function addWidgetTs() {
|
|
24
|
-
|
|
25
|
+
const name = await promptChecker(
|
|
25
26
|
{
|
|
26
27
|
type: 'input',
|
|
27
28
|
name: 'name',
|
|
28
29
|
message: chalk.blue('组件包 包名 (示例 cn.widget.countdown):'),
|
|
29
30
|
},
|
|
30
|
-
answer => {
|
|
31
|
+
(answer) => {
|
|
31
32
|
const name = answer.name
|
|
32
33
|
if (name == null || name === '') {
|
|
33
34
|
consola.log(chalk.red(`包名不能为空`))
|
|
@@ -37,12 +38,13 @@ async function addWidgetTs() {
|
|
|
37
38
|
},
|
|
38
39
|
)
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
const widgetPackageTs = path.join(process.cwd(), 'widget.package.ts')
|
|
41
42
|
if (fs.existsSync(widgetPackageTs)) {
|
|
42
43
|
spinner.info('widget.package.ts已存在,跳过')
|
|
43
|
-
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
44
46
|
spinner.info('创建 widget.package.ts')
|
|
45
|
-
await EJSUtils.renderToFile('WidgetPackage.ejs', widgetPackageTs, 'typescript', {name})
|
|
47
|
+
await EJSUtils.renderToFile('WidgetPackage.ejs', widgetPackageTs, 'typescript', { name })
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
await addVitePlugin()
|
|
@@ -56,21 +58,21 @@ async function addWidgetTs() {
|
|
|
56
58
|
*/
|
|
57
59
|
async function addDependencies() {
|
|
58
60
|
const packageJson = Utils.getPackageJson()
|
|
59
|
-
let dependencies = packageJson
|
|
60
|
-
|
|
61
|
+
let dependencies = packageJson.dependencies
|
|
62
|
+
const devDependencies = packageJson.devDependencies
|
|
61
63
|
if (!dependencies) {
|
|
62
64
|
dependencies = {}
|
|
63
65
|
}
|
|
64
66
|
if (!devDependencies) {
|
|
65
|
-
packageJson
|
|
67
|
+
packageJson.devDependencies = {}
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
await addDependency('@widget-js/core', dependencies)
|
|
69
71
|
await addDependency('@widget-js/vue3', dependencies)
|
|
70
72
|
await addDependency('@widget-js/vite-plugin-widget', devDependencies)
|
|
71
73
|
|
|
72
|
-
packageJson
|
|
73
|
-
packageJson
|
|
74
|
+
packageJson.dependencies = dependencies
|
|
75
|
+
packageJson.devDependencies = devDependencies
|
|
74
76
|
|
|
75
77
|
fs.writeFileSync(Utils.getPackagePath(), JSON.stringify(packageJson, null, 2))
|
|
76
78
|
}
|
|
@@ -83,7 +85,7 @@ async function addVitePlugin() {
|
|
|
83
85
|
return
|
|
84
86
|
}
|
|
85
87
|
let viteConfig = fs.readFileSync(viteConfigPath).toString()
|
|
86
|
-
viteConfig = `import widget from '@widget-js/vite-plugin-widget'\n`
|
|
88
|
+
viteConfig = `import widget from '@widget-js/vite-plugin-widget'\n${viteConfig}`
|
|
87
89
|
viteConfig = viteConfig.replace('vue()', `vue(),widget()`)
|
|
88
90
|
fs.writeFileSync(viteConfigPath, await PrettierUtils.format(viteConfig, 'typescript'))
|
|
89
91
|
}
|