@widget-js/cli 24.1.1-beta.15 → 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/{lib/createWidget-4LQ6PVEM.js → dist/createWidget-EBGZI7JV.js} +3 -3
- package/{lib → dist}/index.js +1 -1
- package/package.json +16 -11
- package/template/WidgetConfig.ejs +2 -6
- package/template/WidgetDefine.ejs +2 -1
- 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}/dependencies-AVNHKRF3.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/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)
|
package/src/init/init.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
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
|
-
import consola from 'consola'
|
|
6
|
-
import chalk from 'chalk'
|
|
7
|
-
import ora from 'ora'
|
|
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
|
-
|
|
15
|
-
const __filename = fileURLToPath(import.meta.url)
|
|
16
|
-
const __dirname = path.dirname(__filename)
|
|
17
|
-
const spinner = ora('Loading')
|
|
18
|
-
|
|
19
|
-
export async function init() {
|
|
20
|
-
await addDependencies()
|
|
21
|
-
await addWidgetTs()
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function addWidgetTs() {
|
|
25
|
-
const name = await promptChecker(
|
|
26
|
-
{
|
|
27
|
-
type: 'input',
|
|
28
|
-
name: 'name',
|
|
29
|
-
message: chalk.blue('组件包 包名 (示例 cn.widget.countdown):'),
|
|
30
|
-
},
|
|
31
|
-
(answer) => {
|
|
32
|
-
const name = answer.name
|
|
33
|
-
if (name == null || name === '') {
|
|
34
|
-
consola.log(chalk.red(`包名不能为空`))
|
|
35
|
-
return false
|
|
36
|
-
}
|
|
37
|
-
return true
|
|
38
|
-
},
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
const widgetPackageTs = path.join(process.cwd(), 'widget.package.ts')
|
|
42
|
-
if (fs.existsSync(widgetPackageTs)) {
|
|
43
|
-
spinner.info('widget.package.ts已存在,跳过')
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
spinner.info('创建 widget.package.ts')
|
|
47
|
-
await EJSUtils.renderToFile('WidgetPackage.ejs', widgetPackageTs, 'typescript', { name })
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
await addVitePlugin()
|
|
51
|
-
await createRouter()
|
|
52
|
-
|
|
53
|
-
spinner.succeed('初始化完成,请运行 npm install')
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 增加widget-js依赖
|
|
58
|
-
*/
|
|
59
|
-
async function addDependencies() {
|
|
60
|
-
const packageJson = Utils.getPackageJson()
|
|
61
|
-
let dependencies = packageJson.dependencies
|
|
62
|
-
const devDependencies = packageJson.devDependencies
|
|
63
|
-
if (!dependencies) {
|
|
64
|
-
dependencies = {}
|
|
65
|
-
}
|
|
66
|
-
if (!devDependencies) {
|
|
67
|
-
packageJson.devDependencies = {}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
await addDependency('@widget-js/core', dependencies)
|
|
71
|
-
await addDependency('@widget-js/vue3', dependencies)
|
|
72
|
-
await addDependency('@widget-js/vite-plugin-widget', devDependencies)
|
|
73
|
-
|
|
74
|
-
packageJson.dependencies = dependencies
|
|
75
|
-
packageJson.devDependencies = devDependencies
|
|
76
|
-
|
|
77
|
-
fs.writeFileSync(Utils.getPackagePath(), JSON.stringify(packageJson, null, 2))
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async function addVitePlugin() {
|
|
81
|
-
spinner.info('添加 vite-plugin-widget 到 vite plugin')
|
|
82
|
-
const viteConfigPath = path.join(process.cwd(), 'vite.config.ts')
|
|
83
|
-
if (!fs.existsSync(viteConfigPath)) {
|
|
84
|
-
spinner.warn('vite.config.ts not exists')
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
let viteConfig = fs.readFileSync(viteConfigPath).toString()
|
|
88
|
-
viteConfig = `import widget from '@widget-js/vite-plugin-widget'\n${viteConfig}`
|
|
89
|
-
viteConfig = viteConfig.replace('vue()', `vue(),widget()`)
|
|
90
|
-
fs.writeFileSync(viteConfigPath, await PrettierUtils.format(viteConfig, 'typescript'))
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function createRouter() {
|
|
94
|
-
const widgetPackage = await scanWidgetPackage()
|
|
95
|
-
if (widgetPackage) {
|
|
96
|
-
spinner.info('创建 widget-router.ts')
|
|
97
|
-
const rootDir = WidgetPackageUtils.getRootDir(widgetPackage)
|
|
98
|
-
const widgetRouterPath = path.join(rootDir, 'widget-router.ts')
|
|
99
|
-
const routerContent = fs.readFileSync(path.join(__dirname, '../template/widget-router.ts'), 'utf8')
|
|
100
|
-
fs.writeFileSync(widgetRouterPath, routerContent)
|
|
101
|
-
|
|
102
|
-
const vueRouterPath = path.join(process.cwd(), './src/router/index.ts')
|
|
103
|
-
spinner.info('修改VueRouter配置')
|
|
104
|
-
if (fs.existsSync(vueRouterPath)) {
|
|
105
|
-
let vueRouterContent = fs.readFileSync(vueRouterPath, 'utf8')
|
|
106
|
-
const importStr = `import WidgetRouter from "../widgets/widget-router";`
|
|
107
|
-
vueRouterContent = `${importStr}\n${vueRouterContent}`
|
|
108
|
-
vueRouterContent = vueRouterContent.replace('routes: [', `routes: [\n...WidgetRouter,`)
|
|
109
|
-
fs.writeFileSync(vueRouterPath, await PrettierUtils.format(vueRouterContent, 'typescript'))
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async function addDependency(packageName: string, dependencies: any) {
|
|
115
|
-
spinner.info(`Adding dependencies ${packageName}`)
|
|
116
|
-
if (dependencies[packageName]) {
|
|
117
|
-
return
|
|
118
|
-
}
|
|
119
|
-
const remoteVersion = await Utils.getRemoteVersion(packageName)
|
|
120
|
-
dependencies[packageName] = `^${remoteVersion}`
|
|
121
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Answers, Question } from 'inquirer'
|
|
2
|
-
import inquirer from 'inquirer'
|
|
3
|
-
|
|
4
|
-
async function promptChecker<T extends Question>(prompt: T, checker?: (answer: any) => boolean): Promise<any> {
|
|
5
|
-
const answer: Answers = await inquirer.prompt([prompt])
|
|
6
|
-
if (checker) {
|
|
7
|
-
if (checker(answer)) {
|
|
8
|
-
return answer[prompt.name!]
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
return promptChecker(prompt, checker)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return answer[prompt.name!]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default promptChecker
|
package/src/publish/index.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import fastGlob from 'fast-glob'
|
|
3
|
-
import axios from 'axios'
|
|
4
|
-
import consola from 'consola'
|
|
5
|
-
import ora from 'ora'
|
|
6
|
-
/**
|
|
7
|
-
* 用fast-glob扫描运行目录下第一个 widget.json 文件
|
|
8
|
-
* 然后用axios发送post请求到 https://widgetjs.cn/api/widget/package,把key加到请求头中,把 widget.json 文件内容作为请求体
|
|
9
|
-
*/
|
|
10
|
-
export async function publish(options: { key: string }): Promise<void> {
|
|
11
|
-
if (!options.key) {
|
|
12
|
-
consola.error('Please provide a developer key with -k or --key option.')
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
const spinner = ora('Search widget.json').start()
|
|
16
|
-
try {
|
|
17
|
-
// Scan the current directory for the first widget.json file, ignore node_modules
|
|
18
|
-
const files = await fastGlob('**/widget.json', { onlyFiles: true, ignore: ['node_modules/**'], absolute: true })
|
|
19
|
-
if (files.length === 0) {
|
|
20
|
-
spinner.fail('No widget.json file found.')
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
spinner.succeed(`Widget.json found: ${files[0]}`)
|
|
25
|
-
|
|
26
|
-
const widgetPath = files[0]
|
|
27
|
-
const widgetContent = fs.readFileSync(widgetPath, 'utf-8')
|
|
28
|
-
|
|
29
|
-
const json = JSON.parse(widgetContent)
|
|
30
|
-
consola.info(`Package name:${json.name}`)
|
|
31
|
-
const widgets = json.widgets
|
|
32
|
-
consola.info(`Widget size:${widgets?.length ?? 0}`)
|
|
33
|
-
|
|
34
|
-
spinner.start('Publishing widget package...')
|
|
35
|
-
// Send a POST request to the specified URL with the widget content
|
|
36
|
-
const response = await axios.post('https://widgetjs.cn/api/v1/widget/package', json, {
|
|
37
|
-
headers: {
|
|
38
|
-
'Content-Type': 'application/json',
|
|
39
|
-
'Key': options.key,
|
|
40
|
-
},
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
if (response.data) {
|
|
44
|
-
if (response.data.code == 200) {
|
|
45
|
-
spinner.succeed('Widget published successfully.')
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
spinner.fail('Failed to publish widget.')
|
|
49
|
-
consola.error(response.data.msg)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
spinner.fail('Empty Response')
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
spinner.fail('Failed to publish widget.')
|
|
58
|
-
consola.error(error)
|
|
59
|
-
}
|
|
60
|
-
}
|
package/src/release/ftp.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
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'
|
|
5
|
-
import SSHConfig from '@widget-js/ssh-config'
|
|
6
|
-
import Client from 'ssh2-sftp-client'
|
|
7
|
-
import consola from 'consola'
|
|
8
|
-
import inquirer from 'inquirer'
|
|
9
|
-
import ora from 'ora'
|
|
10
|
-
import { minimatch } from 'minimatch'
|
|
11
|
-
import { Utils } from '../utils'
|
|
12
|
-
|
|
13
|
-
interface PasswordAnswer {
|
|
14
|
-
password: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function checkParentDir(ftpClient: Client, file: string, onMkdir: (dir: string) => void) {
|
|
18
|
-
const dir = path.dirname(file)
|
|
19
|
-
const dirExists = await ftpClient.exists(dir)
|
|
20
|
-
if (!dirExists) {
|
|
21
|
-
onMkdir(dir)
|
|
22
|
-
await ftpClient.mkdir(dir, true)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async function runSSH(sshConfig: Record<string, string | string[]>, releaseConfig: ReleaseConfig) {
|
|
27
|
-
consola.info('run ssh:', sshConfig)
|
|
28
|
-
const answer = await inquirer.prompt<PasswordAnswer>([
|
|
29
|
-
{ type: 'password', name: 'password', mask: '*', message: 'Enter key pair password' },
|
|
30
|
-
])
|
|
31
|
-
|
|
32
|
-
const ftpClient = new Client()
|
|
33
|
-
const port = sshConfig.Port
|
|
34
|
-
const key = fs.readFileSync(path.resolve(os.homedir(), '.ssh/id_rsa'))
|
|
35
|
-
const spinner = ora('Connecting')
|
|
36
|
-
try {
|
|
37
|
-
spinner.start()
|
|
38
|
-
await ftpClient.connect({
|
|
39
|
-
host: sshConfig.HostName as string,
|
|
40
|
-
port: port ? Number.parseInt(port as string) : 22,
|
|
41
|
-
username: sshConfig.User as string,
|
|
42
|
-
passphrase: answer.password,
|
|
43
|
-
privateKey: key,
|
|
44
|
-
})
|
|
45
|
-
releaseConfig.fileMap.sort((it1, it2) => (it1.order ?? 0) - (it2.order ?? 0))
|
|
46
|
-
// upload files
|
|
47
|
-
for (const item of releaseConfig.fileMap) {
|
|
48
|
-
if (typeof item.src == 'string') {
|
|
49
|
-
if (item.remoteCopy) {
|
|
50
|
-
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
51
|
-
spinner.warn(`Create Dir: ${dir}`)
|
|
52
|
-
})
|
|
53
|
-
const destExists = await ftpClient.exists(item.dest)
|
|
54
|
-
if (destExists) {
|
|
55
|
-
spinner.warn(`Delete exists file:${item.dest}`)
|
|
56
|
-
await ftpClient.delete(item.dest)
|
|
57
|
-
}
|
|
58
|
-
spinner.info(`Copying File: ${item.src} -> ${item.dest}`)
|
|
59
|
-
await ftpClient.rcopy(item.src, item.dest)
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
const localFile = path.resolve(process.cwd(), item.src as string)
|
|
63
|
-
if (!item.remoteCopy && !fs.existsSync(localFile)) {
|
|
64
|
-
spinner.warn(`Skip not exists file:${localFile}`)
|
|
65
|
-
continue
|
|
66
|
-
}
|
|
67
|
-
if (fs.lstatSync(localFile).isDirectory()) {
|
|
68
|
-
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`)
|
|
69
|
-
await ftpClient.uploadDir(localFile, item.dest, {
|
|
70
|
-
filter: (filePath: string, isDirectory: boolean): boolean => {
|
|
71
|
-
if (item.ignorePattern && !isDirectory) {
|
|
72
|
-
const fileName = path.basename(filePath)
|
|
73
|
-
if (minimatch(fileName, item.ignorePattern)) {
|
|
74
|
-
spinner.warn(`Skip file:${filePath}`)
|
|
75
|
-
return false
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return true
|
|
79
|
-
},
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
84
|
-
spinner.succeed(`Create Dir: ${dir}`)
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
spinner.info(`Uploading File: ${localFile} -> ${item.dest}`)
|
|
88
|
-
await ftpClient.put(localFile, item.dest)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
await ftpClient.put(Buffer.from(JSON.stringify(item.src), 'utf-8'), item.dest)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
spinner.succeed('Files uploaded!')
|
|
97
|
-
await ftpClient.end()
|
|
98
|
-
}
|
|
99
|
-
catch (e) {
|
|
100
|
-
spinner.fail(`Connection error:${e}`)
|
|
101
|
-
await ftpClient.end()
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export async function ftpUpload(releaseFile: string = 'release.json') {
|
|
106
|
-
// 读取
|
|
107
|
-
const releaseJsonFilePath = path.join(process.cwd(), releaseFile)
|
|
108
|
-
const packageVersion = Utils.getPackageVersion()
|
|
109
|
-
consola.info('Package Version:', packageVersion)
|
|
110
|
-
|
|
111
|
-
const releaseJson = fs.readFileSync(releaseJsonFilePath).toString().replaceAll('${version}', packageVersion)
|
|
112
|
-
const releaseConfig = JSON.parse(releaseJson) as ReleaseConfig
|
|
113
|
-
const sshConfigFile = path.resolve(os.homedir(), '.ssh/config')
|
|
114
|
-
consola.info('SSH Config File Path:', sshConfigFile)
|
|
115
|
-
const sshConfigs = SSHConfig.parse(fs.readFileSync(sshConfigFile).toString())
|
|
116
|
-
for (const host of releaseConfig.ftpConfig.host) {
|
|
117
|
-
const sshConfig = sshConfigs.compute(host)
|
|
118
|
-
if (!sshConfig) {
|
|
119
|
-
consola.error(`SSH config ${releaseConfig.ftpConfig.host} not found`)
|
|
120
|
-
return
|
|
121
|
-
}
|
|
122
|
-
await runSSH(sshConfig, releaseConfig)
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export interface FileMapConfig {
|
|
127
|
-
src: string | object
|
|
128
|
-
dest: string
|
|
129
|
-
remoteCopy: boolean
|
|
130
|
-
order: number
|
|
131
|
-
/**
|
|
132
|
-
* 支持glob、正则表达式
|
|
133
|
-
*/
|
|
134
|
-
ignorePattern?: string
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export interface ReleaseConfig {
|
|
138
|
-
fileMap: FileMapConfig[]
|
|
139
|
-
ftpConfig: FTPConfig
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export interface FTPConfig {
|
|
143
|
-
host: string[]
|
|
144
|
-
}
|
package/src/release/oss.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import OSS from 'ali-oss'
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import consola from 'consola'
|
|
5
|
-
|
|
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'
|
|
9
|
-
|
|
10
|
-
const headers = {
|
|
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
|
-
}
|
|
18
|
-
|
|
19
|
-
const clinet = new OSS({
|
|
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
|
-
})
|
|
27
|
-
|
|
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
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
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
|
-
}
|
|
50
|
-
}
|
package/src/release/release.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
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'
|
|
6
|
-
import promptChecker from '../promts/promptChecker.js'
|
|
7
|
-
import zipDirectory from './update-zip.js'
|
|
8
|
-
import { copy, put } from './oss.js'
|
|
9
|
-
import { ftpUpload } from './ftp'
|
|
10
|
-
|
|
11
|
-
async function release(options: any) {
|
|
12
|
-
if (options.type == 'ftp') {
|
|
13
|
-
await ftpUpload(options.file)
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
const packageJSON = JSON.parse(fs.readFileSync('package.json', 'utf-8'))
|
|
17
|
-
const changelogJSON = JSON.parse(fs.readFileSync('changelog.json', 'utf-8'))
|
|
18
|
-
const version = packageJSON.version
|
|
19
|
-
const changelog = changelogJSON[version]
|
|
20
|
-
|
|
21
|
-
const needUpdateElectron = await promptChecker({
|
|
22
|
-
type: 'confirm',
|
|
23
|
-
name: 'electron',
|
|
24
|
-
message: chalk.blue('用户是否需要更新Electron?'),
|
|
25
|
-
})
|
|
26
|
-
//
|
|
27
|
-
// let needUpdateNodeModule = await promptChecker({
|
|
28
|
-
// type: "confirm",
|
|
29
|
-
// name: 'electron',
|
|
30
|
-
// message: chalk.blue("用户是否需要更新node_module?")
|
|
31
|
-
// });
|
|
32
|
-
|
|
33
|
-
const versionInfo = {
|
|
34
|
-
version,
|
|
35
|
-
releaseNote: changelog,
|
|
36
|
-
updateElectron: needUpdateElectron,
|
|
37
|
-
updateNodeModule: false,
|
|
38
|
-
updateWindowsApi: false,
|
|
39
|
-
downloadLink: '',
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let installerPath = path.join(`./dist/widgets-${version}-setup-win-x64.exe`)
|
|
43
|
-
if (!fs.existsSync(installerPath)) {
|
|
44
|
-
installerPath = path.join(`./dist/electron-${version}-setup-win-x64.exe`)
|
|
45
|
-
}
|
|
46
|
-
if (!fs.existsSync(installerPath)) {
|
|
47
|
-
installerPath = path.join(`./dist/app-${version}-setup-win-x64.exe`)
|
|
48
|
-
}
|
|
49
|
-
const updateZipPath = path.join(`./dist/update.zip`)
|
|
50
|
-
|
|
51
|
-
consola.log(chalk.blue('压缩更新文件中'))
|
|
52
|
-
await zipDirectory('./release', updateZipPath)
|
|
53
|
-
|
|
54
|
-
consola.log(chalk.blue('上传installer.exe到OSS'))
|
|
55
|
-
await put('version/installer.exe', installerPath)
|
|
56
|
-
|
|
57
|
-
consola.log(chalk.blue('上传update.zip到OSS'))
|
|
58
|
-
await put('version/update.zip', updateZipPath)
|
|
59
|
-
|
|
60
|
-
consola.log(chalk.blue('更新版本信息'))
|
|
61
|
-
versionInfo.downloadLink = 'https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip'
|
|
62
|
-
const versionJSON = JSON.stringify(versionInfo, null, 2)
|
|
63
|
-
await put('version/version.json', Buffer.from(versionJSON))
|
|
64
|
-
|
|
65
|
-
await Promise.all([copy(`version/history/${version}.exe`, 'version/installer.exe'), copy(`version/history/update-${version}.zip`, 'version/update.zip')])
|
|
66
|
-
|
|
67
|
-
consola.log(chalk.yellow(versionJSON))
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export default release
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import archiver from 'archiver'
|
|
3
|
-
|
|
4
|
-
function zipDirectory(sourceDir: string, outPath: string, ignoreDir?: string[]) {
|
|
5
|
-
const archive = archiver('zip', { zlib: { level: 9 } })
|
|
6
|
-
const stream = fs.createWriteStream(outPath)
|
|
7
|
-
|
|
8
|
-
return new Promise<void>((resolve, reject) => {
|
|
9
|
-
const ignore: string[] = ['node_modules/**']
|
|
10
|
-
if (ignoreDir) {
|
|
11
|
-
ignore.push(...ignoreDir)
|
|
12
|
-
}
|
|
13
|
-
archive
|
|
14
|
-
.glob('**/*', { cwd: sourceDir, ignore })
|
|
15
|
-
.on('error', err => reject(err))
|
|
16
|
-
.pipe(stream)
|
|
17
|
-
|
|
18
|
-
stream.on('close', () => resolve())
|
|
19
|
-
archive.finalize()
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default zipDirectory
|
package/src/utils/EJSUtils.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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'
|
|
8
|
-
|
|
9
|
-
export class EJSUtils {
|
|
10
|
-
static async renderToFile(templateFile: string, outputFile: string, parser: BuiltInParserName, renderOptions: Data) {
|
|
11
|
-
const defineTemplatePath = path.join(dirname(import.meta), '../template', templateFile)
|
|
12
|
-
const defineTemplate = fs.readFileSync(defineTemplatePath, 'utf8')
|
|
13
|
-
// Format the EJS code using Prettier
|
|
14
|
-
const code = ejs.render(defineTemplate, renderOptions)
|
|
15
|
-
const formattedEJSCode = await PrettierUtils.format(code, parser)
|
|
16
|
-
fs.writeFileSync(outputFile, formattedEJSCode)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { BuiltInParserName } from 'prettier'
|
|
2
|
-
import { format } from 'prettier'
|
|
3
|
-
|
|
4
|
-
export class PrettierUtils {
|
|
5
|
-
static async format(code: string, parser: BuiltInParserName) {
|
|
6
|
-
return format(code, {
|
|
7
|
-
parser,
|
|
8
|
-
tabWidth: 2,
|
|
9
|
-
singleQuote: true,
|
|
10
|
-
})
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import fs from 'node:fs'
|
|
3
|
-
import type { WidgetPackage } from '@widget-js/core'
|
|
4
|
-
|
|
5
|
-
export class WidgetPackageUtils {
|
|
6
|
-
static getRootDir(widgetPackage: WidgetPackage) {
|
|
7
|
-
const widgetRootDir = path.join(process.cwd(), widgetPackage.devOptions?.folder ?? './src/widgets')
|
|
8
|
-
if (!fs.existsSync(widgetRootDir)) {
|
|
9
|
-
fs.mkdirSync(widgetRootDir, { recursive: true })
|
|
10
|
-
}
|
|
11
|
-
return widgetRootDir
|
|
12
|
-
}
|
|
13
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
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
|
-
|
|
6
|
-
export const widgetPackages: { [key: string]: string } = {
|
|
7
|
-
'@widget-js/core': '',
|
|
8
|
-
'@widget-js/vue3': '',
|
|
9
|
-
'@widget-js/cli': '',
|
|
10
|
-
'@widget-js/utils': '',
|
|
11
|
-
'@widget-js/vite-plugin-widget': '',
|
|
12
|
-
}
|
|
13
|
-
export default function exit(code: number = 0) {
|
|
14
|
-
if (exports.exitProcess) {
|
|
15
|
-
process.exit(code)
|
|
16
|
-
}
|
|
17
|
-
else if (code > 0) {
|
|
18
|
-
throw new Error(`Process exited with code ${code}`)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function getPackagePath() {
|
|
23
|
-
return path.join(process.cwd(), 'package.json')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export class Utils {
|
|
27
|
-
static async getRemoteVersion(packageName: string): Promise<string> {
|
|
28
|
-
const metadata = await packageJson(packageName)
|
|
29
|
-
const version = metadata.version
|
|
30
|
-
return version as string
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static getPackagePath() {
|
|
34
|
-
return path.join(process.cwd(), 'package.json')
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
static getPackageJson() {
|
|
38
|
-
return JSON.parse(fs.readFileSync(this.getPackagePath()).toString())
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static getPackageVersion() {
|
|
42
|
-
return this.getPackageJson().version
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 检查包名是否合法,包名格式一般为 倒置域名与java包类似
|
|
47
|
-
* 1.只能包含小写字母、数字、下划线、小数点。
|
|
48
|
-
* 2.不能以小数点结尾
|
|
49
|
-
* 3.不能包含连续的小数点
|
|
50
|
-
* @param name
|
|
51
|
-
*/
|
|
52
|
-
static checkPackageName(name: string): boolean {
|
|
53
|
-
// 检查包名是否以小数点结尾
|
|
54
|
-
if (name.endsWith('.')) {
|
|
55
|
-
return false
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// 检查包名是否包含无效字符
|
|
59
|
-
const invalidCharacters = /[\\/:*?\"<>| ]/g
|
|
60
|
-
if (name.match(invalidCharacters)) {
|
|
61
|
-
return false
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 检查包名是否至少包含一个子段
|
|
65
|
-
const segments = name.split('.')
|
|
66
|
-
if (segments.length < 2) {
|
|
67
|
-
return false
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// 检查每个子段是否以字母开头
|
|
71
|
-
for (const segment of segments) {
|
|
72
|
-
if (!segment.match(/^[a-z]/)) {
|
|
73
|
-
return false
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// 检查子段是否包含连续的小数点
|
|
77
|
-
if (segment.includes('.' + '.')) {
|
|
78
|
-
return false
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return true
|
|
83
|
-
}
|
|
84
|
-
}
|