@widget-js/cli 24.1.1-beta.16 → 24.1.1-beta.17
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/package.json +16 -12
- package/template/WidgetView.ejs +1 -2
- package/.idea/cli.iml +0 -9
- package/.idea/codeStyles/Project.xml +0 -60
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.prettierrc +0 -21
- package/jest.config.js +0 -14
- package/release.json +0 -9
- package/src/build/build.ts +0 -35
- package/src/createWidget.ts +0 -232
- package/src/dependencies/index.ts +0 -13
- package/src/dependencies/localDependencies.ts +0 -29
- package/src/dependencies/remoteDependencies.ts +0 -37
- package/src/index.ts +0 -65
- package/src/init/init.ts +0 -121
- package/src/promts/promptChecker.ts +0 -17
- package/src/publish/index.ts +0 -60
- package/src/release/ftp.ts +0 -144
- package/src/release/oss.ts +0 -50
- package/src/release/release.ts +0 -70
- package/src/release/update-zip.ts +0 -23
- package/src/utils/EJSUtils.ts +0 -18
- package/src/utils/PrettierUtils.ts +0 -12
- package/src/utils/WidgetPackageUtils.ts +0 -13
- package/src/utils.ts +0 -84
- package/test/index.test.ts +0 -9
- package/tsconfig.json +0 -78
- package/tsup.config.ts +0 -6
- package/vite.config.ts +0 -15
- package/widget.json +0 -14
- /package/{lib → dist}/chunk-I4ZBPB2S.js +0 -0
- /package/{lib → dist}/chunk-RDJH7Z4C.js +0 -0
- /package/{lib → dist}/chunk-XPJ33Y5L.js +0 -0
- /package/{lib → dist}/createWidget-EBGZI7JV.js +0 -0
- /package/{lib → dist}/dependencies-AVNHKRF3.js +0 -0
- /package/{lib → dist}/index.js +0 -0
- /package/{lib → dist}/init-HCEGKTNF.js +0 -0
- /package/{lib → dist}/publish-C52GHJWG.js +0 -0
- /package/{lib → dist}/release-5GS34BAJ.js +0 -0
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widget-js/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "24.1.1-beta.
|
|
4
|
+
"version": "24.1.1-beta.17",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Neo Fu",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"main": "
|
|
8
|
+
"main": "dist/index.js",
|
|
9
9
|
"bin": {
|
|
10
|
-
"widget": "
|
|
10
|
+
"widget": "dist/index.js"
|
|
11
11
|
},
|
|
12
12
|
"engines": {
|
|
13
13
|
"node": "^12.0.0 || >= 14.0.0"
|
|
14
14
|
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"template"
|
|
18
|
+
],
|
|
15
19
|
"publishConfig": {
|
|
16
20
|
"access": "public"
|
|
17
21
|
},
|
|
@@ -75,20 +79,20 @@
|
|
|
75
79
|
"webpack-cli": "^5.0.0"
|
|
76
80
|
},
|
|
77
81
|
"scripts": {
|
|
78
|
-
"build": "rimraf ./
|
|
79
|
-
"watch": "tsup-node src/index.ts --
|
|
82
|
+
"build": "rimraf ./dist/ && tsup-node src/index.ts",
|
|
83
|
+
"watch": "tsup-node src/index.ts --watch",
|
|
80
84
|
"build:run": "npm run build && npm run widget",
|
|
81
|
-
"widget": "node ./
|
|
82
|
-
"widget:ftp": "node ./
|
|
83
|
-
"widget:init": "node ./
|
|
84
|
-
"widget:publish": "node ./
|
|
85
|
-
"widget:create": "npm run build && node ./
|
|
86
|
-
"widget:local": "npm run build && node ./
|
|
85
|
+
"widget": "node ./dist/index.js",
|
|
86
|
+
"widget:ftp": "node ./dist/index.js release -t ftp",
|
|
87
|
+
"widget:init": "node ./dist/index.js init",
|
|
88
|
+
"widget:publish": "node ./dist/index.js publish -key 123",
|
|
89
|
+
"widget:create": "npm run build && node ./dist/index.js create",
|
|
90
|
+
"widget:local": "npm run build && node ./dist/index.js dependencies -t local",
|
|
87
91
|
"build:publish": "npm run build && npm run pnpm:publish",
|
|
88
92
|
"pnpm:publish": "pnpm publish --no-git-checks",
|
|
89
93
|
"remote": "widget dependencies -t remote && pnpm install",
|
|
90
94
|
"local": "widget dependencies -t local && pnpm install",
|
|
91
|
-
"link": "pnpm link
|
|
95
|
+
"link": "pnpm link --global",
|
|
92
96
|
"lint": "eslint .",
|
|
93
97
|
"lint:fix": "eslint . --fix"
|
|
94
98
|
}
|
package/template/WidgetView.ejs
CHANGED
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script lang="ts" setup>
|
|
8
|
-
import {WidgetData} from "@widget-js/core";
|
|
9
8
|
import {useWidget} from "@widget-js/vue3";
|
|
10
9
|
|
|
11
|
-
const {
|
|
10
|
+
const {widgetParams} = useWidget();
|
|
12
11
|
</script>
|
|
13
12
|
|
|
14
13
|
<style scoped>
|
package/.idea/cli.iml
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="JAVA_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
-
<exclude-output />
|
|
5
|
-
<content url="file://$MODULE_DIR$" />
|
|
6
|
-
<orderEntry type="inheritedJdk" />
|
|
7
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
-
</component>
|
|
9
|
-
</module>
|
|
@@ -1,60 +0,0 @@
|
|
|
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
DELETED
package/.idea/modules.xml
DELETED
package/.idea/vcs.xml
DELETED
package/.prettierrc
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"printWidth": 120,
|
|
3
|
-
"semi": false,
|
|
4
|
-
"singleQuote": true,
|
|
5
|
-
"overrides": [
|
|
6
|
-
{
|
|
7
|
-
"files": ["**/*.css", "**/*.scss", "**/*.html"],
|
|
8
|
-
"options": {
|
|
9
|
-
"singleQuote": false
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
],
|
|
13
|
-
"trailingComma": "all",
|
|
14
|
-
"bracketSpacing": false,
|
|
15
|
-
"arrowParens": "avoid",
|
|
16
|
-
"proseWrap": "never",
|
|
17
|
-
"htmlWhitespaceSensitivity": "strict",
|
|
18
|
-
"vueIndentScriptAndStyle": false,
|
|
19
|
-
"endOfLine": "lf",
|
|
20
|
-
"singleAttributePerLine": true
|
|
21
|
-
}
|
package/jest.config.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
roots: ['<rootDir>/test'],
|
|
3
|
-
testMatch: [
|
|
4
|
-
'**/__tests__/**/*.+(ts|tsx|js)',
|
|
5
|
-
'**/?(*.)+(spec|test).+(ts|tsx|js)',
|
|
6
|
-
],
|
|
7
|
-
transform: {
|
|
8
|
-
'^.+\\.(ts|tsx)$': ['ts-jest', {
|
|
9
|
-
tsconfig: 'tsconfig.json',
|
|
10
|
-
}],
|
|
11
|
-
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
|
|
12
|
-
'./config/fileTransformer.js',
|
|
13
|
-
},
|
|
14
|
-
}
|
package/release.json
DELETED
package/src/build/build.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { exec } from 'node:child_process'
|
|
2
|
-
import ora from 'ora'
|
|
3
|
-
import consola from 'consola'
|
|
4
|
-
|
|
5
|
-
export function build() {
|
|
6
|
-
const preloadSpinner = ora('Preload').start()
|
|
7
|
-
const mainSpinner = ora('Main').start()
|
|
8
|
-
// @ts-expect-error
|
|
9
|
-
const build = exec('npm run build:preload').on('close', () => {
|
|
10
|
-
consola.success('done')
|
|
11
|
-
})
|
|
12
|
-
// @ts-expect-error
|
|
13
|
-
build.stdout.on('data', (data) => {
|
|
14
|
-
consola.log('data', data)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
// @ts-expect-error
|
|
18
|
-
exec('npm run build:main', (error, stdout, stderr) => {
|
|
19
|
-
if (error) {
|
|
20
|
-
consola.error(`error: ${error}`)
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
consola.log(`stdout: ${stdout}`)
|
|
24
|
-
consola.log(`stderr: ${typeof stderr}`)
|
|
25
|
-
})
|
|
26
|
-
.on('message', () => {
|
|
27
|
-
consola.log('on-message')
|
|
28
|
-
})
|
|
29
|
-
.on('data', () => {
|
|
30
|
-
consola.log('on-data')
|
|
31
|
-
})
|
|
32
|
-
.on('close', () => {
|
|
33
|
-
consola.log('done')
|
|
34
|
-
})
|
|
35
|
-
}
|
package/src/createWidget.ts
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import fs from 'node:fs'
|
|
3
|
-
import { fileURLToPath } from 'node:url'
|
|
4
|
-
import consola from 'consola'
|
|
5
|
-
import { paramCase, snakeCase } from 'change-case'
|
|
6
|
-
import inquirer from 'inquirer'
|
|
7
|
-
import shell from 'shelljs'
|
|
8
|
-
import chalk from 'chalk'
|
|
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
|
-
|
|
15
|
-
// import vm from "vm";
|
|
16
|
-
const __filename = fileURLToPath(import.meta.url)
|
|
17
|
-
const __dirname = path.dirname(__filename)
|
|
18
|
-
|
|
19
|
-
interface RenderOptions {
|
|
20
|
-
name: string
|
|
21
|
-
snakeCaseName: string
|
|
22
|
-
paramCaseName: string
|
|
23
|
-
packageName: string
|
|
24
|
-
widgetName: string
|
|
25
|
-
title: string
|
|
26
|
-
configurable: string
|
|
27
|
-
width: number
|
|
28
|
-
height: number
|
|
29
|
-
maxWidth: number
|
|
30
|
-
minHeight: number
|
|
31
|
-
maxHeight: number
|
|
32
|
-
minWidth: number
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export default async function createWidget() {
|
|
36
|
-
const widgetPackage = await scanWidgetPackage()
|
|
37
|
-
if (!widgetPackage) {
|
|
38
|
-
consola.error('widget.ts or widget.json not found')
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
const widgetRootDir = WidgetPackageUtils.getRootDir(widgetPackage)
|
|
42
|
-
if (widgetPackage.devOptions && widgetPackage.devOptions.folder) {
|
|
43
|
-
consola.info(`组件路径:${widgetRootDir}`)
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
consola.info(`没有配置devOptions.folder,使用默认路径${widgetRootDir}`)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const getMiddleValue = (arr: number[]) => {
|
|
50
|
-
if (arr.length === 1) {
|
|
51
|
-
return arr[0]
|
|
52
|
-
}
|
|
53
|
-
else if (arr.length === 2) {
|
|
54
|
-
return Math.max(...arr)
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
const max = Math.max(...arr)
|
|
58
|
-
const min = Math.min(...arr)
|
|
59
|
-
const sum = arr[0] + arr[1] + arr[2]
|
|
60
|
-
return sum - max - min
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const name = await promptChecker(
|
|
65
|
-
{
|
|
66
|
-
type: 'input',
|
|
67
|
-
name: 'name',
|
|
68
|
-
message: chalk.blue('请输入组件名(大驼峰式),如:CountdownClock'),
|
|
69
|
-
},
|
|
70
|
-
(answer) => {
|
|
71
|
-
const name = answer.name
|
|
72
|
-
if (name == null || name === '') {
|
|
73
|
-
consola.log(chalk.red('组件名不能为空'))
|
|
74
|
-
return false
|
|
75
|
-
}
|
|
76
|
-
return true
|
|
77
|
-
},
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
consola.log(chalk.green(name))
|
|
81
|
-
|
|
82
|
-
const title = await promptChecker({
|
|
83
|
-
type: 'input',
|
|
84
|
-
name: 'title',
|
|
85
|
-
message: chalk.blue('请输入组件标题,如:倒计时'),
|
|
86
|
-
})
|
|
87
|
-
consola.log(chalk.green(title))
|
|
88
|
-
const answerW = await promptChecker(
|
|
89
|
-
{
|
|
90
|
-
type: 'checkbox',
|
|
91
|
-
name: 'w',
|
|
92
|
-
message: chalk.blue(
|
|
93
|
-
'请选择组件宽度,最多选3个,例如选中2,4,6,代表组件最小宽为2,默认宽为4,最大宽为6,单选代表不可拉伸',
|
|
94
|
-
),
|
|
95
|
-
choices: [1, 2, 3, 4, 5, 6],
|
|
96
|
-
},
|
|
97
|
-
(answer) => {
|
|
98
|
-
if (answer.w.length === 0) {
|
|
99
|
-
consola.log(chalk.red('宽度必须选择'))
|
|
100
|
-
return false
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (answer.w.length > 3) {
|
|
104
|
-
consola.log(chalk.red('宽度最多选择3个'))
|
|
105
|
-
return false
|
|
106
|
-
}
|
|
107
|
-
return true
|
|
108
|
-
},
|
|
109
|
-
)
|
|
110
|
-
consola.log(chalk.green(answerW))
|
|
111
|
-
|
|
112
|
-
const answerH = await promptChecker(
|
|
113
|
-
{
|
|
114
|
-
type: 'checkbox',
|
|
115
|
-
name: 'h',
|
|
116
|
-
message: chalk.blue(
|
|
117
|
-
'请选择组件高度,最多选3个,例如选中1,2,代表组件最小高为1,默认高为2,最大高为2,单选代表不可拉伸',
|
|
118
|
-
),
|
|
119
|
-
choices: [1, 2, 3, 4, 5, 6],
|
|
120
|
-
},
|
|
121
|
-
(answer) => {
|
|
122
|
-
if (answer.h.length === 0) {
|
|
123
|
-
consola.log(chalk.red('高度必须选择'))
|
|
124
|
-
return false
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (answer.h.length > 3) {
|
|
128
|
-
consola.log(chalk.red('高度最多选择3个'))
|
|
129
|
-
return false
|
|
130
|
-
}
|
|
131
|
-
return true
|
|
132
|
-
},
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
consola.log(chalk.green(answerH))
|
|
136
|
-
|
|
137
|
-
const configurable = await promptChecker({
|
|
138
|
-
type: 'confirm',
|
|
139
|
-
name: 'configurable',
|
|
140
|
-
message: chalk.blue('组件是否可配置,例如修改背景颜色,字体大小等'),
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
consola.log(chalk.green(configurable))
|
|
144
|
-
|
|
145
|
-
const width = getMiddleValue(answerW)
|
|
146
|
-
const height = getMiddleValue(answerH)
|
|
147
|
-
const minWidth = Math.min(...answerW)
|
|
148
|
-
const maxWidth = Math.max(...answerW)
|
|
149
|
-
const minHeight = Math.min(...answerH)
|
|
150
|
-
const maxHeight = Math.max(...answerH)
|
|
151
|
-
const snakeCaseName = snakeCase(name)
|
|
152
|
-
const paramCaseName = paramCase(name)
|
|
153
|
-
|
|
154
|
-
const widgetName = `${widgetPackage.name}.${snakeCaseName}`
|
|
155
|
-
|
|
156
|
-
const widgetDir = path.join(widgetRootDir, paramCaseName)
|
|
157
|
-
if (!fs.existsSync(widgetDir)) {
|
|
158
|
-
fs.mkdirSync(widgetDir)
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
const answer = await inquirer.prompt([
|
|
162
|
-
{
|
|
163
|
-
type: 'confirm',
|
|
164
|
-
name: 'override',
|
|
165
|
-
message: chalk.red('组件名已存在,是否继续?'),
|
|
166
|
-
},
|
|
167
|
-
])
|
|
168
|
-
if (!answer.override) {
|
|
169
|
-
exit()
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const renderOptions: RenderOptions = {
|
|
174
|
-
name,
|
|
175
|
-
snakeCaseName,
|
|
176
|
-
paramCaseName,
|
|
177
|
-
packageName: widgetPackage.name,
|
|
178
|
-
widgetName,
|
|
179
|
-
title,
|
|
180
|
-
configurable,
|
|
181
|
-
width,
|
|
182
|
-
height,
|
|
183
|
-
maxWidth,
|
|
184
|
-
minHeight,
|
|
185
|
-
maxHeight,
|
|
186
|
-
minWidth,
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const widgetDefineFile = path.resolve(widgetDir, `${name}.widget.ts`)
|
|
190
|
-
const widgetFile = path.resolve(widgetDir, `${name}Widget.vue`)
|
|
191
|
-
const widgetViewFile = path.resolve(widgetDir, `${name}WidgetView.vue`)
|
|
192
|
-
const widgetRoutesFile = path.resolve(widgetDir, `${name}WidgetRoutes.ts`)
|
|
193
|
-
|
|
194
|
-
await EJSUtils.renderToFile('WidgetDefine.ejs', widgetDefineFile, 'typescript', renderOptions)
|
|
195
|
-
// EJSUtils.renderToFile('Widget.ejs', widgetFile, 'vue', renderOptions)
|
|
196
|
-
await EJSUtils.renderToFile('WidgetView.ejs', widgetViewFile, 'vue', renderOptions)
|
|
197
|
-
await EJSUtils.renderToFile('WidgetRoutes.ejs', widgetRoutesFile, 'typescript', renderOptions)
|
|
198
|
-
if (configurable) {
|
|
199
|
-
const configFile = path.resolve(widgetDir, `${name}ConfigView.vue`)
|
|
200
|
-
await EJSUtils.renderToFile('WidgetConfig.ejs', configFile, 'vue', renderOptions)
|
|
201
|
-
}
|
|
202
|
-
// 注册路由
|
|
203
|
-
const routeFile = path.join(widgetRootDir, 'widget-router.ts')
|
|
204
|
-
let routeContent
|
|
205
|
-
if (fs.existsSync(routeFile)) {
|
|
206
|
-
routeContent = fs.readFileSync(routeFile, 'utf8')
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
routeContent = fs.readFileSync(path.join(__dirname, '../template/widget-router.ts'), 'utf8')
|
|
210
|
-
}
|
|
211
|
-
const importRouteStr = `import ${name}WidgetRoutes from "./${paramCaseName}/${name}WidgetRoutes";`
|
|
212
|
-
const routeStr = `...${name}WidgetRoutes,`
|
|
213
|
-
if (!routeContent.includes(importRouteStr)) {
|
|
214
|
-
routeContent = routeContent.replaceAll(
|
|
215
|
-
'// FBI WANING! IMPORT PLACE',
|
|
216
|
-
`${importRouteStr}\n//FBI WANING! IMPORT PLACE`,
|
|
217
|
-
)
|
|
218
|
-
}
|
|
219
|
-
if (!routeContent.includes(routeStr)) {
|
|
220
|
-
routeContent = routeContent.replaceAll('// FBI WANING! ROUTE PLACE', `${routeStr}\n // FBI WANING! ROUTE PLACE`)
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
fs.writeFileSync(routeFile, routeContent)
|
|
224
|
-
|
|
225
|
-
// 添加到版本控制
|
|
226
|
-
const gitAdd = `git add ${widgetDir}`
|
|
227
|
-
consola.info(chalk.grey(gitAdd))
|
|
228
|
-
shell.exec(gitAdd)
|
|
229
|
-
consola.log('=================')
|
|
230
|
-
consola.info(`已创建组件:${widgetDir}`)
|
|
231
|
-
consola.success('Happy coding!')
|
|
232
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { RemoteDependencies } from './remoteDependencies'
|
|
2
|
-
import { LocalDependencies } from './localDependencies'
|
|
3
|
-
|
|
4
|
-
export type DependenciesOptions = 'remote' | 'local'
|
|
5
|
-
export default async function (options: any) {
|
|
6
|
-
const type = options.type as DependenciesOptions
|
|
7
|
-
if (type == 'remote') {
|
|
8
|
-
await RemoteDependencies.start()
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
await LocalDependencies.start()
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import ora from 'ora'
|
|
3
|
-
import { Utils, getPackagePath, widgetPackages } from '../utils'
|
|
4
|
-
|
|
5
|
-
const spinner = ora('Connecting')
|
|
6
|
-
|
|
7
|
-
export namespace LocalDependencies {
|
|
8
|
-
export async function start() {
|
|
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:*)!')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function setWorkspaceVersion(dependencies: { [key: string]: string }, packageNames: string[]) {
|
|
21
|
-
const localPackages = Object.keys(dependencies)
|
|
22
|
-
for (const localPackage of localPackages) {
|
|
23
|
-
if (packageNames.includes(localPackage)) {
|
|
24
|
-
dependencies[localPackage] = `workspace:*`
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import ora from 'ora'
|
|
3
|
-
import { Utils, getPackagePath, widgetPackages } from '../utils'
|
|
4
|
-
|
|
5
|
-
const spinner = ora('Connecting')
|
|
6
|
-
|
|
7
|
-
export namespace RemoteDependencies {
|
|
8
|
-
|
|
9
|
-
export async function start() {
|
|
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!')
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function upgradePackage(dependencies: { [key: string]: string }, packageNames: string[]) {
|
|
22
|
-
const localPackages = Object.keys(dependencies)
|
|
23
|
-
for (const localPackage of localPackages) {
|
|
24
|
-
if (packageNames.includes(localPackage)) {
|
|
25
|
-
let packageVersion = widgetPackages[localPackage]
|
|
26
|
-
if (!packageVersion) {
|
|
27
|
-
spinner.info(`Fetching package version:${localPackage}`)
|
|
28
|
-
packageVersion = await Utils.getRemoteVersion(localPackage)
|
|
29
|
-
widgetPackages[localPackage] = packageVersion
|
|
30
|
-
spinner.info(`version:${packageVersion}`)
|
|
31
|
-
}
|
|
32
|
-
dependencies[localPackage] = `^${packageVersion}`
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
|
|
6
|
-
import figlet from 'figlet'
|
|
7
|
-
import gradient from 'gradient-string'
|
|
8
|
-
import { dirname } from 'dirname-filename-esm'
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
const packageJsonPath = path.join(dirname(import.meta), '../package.json')
|
|
12
|
-
const cliPackage = JSON.parse(fs.readFileSync(packageJsonPath).toString())
|
|
13
|
-
// eslint-disable-next-line no-console
|
|
14
|
-
console.log(gradient.pastel.multiline(figlet.textSync('widget-cli', { horizontalLayout: 'full' })))
|
|
15
|
-
program.version(`@widget-js/cli ${cliPackage.version}`).usage('<command> [options]')
|
|
16
|
-
program
|
|
17
|
-
.command('create')
|
|
18
|
-
.description('Create new widget')
|
|
19
|
-
.action(async () => {
|
|
20
|
-
const createWidget = await import('./createWidget')
|
|
21
|
-
await createWidget.default()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const dependenciesOption = new Option('-t, --type <type>').choices(['remote', 'local'])
|
|
25
|
-
|
|
26
|
-
program
|
|
27
|
-
.command('dependencies')
|
|
28
|
-
.description('Set @widget-js dependencies to local(workspace:*) or remote(^1.0.0 etc)')
|
|
29
|
-
.addOption(dependenciesOption)
|
|
30
|
-
.action(async (options) => {
|
|
31
|
-
const dependencies = await import('./dependencies/index')
|
|
32
|
-
await dependencies.default(options)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
program
|
|
36
|
-
.command('init')
|
|
37
|
-
.description('Initialize widget-js project')
|
|
38
|
-
.action(async () => {
|
|
39
|
-
const init = await import('./init/init')
|
|
40
|
-
await init.init()
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
const keyOption = new Option('-k, --key <key>')
|
|
44
|
-
program
|
|
45
|
-
.command('publish')
|
|
46
|
-
.description('Publish widget package with developer key')
|
|
47
|
-
.addOption(keyOption)
|
|
48
|
-
.action(async (options) => {
|
|
49
|
-
const publishImport = await import('./publish/index')
|
|
50
|
-
await publishImport.publish(options)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
const typeOption = new Option('-t, --type <type>').choices(['ftp', 'oss'])
|
|
54
|
-
const fileOption = new Option('-f, --file <file>')
|
|
55
|
-
program
|
|
56
|
-
.command('release')
|
|
57
|
-
.description('通过FTP/OSS发布文件,仅内部使用')
|
|
58
|
-
.addOption(typeOption)
|
|
59
|
-
.addOption(fileOption)
|
|
60
|
-
.action(async (options) => {
|
|
61
|
-
const release = await import('./release/release')
|
|
62
|
-
await release.default(options)
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
program.parse(process.argv)
|