@widget-js/cli 1.0.14 → 1.0.16

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.
@@ -0,0 +1,35 @@
1
+ import ora from 'ora'
2
+ import {exec} from 'child_process'
3
+ import consola from 'consola'
4
+
5
+ export function build() {
6
+ const preloadSpinner = ora('Preload').start()
7
+ const mainSpinner = ora('Main').start()
8
+ //@ts-ignore
9
+ const build = exec('npm run build:preload').on('close', () => {
10
+ consola.success('done')
11
+ })
12
+ //@ts-ignore
13
+ build.stdout.on('data', data => {
14
+ consola.log('data', data)
15
+ })
16
+
17
+ //@ts-ignore
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/index.ts CHANGED
@@ -2,8 +2,6 @@ import {Option, program} from 'commander'
2
2
  import fs from 'fs'
3
3
  import path from 'path'
4
4
  import * as process from 'process'
5
- import createWidget from './createWidget'
6
- import release from './release/release'
7
5
 
8
6
  import {fileURLToPath} from 'url'
9
7
  import figlet from 'figlet'
@@ -21,7 +19,16 @@ program
21
19
  .command('create')
22
20
  .description('创建新的组件')
23
21
  .action(async () => {
24
- await createWidget()
22
+ const createWidget = await import('./createWidget')
23
+ await createWidget.default()
24
+ })
25
+
26
+ program
27
+ .command('build')
28
+ .description('执行编译任务')
29
+ .action(async () => {
30
+ const build = await import('./build/build')
31
+ await build.build()
25
32
  })
26
33
 
27
34
  let typeOption = new Option('-t, --type <type>').choices(['ftp', 'oss'])
@@ -31,8 +38,8 @@ program
31
38
  .addOption(typeOption)
32
39
  .action(async (options, command) => {
33
40
  // @ts-ignore
34
- console.log(options)
35
- await release(options)
41
+ let release = await import('./release/release');
42
+ await release.default(options)
36
43
  })
37
44
 
38
45
  //TODO init 初始化项目
@@ -8,6 +8,8 @@ import inquirer from 'inquirer'
8
8
  import ora from 'ora'
9
9
  import * as process from 'process'
10
10
  import * as console from 'console'
11
+ import {getPackageVersion} from "../utils";
12
+
11
13
 
12
14
  interface PasswordAnswer {
13
15
  password: string
@@ -24,10 +26,14 @@ async function checkParentDir(ftpClient: Client, file: string, onMkdir: (dir: st
24
26
 
25
27
  export function ftpUpload() {
26
28
  // 读取
27
- const file = path.join(process.cwd(), 'release.json')
28
- const releaseConfig = JSON.parse(fs.readFileSync(file).toString()) as ReleaseConfig
29
+ const releaseJsonFilePath = path.join(process.cwd(), 'release.json')
30
+ const packageVersion = getPackageVersion()
31
+ consola.info('Package Version:', packageVersion)
32
+
33
+ let releaseJson = fs.readFileSync(releaseJsonFilePath).toString().replaceAll('${version}', packageVersion);
34
+ const releaseConfig = JSON.parse(releaseJson) as ReleaseConfig
29
35
  const sshConfigFile = path.resolve(os.homedir(), '.ssh/config')
30
- console.log('SSH Config file:', sshConfigFile)
36
+ consola.info('SSH Config File Path:', sshConfigFile)
31
37
  const sshConfigs = SSHConfig.parse(fs.readFileSync(sshConfigFile).toString())
32
38
  let sshConfig = sshConfigs.compute(releaseConfig.ftpConfig.host)
33
39
  if (!sshConfig) {
@@ -51,7 +57,7 @@ export function ftpUpload() {
51
57
  passphrase: answer.password,
52
58
  privateKey: key,
53
59
  })
54
- releaseConfig.fileMap.sort((it1, it2) => it1.order - it2.order)
60
+ releaseConfig.fileMap.sort((it1, it2) => (it1.order ?? 0) - (it2.order ?? 0))
55
61
  // upload files
56
62
  for (let item of releaseConfig.fileMap) {
57
63
  if (typeof item.src == 'string') {
@@ -59,6 +65,11 @@ export function ftpUpload() {
59
65
  await checkParentDir(ftpClient, item.dest, dir => {
60
66
  spinner.warn(`Create Dir: ${dir}`)
61
67
  })
68
+ let destExists = await ftpClient.exists(item.dest)
69
+ if (destExists) {
70
+ spinner.warn(`Delete exists file:${item.dest}`)
71
+ await ftpClient.delete(item.dest)
72
+ }
62
73
  spinner.info(`Copying File: ${item.src} -> ${item.dest}`)
63
74
  await ftpClient.rcopy(item.src, item.dest)
64
75
  } else {
package/src/utils.ts CHANGED
@@ -1,7 +1,16 @@
1
- export default function exit(code:number = 0) {
2
- if (exports.exitProcess) {
3
- process.exit(code)
4
- } else if (code > 0) {
5
- throw new Error(`Process exited with code ${code}`)
6
- }
1
+ import path from "path";
2
+ import process from "process";
3
+ import fs from "fs";
4
+
5
+ export default function exit(code: number = 0) {
6
+ if (exports.exitProcess) {
7
+ process.exit(code)
8
+ } else if (code > 0) {
9
+ throw new Error(`Process exited with code ${code}`)
10
+ }
11
+ }
12
+
13
+ export function getPackageVersion() {
14
+ const packagePath = path.join(process.cwd(), 'package.json')
15
+ return JSON.parse(fs.readFileSync(packagePath).toString())['version']
7
16
  }