@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
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Answers, Question } from 'inquirer'
|
|
2
|
+
import inquirer from 'inquirer'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
const answer:Answers = await inquirer.prompt([prompt])
|
|
4
|
+
async function promptChecker<T extends Question>(prompt: T, checker?: (answer: any) => boolean): Promise<any> {
|
|
5
|
+
const answer: Answers = await inquirer.prompt([prompt])
|
|
5
6
|
if (checker) {
|
|
6
7
|
if (checker(answer)) {
|
|
7
|
-
return answer[prompt.name!]
|
|
8
|
-
}
|
|
9
|
-
|
|
8
|
+
return answer[prompt.name!]
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return promptChecker(prompt, checker)
|
|
10
12
|
}
|
|
11
13
|
}
|
|
12
|
-
return answer[prompt.name!]
|
|
14
|
+
return answer[prompt.name!]
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
export default promptChecker
|
|
17
|
+
export default promptChecker
|
package/src/release/ftp.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import fs from 'fs'
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import os from 'node:os'
|
|
4
|
+
import * as process from 'node:process'
|
|
3
5
|
import SSHConfig from '@widget-js/ssh-config'
|
|
4
|
-
import os from 'os'
|
|
5
6
|
import Client from 'ssh2-sftp-client'
|
|
6
7
|
import consola from 'consola'
|
|
7
8
|
import inquirer from 'inquirer'
|
|
8
9
|
import ora from 'ora'
|
|
9
|
-
import
|
|
10
|
-
import {Utils} from '../utils'
|
|
11
|
-
import {minimatch} from 'minimatch'
|
|
10
|
+
import { minimatch } from 'minimatch'
|
|
11
|
+
import { Utils } from '../utils'
|
|
12
12
|
|
|
13
13
|
interface PasswordAnswer {
|
|
14
14
|
password: string
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
async function checkParentDir(ftpClient: Client, file: string, onMkdir: (dir: string) => void) {
|
|
18
|
-
|
|
18
|
+
const dir = path.dirname(file)
|
|
19
19
|
const dirExists = await ftpClient.exists(dir)
|
|
20
20
|
if (!dirExists) {
|
|
21
21
|
onMkdir(dir)
|
|
@@ -26,38 +26,39 @@ async function checkParentDir(ftpClient: Client, file: string, onMkdir: (dir: st
|
|
|
26
26
|
async function runSSH(sshConfig: Record<string, string | string[]>, releaseConfig: ReleaseConfig) {
|
|
27
27
|
consola.info('run ssh:', sshConfig)
|
|
28
28
|
const answer = await inquirer.prompt<PasswordAnswer>([
|
|
29
|
-
{type: 'password', name: 'password', mask: '*', message: 'Enter key pair password'},
|
|
29
|
+
{ type: 'password', name: 'password', mask: '*', message: 'Enter key pair password' },
|
|
30
30
|
])
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
const port = sshConfig
|
|
32
|
+
const ftpClient = new Client()
|
|
33
|
+
const port = sshConfig.Port
|
|
34
34
|
const key = fs.readFileSync(path.resolve(os.homedir(), '.ssh/id_rsa'))
|
|
35
35
|
const spinner = ora('Connecting')
|
|
36
36
|
try {
|
|
37
37
|
spinner.start()
|
|
38
38
|
await ftpClient.connect({
|
|
39
|
-
host: sshConfig
|
|
40
|
-
port: port ? parseInt(port as string) : 22,
|
|
41
|
-
username: sshConfig
|
|
39
|
+
host: sshConfig.HostName as string,
|
|
40
|
+
port: port ? Number.parseInt(port as string) : 22,
|
|
41
|
+
username: sshConfig.User as string,
|
|
42
42
|
passphrase: answer.password,
|
|
43
43
|
privateKey: key,
|
|
44
44
|
})
|
|
45
45
|
releaseConfig.fileMap.sort((it1, it2) => (it1.order ?? 0) - (it2.order ?? 0))
|
|
46
46
|
// upload files
|
|
47
|
-
for (
|
|
47
|
+
for (const item of releaseConfig.fileMap) {
|
|
48
48
|
if (typeof item.src == 'string') {
|
|
49
49
|
if (item.remoteCopy) {
|
|
50
|
-
await checkParentDir(ftpClient, item.dest, dir => {
|
|
50
|
+
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
51
51
|
spinner.warn(`Create Dir: ${dir}`)
|
|
52
52
|
})
|
|
53
|
-
|
|
53
|
+
const destExists = await ftpClient.exists(item.dest)
|
|
54
54
|
if (destExists) {
|
|
55
55
|
spinner.warn(`Delete exists file:${item.dest}`)
|
|
56
56
|
await ftpClient.delete(item.dest)
|
|
57
57
|
}
|
|
58
58
|
spinner.info(`Copying File: ${item.src} -> ${item.dest}`)
|
|
59
59
|
await ftpClient.rcopy(item.src, item.dest)
|
|
60
|
-
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
61
62
|
const localFile = path.resolve(process.cwd(), item.src as string)
|
|
62
63
|
if (!item.remoteCopy && !fs.existsSync(localFile)) {
|
|
63
64
|
spinner.warn(`Skip not exists file:${localFile}`)
|
|
@@ -66,19 +67,20 @@ async function runSSH(sshConfig: Record<string, string | string[]>, releaseConfi
|
|
|
66
67
|
if (fs.lstatSync(localFile).isDirectory()) {
|
|
67
68
|
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`)
|
|
68
69
|
await ftpClient.uploadDir(localFile, item.dest, {
|
|
69
|
-
filter: (filePath: string, isDirectory: boolean):boolean => {
|
|
70
|
+
filter: (filePath: string, isDirectory: boolean): boolean => {
|
|
70
71
|
if (item.ignorePattern && !isDirectory) {
|
|
71
|
-
|
|
72
|
+
const fileName = path.basename(filePath)
|
|
72
73
|
if (minimatch(fileName, item.ignorePattern)) {
|
|
73
74
|
spinner.warn(`Skip file:${filePath}`)
|
|
74
75
|
return false
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
|
-
return true
|
|
78
|
+
return true
|
|
78
79
|
},
|
|
79
80
|
})
|
|
80
|
-
}
|
|
81
|
-
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
82
84
|
spinner.succeed(`Create Dir: ${dir}`)
|
|
83
85
|
})
|
|
84
86
|
|
|
@@ -86,13 +88,15 @@ async function runSSH(sshConfig: Record<string, string | string[]>, releaseConfi
|
|
|
86
88
|
await ftpClient.put(localFile, item.dest)
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
|
-
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
90
93
|
await ftpClient.put(Buffer.from(JSON.stringify(item.src), 'utf-8'), item.dest)
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
spinner.succeed('Files uploaded!')
|
|
94
97
|
await ftpClient.end()
|
|
95
|
-
}
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
96
100
|
spinner.fail(`Connection error:${e}`)
|
|
97
101
|
await ftpClient.end()
|
|
98
102
|
}
|
|
@@ -104,13 +108,13 @@ export async function ftpUpload(releaseFile: string = 'release.json') {
|
|
|
104
108
|
const packageVersion = Utils.getPackageVersion()
|
|
105
109
|
consola.info('Package Version:', packageVersion)
|
|
106
110
|
|
|
107
|
-
|
|
111
|
+
const releaseJson = fs.readFileSync(releaseJsonFilePath).toString().replaceAll('${version}', packageVersion)
|
|
108
112
|
const releaseConfig = JSON.parse(releaseJson) as ReleaseConfig
|
|
109
113
|
const sshConfigFile = path.resolve(os.homedir(), '.ssh/config')
|
|
110
114
|
consola.info('SSH Config File Path:', sshConfigFile)
|
|
111
115
|
const sshConfigs = SSHConfig.parse(fs.readFileSync(sshConfigFile).toString())
|
|
112
|
-
for (
|
|
113
|
-
|
|
116
|
+
for (const host of releaseConfig.ftpConfig.host) {
|
|
117
|
+
const sshConfig = sshConfigs.compute(host)
|
|
114
118
|
if (!sshConfig) {
|
|
115
119
|
consola.error(`SSH config ${releaseConfig.ftpConfig.host} not found`)
|
|
116
120
|
return
|
package/src/release/oss.ts
CHANGED
|
@@ -1,47 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import chalk from
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import OSS from 'ali-oss'
|
|
3
|
+
import chalk from 'chalk'
|
|
4
|
+
import consola from 'consola'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
export const AccessKeyID = packageData.oss?.id ??
|
|
7
|
-
export const AccessKeySecret = packageData.oss?.secret ??
|
|
6
|
+
const packageData = JSON.parse(fs.readFileSync('./package.json').toString())
|
|
7
|
+
export const AccessKeyID = packageData.oss?.id ?? 'default'
|
|
8
|
+
export const AccessKeySecret = packageData.oss?.secret ?? 'default'
|
|
8
9
|
|
|
9
10
|
const headers = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
11
|
+
// 指定Object的存储类型。
|
|
12
|
+
'x-oss-storage-class': 'Standard',
|
|
13
|
+
// 指定Object的访问权限。
|
|
14
|
+
'x-oss-object-acl': 'public-read',
|
|
15
|
+
'x-oss-forbid-overwrite': 'false',
|
|
16
|
+
'Cache-Control': 'no-cache',
|
|
17
|
+
}
|
|
17
18
|
|
|
18
19
|
const clinet = new OSS({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
20
|
+
// yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
|
|
21
|
+
region: 'oss-cn-hangzhou',
|
|
22
|
+
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
23
|
+
accessKeyId: AccessKeyID,
|
|
24
|
+
accessKeySecret: AccessKeySecret,
|
|
25
|
+
bucket: 'widget-fun',
|
|
26
|
+
})
|
|
26
27
|
|
|
27
|
-
export async function put(ossPath:string, file:any) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
export async function put(ossPath: string, file: any) {
|
|
29
|
+
try {
|
|
30
|
+
// 填写OSS文件完整路径和本地文件的完整路径。OSS文件完整路径中不能包含Bucket名称。
|
|
31
|
+
// 如果本地文件的完整路径中未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件。
|
|
32
|
+
await clinet.put(ossPath, file, { headers })
|
|
33
|
+
consola.log(chalk.green(`上传成功:${file}->${ossPath}`))
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
consola.log(e)
|
|
37
|
+
}
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
export async function copy(dist:string, src:string) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
export async function copy(dist: string, src: string) {
|
|
41
|
+
try {
|
|
42
|
+
// 填写OSS文件完整路径和本地文件的完整路径。OSS文件完整路径中不能包含Bucket名称。
|
|
43
|
+
// 如果本地文件的完整路径中未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件。
|
|
44
|
+
await clinet.copy(dist, src, { headers })
|
|
45
|
+
consola.log(chalk.green(`复制成功:${src}->${dist}`))
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
console.error(e)
|
|
49
|
+
}
|
|
47
50
|
}
|
package/src/release/release.ts
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import path from 'path'
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { Buffer } from 'node:buffer'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
import consola from 'consola'
|
|
3
6
|
import promptChecker from '../promts/promptChecker.js'
|
|
4
7
|
import zipDirectory from './update-zip.js'
|
|
5
|
-
import {copy, put} from './oss.js'
|
|
6
|
-
import
|
|
7
|
-
import {ftpUpload} from './ftp'
|
|
8
|
-
|
|
9
|
-
async function delay(time: number) {
|
|
10
|
-
return new Promise<void>((resolve, reject) => {
|
|
11
|
-
setTimeout(() => {
|
|
12
|
-
resolve()
|
|
13
|
-
}, time)
|
|
14
|
-
})
|
|
15
|
-
}
|
|
8
|
+
import { copy, put } from './oss.js'
|
|
9
|
+
import { ftpUpload } from './ftp'
|
|
16
10
|
|
|
17
|
-
|
|
11
|
+
async function release(options: any) {
|
|
18
12
|
if (options.type == 'ftp') {
|
|
19
13
|
await ftpUpload(options.file)
|
|
20
14
|
return
|
|
21
15
|
}
|
|
22
16
|
const packageJSON = JSON.parse(fs.readFileSync('package.json', 'utf-8'))
|
|
23
17
|
const changelogJSON = JSON.parse(fs.readFileSync('changelog.json', 'utf-8'))
|
|
24
|
-
const version = packageJSON
|
|
18
|
+
const version = packageJSON.version
|
|
25
19
|
const changelog = changelogJSON[version]
|
|
26
20
|
|
|
27
|
-
|
|
21
|
+
const needUpdateElectron = await promptChecker({
|
|
28
22
|
type: 'confirm',
|
|
29
23
|
name: 'electron',
|
|
30
24
|
message: chalk.blue('用户是否需要更新Electron?'),
|
|
@@ -37,7 +31,7 @@ const release = async (options: any) => {
|
|
|
37
31
|
// });
|
|
38
32
|
|
|
39
33
|
const versionInfo = {
|
|
40
|
-
version
|
|
34
|
+
version,
|
|
41
35
|
releaseNote: changelog,
|
|
42
36
|
updateElectron: needUpdateElectron,
|
|
43
37
|
updateNodeModule: false,
|
|
@@ -54,24 +48,23 @@ const release = async (options: any) => {
|
|
|
54
48
|
}
|
|
55
49
|
const updateZipPath = path.join(`./dist/update.zip`)
|
|
56
50
|
|
|
57
|
-
|
|
51
|
+
consola.log(chalk.blue('压缩更新文件中'))
|
|
58
52
|
await zipDirectory('./release', updateZipPath)
|
|
59
53
|
|
|
60
|
-
|
|
54
|
+
consola.log(chalk.blue('上传installer.exe到OSS'))
|
|
61
55
|
await put('version/installer.exe', installerPath)
|
|
62
56
|
|
|
63
|
-
|
|
57
|
+
consola.log(chalk.blue('上传update.zip到OSS'))
|
|
64
58
|
await put('version/update.zip', updateZipPath)
|
|
65
59
|
|
|
66
|
-
|
|
60
|
+
consola.log(chalk.blue('更新版本信息'))
|
|
67
61
|
versionInfo.downloadLink = 'https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip'
|
|
68
62
|
const versionJSON = JSON.stringify(versionInfo, null, 2)
|
|
69
63
|
await put('version/version.json', Buffer.from(versionJSON))
|
|
70
64
|
|
|
71
|
-
copy(`version/history/${version}.exe`, 'version/installer.exe')
|
|
72
|
-
copy(`version/history/update-${version}.zip`, 'version/update.zip')
|
|
65
|
+
await Promise.all([copy(`version/history/${version}.exe`, 'version/installer.exe'), copy(`version/history/update-${version}.zip`, 'version/update.zip')])
|
|
73
66
|
|
|
74
|
-
|
|
67
|
+
consola.log(chalk.yellow(versionJSON))
|
|
75
68
|
}
|
|
76
69
|
|
|
77
70
|
export default release
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import archiver from
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import archiver from 'archiver'
|
|
3
3
|
|
|
4
|
-
function zipDirectory(sourceDir:string, outPath:string, ignoreDir?:string[]) {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
function zipDirectory(sourceDir: string, outPath: string, ignoreDir?: string[]) {
|
|
5
|
+
const archive = archiver('zip', { zlib: { level: 9 } })
|
|
6
|
+
const stream = fs.createWriteStream(outPath)
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
return new Promise<void>((resolve, reject) => {
|
|
9
|
+
archive
|
|
10
|
+
.glob('**/*', { cwd: sourceDir, ignore: ['node_modules/**'] })
|
|
11
|
+
.on('error', err => reject(err))
|
|
12
|
+
.pipe(stream)
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
stream.on('close', () => resolve())
|
|
15
|
+
archive.finalize()
|
|
16
|
+
})
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export default zipDirectory
|
|
19
|
+
export default zipDirectory
|
package/src/utils/EJSUtils.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import fs from 'fs'
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import type { Data } from 'ejs'
|
|
4
|
+
import ejs from 'ejs'
|
|
5
|
+
import type { BuiltInParserName } from 'prettier'
|
|
6
|
+
import { dirname } from 'dirname-filename-esm'
|
|
7
|
+
import { PrettierUtils } from './PrettierUtils'
|
|
7
8
|
|
|
8
9
|
export class EJSUtils {
|
|
9
10
|
static async renderToFile(templateFile: string, outputFile: string, parser: BuiltInParserName, renderOptions: Data) {
|
|
10
11
|
const defineTemplatePath = path.join(dirname(import.meta), '../template', templateFile)
|
|
11
|
-
|
|
12
|
+
const defineTemplate = fs.readFileSync(defineTemplatePath, 'utf8')
|
|
12
13
|
// Format the EJS code using Prettier
|
|
13
|
-
|
|
14
|
-
const formattedEJSCode =await PrettierUtils.format(code,parser)
|
|
14
|
+
const code = ejs.render(defineTemplate, renderOptions)
|
|
15
|
+
const formattedEJSCode = await PrettierUtils.format(code, parser)
|
|
15
16
|
fs.writeFileSync(outputFile, formattedEJSCode)
|
|
16
17
|
}
|
|
17
18
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {BuiltInParserName
|
|
1
|
+
import type { BuiltInParserName } from 'prettier'
|
|
2
|
+
import { format } from 'prettier'
|
|
2
3
|
|
|
3
4
|
export class PrettierUtils {
|
|
4
5
|
static async format(code: string, parser: BuiltInParserName) {
|
|
5
6
|
return format(code, {
|
|
6
|
-
parser
|
|
7
|
+
parser,
|
|
7
8
|
tabWidth: 2,
|
|
8
9
|
singleQuote: true,
|
|
9
10
|
})
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import type { WidgetPackage } from '@widget-js/core'
|
|
4
4
|
|
|
5
5
|
export class WidgetPackageUtils {
|
|
6
6
|
static getRootDir(widgetPackage: WidgetPackage) {
|
|
7
7
|
const widgetRootDir = path.join(process.cwd(), widgetPackage.devOptions?.folder ?? './src/widgets')
|
|
8
8
|
if (!fs.existsSync(widgetRootDir)) {
|
|
9
|
-
fs.mkdirSync(widgetRootDir, {recursive: true})
|
|
9
|
+
fs.mkdirSync(widgetRootDir, { recursive: true })
|
|
10
10
|
}
|
|
11
|
-
return widgetRootDir
|
|
11
|
+
return widgetRootDir
|
|
12
12
|
}
|
|
13
13
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,41 +1,45 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import process from
|
|
3
|
-
import fs from
|
|
4
|
-
import packageJson from
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import process from 'node:process'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import packageJson from 'package-json'
|
|
5
5
|
|
|
6
6
|
export const widgetPackages: { [key: string]: string } = {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
'@widget-js/core': '',
|
|
8
|
+
'@widget-js/vue3': '',
|
|
9
|
+
'@widget-js/cli': '',
|
|
10
|
+
'@widget-js/utils': '',
|
|
11
|
+
'@widget-js/vite-plugin-widget': '',
|
|
12
|
+
}
|
|
9
13
|
export default function exit(code: number = 0) {
|
|
10
14
|
if (exports.exitProcess) {
|
|
11
|
-
process.exit(code)
|
|
12
|
-
}
|
|
13
|
-
|
|
15
|
+
process.exit(code)
|
|
16
|
+
}
|
|
17
|
+
else if (code > 0) {
|
|
18
|
+
throw new Error(`Process exited with code ${code}`)
|
|
14
19
|
}
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
export function getPackagePath() {
|
|
18
|
-
return path.join(process.cwd(),
|
|
23
|
+
return path.join(process.cwd(), 'package.json')
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
|
|
22
26
|
export class Utils {
|
|
23
27
|
static async getRemoteVersion(packageName: string): Promise<string> {
|
|
24
|
-
const metadata = await packageJson(packageName)
|
|
25
|
-
|
|
26
|
-
return version as string
|
|
28
|
+
const metadata = await packageJson(packageName)
|
|
29
|
+
const version = metadata.version
|
|
30
|
+
return version as string
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
static getPackagePath() {
|
|
30
|
-
return path.join(process.cwd(),
|
|
34
|
+
return path.join(process.cwd(), 'package.json')
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
static getPackageJson() {
|
|
34
|
-
return JSON.parse(fs.readFileSync(this.getPackagePath()).toString())
|
|
38
|
+
return JSON.parse(fs.readFileSync(this.getPackagePath()).toString())
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
return this.getPackageJson()
|
|
41
|
+
static getPackageVersion() {
|
|
42
|
+
return this.getPackageJson().version
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
/**
|
|
@@ -45,36 +49,36 @@ export class Utils {
|
|
|
45
49
|
* 3.不能包含连续的小数点
|
|
46
50
|
* @param name
|
|
47
51
|
*/
|
|
48
|
-
static checkPackageName(name: string):boolean {
|
|
52
|
+
static checkPackageName(name: string): boolean {
|
|
49
53
|
// 检查包名是否以小数点结尾
|
|
50
54
|
if (name.endsWith('.')) {
|
|
51
|
-
return false
|
|
55
|
+
return false
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
// 检查包名是否包含无效字符
|
|
55
|
-
const invalidCharacters = /[\\/:*?\"<>| ]/g
|
|
59
|
+
const invalidCharacters = /[\\/:*?\"<>| ]/g
|
|
56
60
|
if (name.match(invalidCharacters)) {
|
|
57
|
-
return false
|
|
61
|
+
return false
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
// 检查包名是否至少包含一个子段
|
|
61
|
-
const segments = name.split('.')
|
|
65
|
+
const segments = name.split('.')
|
|
62
66
|
if (segments.length < 2) {
|
|
63
|
-
return false
|
|
67
|
+
return false
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
// 检查每个子段是否以字母开头
|
|
67
71
|
for (const segment of segments) {
|
|
68
72
|
if (!segment.match(/^[a-z]/)) {
|
|
69
|
-
return false
|
|
73
|
+
return false
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
// 检查子段是否包含连续的小数点
|
|
73
77
|
if (segment.includes('.' + '.')) {
|
|
74
|
-
return false
|
|
78
|
+
return false
|
|
75
79
|
}
|
|
76
80
|
}
|
|
77
81
|
|
|
78
|
-
return true
|
|
82
|
+
return true
|
|
79
83
|
}
|
|
80
84
|
}
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<widget-edit-dialog :widget-params="widgetParams" :option="widgetConfigOption"
|
|
3
|
-
|
|
3
|
+
v-model="widgetData"
|
|
4
4
|
@apply="save()"
|
|
5
5
|
@confirm="save({ closeWindow: true })">
|
|
6
6
|
</widget-edit-dialog>
|
|
7
7
|
</template>
|
|
8
8
|
|
|
9
9
|
<script lang="ts" setup>
|
|
10
|
-
import {useWidget, WidgetConfigOption
|
|
10
|
+
import {useWidget, WidgetConfigOption} from "@widget-js/vue3";
|
|
11
11
|
import {WidgetData} from "@widget-js/core";
|
|
12
12
|
|
|
13
13
|
const {widgetData, widgetParams, save} = useWidget(WidgetData)
|
|
14
14
|
|
|
15
15
|
//修改成需要设置组件参数配置
|
|
16
16
|
const widgetConfigOption = new WidgetConfigOption({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
theme:{
|
|
18
|
+
backgroundColor: true,
|
|
19
|
+
borderRadius: true,
|
|
20
|
+
color:true
|
|
21
|
+
}
|
|
21
22
|
});
|
|
22
23
|
|
|
23
24
|
</script>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { RouteRecordRaw } from 'vue-router'
|
|
2
|
-
|
|
1
|
+
import type { RouteRecordRaw } from 'vue-router'
|
|
2
|
+
|
|
3
|
+
// FBI WANING! IMPORT PLACE, DONT DELETE THIS LINE
|
|
3
4
|
const WidgetRouter: RouteRecordRaw[] = [
|
|
4
|
-
|
|
5
|
-
]
|
|
5
|
+
// FBI WANING! ROUTE PLACE, DONT DELETE THIS LINE
|
|
6
|
+
]
|
|
6
7
|
export default WidgetRouter
|
package/test/index.test.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { expect } from 'vitest'
|
|
3
|
+
import { minimatch } from 'minimatch'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
expect(minimatch(fileName,'*.ejs')).toBeTruthy()
|
|
8
|
-
expect(minimatch(fileName,'*.ts')).toBeFalsy()
|
|
5
|
+
it('minimatch', () => {
|
|
6
|
+
const fileName = path.basename('C:\\Users\\rtuge\\Desktop\\github\\widgetjs\\packages\\@widget-js\\cli\\template\\Widget.ejs')
|
|
7
|
+
expect(minimatch(fileName, '*.ejs')).toBeTruthy()
|
|
8
|
+
expect(minimatch(fileName, '*.ts')).toBeFalsy()
|
|
9
9
|
})
|