@widget-js/cli 1.1.11 → 1.2.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/.idea/codeStyles/Project.xml +64 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/misc.xml +0 -3
- package/lib/index.js +1 -1
- package/lib/{release-HXCPKDIN.js → release-VEU3T5KK.js} +17 -3
- package/package.json +8 -7
- package/release.json +3 -1
- package/src/release/ftp.ts +140 -123
- package/test/index.test.ts +9 -0
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jpa-buddy.xml +0 -6
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<component name="ProjectCodeStyleConfiguration">
|
|
2
|
+
<code_scheme name="Project" version="173">
|
|
3
|
+
<HTMLCodeStyleSettings>
|
|
4
|
+
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
|
5
|
+
<option name="HTML_ENFORCE_QUOTES" value="true" />
|
|
6
|
+
</HTMLCodeStyleSettings>
|
|
7
|
+
<JSCodeStyleSettings version="0">
|
|
8
|
+
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
9
|
+
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
10
|
+
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
11
|
+
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
|
12
|
+
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
13
|
+
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
14
|
+
</JSCodeStyleSettings>
|
|
15
|
+
<JetCodeStyleSettings>
|
|
16
|
+
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
|
17
|
+
</JetCodeStyleSettings>
|
|
18
|
+
<TypeScriptCodeStyleSettings version="0">
|
|
19
|
+
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
20
|
+
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
21
|
+
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
22
|
+
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
|
23
|
+
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
24
|
+
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
25
|
+
</TypeScriptCodeStyleSettings>
|
|
26
|
+
<VueCodeStyleSettings>
|
|
27
|
+
<option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
|
|
28
|
+
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
|
|
29
|
+
</VueCodeStyleSettings>
|
|
30
|
+
<codeStyleSettings language="HTML">
|
|
31
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
32
|
+
<indentOptions>
|
|
33
|
+
<option name="INDENT_SIZE" value="2" />
|
|
34
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
35
|
+
<option name="TAB_SIZE" value="2" />
|
|
36
|
+
</indentOptions>
|
|
37
|
+
</codeStyleSettings>
|
|
38
|
+
<codeStyleSettings language="JavaScript">
|
|
39
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
40
|
+
<indentOptions>
|
|
41
|
+
<option name="INDENT_SIZE" value="2" />
|
|
42
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
43
|
+
<option name="TAB_SIZE" value="2" />
|
|
44
|
+
</indentOptions>
|
|
45
|
+
</codeStyleSettings>
|
|
46
|
+
<codeStyleSettings language="TypeScript">
|
|
47
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
48
|
+
<indentOptions>
|
|
49
|
+
<option name="INDENT_SIZE" value="2" />
|
|
50
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
51
|
+
<option name="TAB_SIZE" value="2" />
|
|
52
|
+
</indentOptions>
|
|
53
|
+
</codeStyleSettings>
|
|
54
|
+
<codeStyleSettings language="Vue">
|
|
55
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
56
|
+
<indentOptions>
|
|
57
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
58
|
+
</indentOptions>
|
|
59
|
+
</codeStyleSettings>
|
|
60
|
+
<codeStyleSettings language="kotlin">
|
|
61
|
+
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
|
62
|
+
</codeStyleSettings>
|
|
63
|
+
</code_scheme>
|
|
64
|
+
</component>
|
package/.idea/misc.xml
CHANGED
package/lib/index.js
CHANGED
|
@@ -26,7 +26,7 @@ program.command("init").description("Initialize widget-js project").action(async
|
|
|
26
26
|
var typeOption = new Option("-t, --type <type>").choices(["ftp", "oss"]);
|
|
27
27
|
var fileOption = new Option("-f, --file <file>");
|
|
28
28
|
program.command("release").description("\u901A\u8FC7FTP/OSS\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").addOption(typeOption).addOption(fileOption).action(async (options, command) => {
|
|
29
|
-
let release = await import("./release-
|
|
29
|
+
let release = await import("./release-VEU3T5KK.js");
|
|
30
30
|
await release.default(options);
|
|
31
31
|
});
|
|
32
32
|
program.parse(process.argv);
|
|
@@ -76,6 +76,7 @@ import consola from "consola";
|
|
|
76
76
|
import inquirer from "inquirer";
|
|
77
77
|
import ora from "ora";
|
|
78
78
|
import * as process from "process";
|
|
79
|
+
import { minimatch } from "minimatch";
|
|
79
80
|
async function checkParentDir(ftpClient, file, onMkdir) {
|
|
80
81
|
let dir = path.dirname(file);
|
|
81
82
|
const dirExists = await ftpClient.exists(dir);
|
|
@@ -86,7 +87,9 @@ async function checkParentDir(ftpClient, file, onMkdir) {
|
|
|
86
87
|
}
|
|
87
88
|
async function runSSH(sshConfig, releaseConfig) {
|
|
88
89
|
consola.info("run ssh:", sshConfig);
|
|
89
|
-
const answer = await inquirer.prompt([
|
|
90
|
+
const answer = await inquirer.prompt([
|
|
91
|
+
{ type: "password", name: "password", mask: "*", message: "Enter key pair password" }
|
|
92
|
+
]);
|
|
90
93
|
let ftpClient = new Client();
|
|
91
94
|
const port = sshConfig["Port"];
|
|
92
95
|
const key = fs3.readFileSync(path.resolve(os.homedir(), ".ssh/id_rsa"));
|
|
@@ -122,10 +125,21 @@ async function runSSH(sshConfig, releaseConfig) {
|
|
|
122
125
|
}
|
|
123
126
|
if (fs3.lstatSync(localFile).isDirectory()) {
|
|
124
127
|
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
|
|
125
|
-
await ftpClient.uploadDir(localFile, item.dest
|
|
128
|
+
await ftpClient.uploadDir(localFile, item.dest, {
|
|
129
|
+
filter: (filePath, isDirectory) => {
|
|
130
|
+
if (item.ignorePattern && !isDirectory) {
|
|
131
|
+
let fileName = path.basename(filePath);
|
|
132
|
+
if (minimatch(fileName, item.ignorePattern)) {
|
|
133
|
+
spinner.warn(`Skip file:${filePath}`);
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
126
140
|
} else {
|
|
127
141
|
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
128
|
-
spinner.
|
|
142
|
+
spinner.succeed(`Create Dir: ${dir}`);
|
|
129
143
|
});
|
|
130
144
|
spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
|
|
131
145
|
await ftpClient.put(localFile, item.dest);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widget-js/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"author": "Neo Fu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,11 +31,13 @@
|
|
|
31
31
|
"figlet": "^1.5.2",
|
|
32
32
|
"gradient-string": "^2.0.2",
|
|
33
33
|
"inquirer": "^8.0.0",
|
|
34
|
+
"minimatch": "^9.0.3",
|
|
34
35
|
"ora": "^6.2.0",
|
|
35
36
|
"package-json": "^8.1.0",
|
|
36
37
|
"semver": "^7.3.8",
|
|
38
|
+
"prettier": "^2.8.8",
|
|
37
39
|
"shelljs": "^0.8.5",
|
|
38
|
-
"ssh2-sftp-client": "^9.0
|
|
40
|
+
"ssh2-sftp-client": "^9.1.0",
|
|
39
41
|
"ws": "^8.11.0",
|
|
40
42
|
"@widget-js/utils": "0.7.19"
|
|
41
43
|
},
|
|
@@ -48,25 +50,24 @@
|
|
|
48
50
|
"@types/node": "^18.11.13",
|
|
49
51
|
"@types/semver": "^7.5.0",
|
|
50
52
|
"@types/shelljs": "latest",
|
|
51
|
-
"@types/ssh2-sftp-client": "^9.0.
|
|
53
|
+
"@types/ssh2-sftp-client": "^9.0.1",
|
|
52
54
|
"jest": "^29.5.0",
|
|
53
55
|
"pinst": "^3.0.0",
|
|
54
|
-
"prettier": "^2.8.8",
|
|
55
56
|
"rimraf": "^4.4.1",
|
|
56
57
|
"ts-jest": "^29.0.3",
|
|
57
58
|
"ts-loader": "^9.4.1",
|
|
58
59
|
"ts-node": "^10.9.1",
|
|
59
60
|
"tsup": "^6.5.0",
|
|
60
|
-
"typescript": "^
|
|
61
|
+
"typescript": "^5.2.2",
|
|
62
|
+
"vitest": "^0.34.6",
|
|
61
63
|
"webpack": "^5.75.0",
|
|
62
64
|
"webpack-cli": "^5.0.0",
|
|
63
|
-
"@widget-js/core": "0.
|
|
65
|
+
"@widget-js/core": "0.10.14"
|
|
64
66
|
},
|
|
65
67
|
"scripts": {
|
|
66
68
|
"build": "rimraf ./lib/ && tsup-node src/index.ts --format esm",
|
|
67
69
|
"watch": "tsup src/index.ts --format esm --watch",
|
|
68
70
|
"build:run": "npm run build && npm run widget",
|
|
69
|
-
"prebuild": "",
|
|
70
71
|
"widget": "node ./lib/index.js",
|
|
71
72
|
"widget:ftp": "node ./lib/index.js release -t ftp",
|
|
72
73
|
"widget:init": "node ./lib/index.js init",
|
package/release.json
CHANGED
package/src/release/ftp.ts
CHANGED
|
@@ -1,123 +1,140 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import fs from
|
|
3
|
-
import SSHConfig from
|
|
4
|
-
import os from
|
|
5
|
-
import Client from
|
|
6
|
-
import consola from
|
|
7
|
-
import inquirer from
|
|
8
|
-
import ora from
|
|
9
|
-
import * as process from
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
interface PasswordAnswer {
|
|
14
|
-
password: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function checkParentDir(ftpClient: Client, file: string, onMkdir: (dir: string) => void) {
|
|
18
|
-
let 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
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import SSHConfig from '@widget-js/ssh-config'
|
|
4
|
+
import os from 'os'
|
|
5
|
+
import Client from 'ssh2-sftp-client'
|
|
6
|
+
import consola from 'consola'
|
|
7
|
+
import inquirer from 'inquirer'
|
|
8
|
+
import ora from 'ora'
|
|
9
|
+
import * as process from 'process'
|
|
10
|
+
import {Utils} from '../utils'
|
|
11
|
+
import {minimatch} from 'minimatch'
|
|
12
|
+
|
|
13
|
+
interface PasswordAnswer {
|
|
14
|
+
password: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function checkParentDir(ftpClient: Client, file: string, onMkdir: (dir: string) => void) {
|
|
18
|
+
let 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
|
+
let 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 ? 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 (let 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
|
+
let 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
|
+
} else {
|
|
61
|
+
const localFile = path.resolve(process.cwd(), item.src as string)
|
|
62
|
+
if (!item.remoteCopy && !fs.existsSync(localFile)) {
|
|
63
|
+
spinner.warn(`Skip not exists file:${localFile}`)
|
|
64
|
+
continue
|
|
65
|
+
}
|
|
66
|
+
if (fs.lstatSync(localFile).isDirectory()) {
|
|
67
|
+
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`)
|
|
68
|
+
await ftpClient.uploadDir(localFile, item.dest, {
|
|
69
|
+
filter: (filePath: string, isDirectory: boolean):boolean => {
|
|
70
|
+
if (item.ignorePattern && !isDirectory) {
|
|
71
|
+
let fileName = path.basename(filePath)
|
|
72
|
+
if (minimatch(fileName, item.ignorePattern)) {
|
|
73
|
+
spinner.warn(`Skip file:${filePath}`)
|
|
74
|
+
return false
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
} else {
|
|
81
|
+
await checkParentDir(ftpClient, item.dest, dir => {
|
|
82
|
+
spinner.succeed(`Create Dir: ${dir}`)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
spinner.info(`Uploading File: ${localFile} -> ${item.dest}`)
|
|
86
|
+
await ftpClient.put(localFile, item.dest)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
await ftpClient.put(Buffer.from(JSON.stringify(item.src), 'utf-8'), item.dest)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
spinner.succeed('Files uploaded!')
|
|
94
|
+
await ftpClient.end()
|
|
95
|
+
} catch (e) {
|
|
96
|
+
spinner.fail(`Connection error:${e}`)
|
|
97
|
+
await ftpClient.end()
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function ftpUpload(releaseFile: string = 'release.json') {
|
|
102
|
+
// 读取
|
|
103
|
+
const releaseJsonFilePath = path.join(process.cwd(), releaseFile)
|
|
104
|
+
const packageVersion = Utils.getPackageVersion()
|
|
105
|
+
consola.info('Package Version:', packageVersion)
|
|
106
|
+
|
|
107
|
+
let releaseJson = fs.readFileSync(releaseJsonFilePath).toString().replaceAll('${version}', packageVersion)
|
|
108
|
+
const releaseConfig = JSON.parse(releaseJson) as ReleaseConfig
|
|
109
|
+
const sshConfigFile = path.resolve(os.homedir(), '.ssh/config')
|
|
110
|
+
consola.info('SSH Config File Path:', sshConfigFile)
|
|
111
|
+
const sshConfigs = SSHConfig.parse(fs.readFileSync(sshConfigFile).toString())
|
|
112
|
+
for (let host of releaseConfig.ftpConfig.host) {
|
|
113
|
+
let sshConfig = sshConfigs.compute(host)
|
|
114
|
+
if (!sshConfig) {
|
|
115
|
+
consola.error(`SSH config ${releaseConfig.ftpConfig.host} not found`)
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
await runSSH(sshConfig, releaseConfig)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface FileMapConfig {
|
|
123
|
+
src: string | object
|
|
124
|
+
dest: string
|
|
125
|
+
remoteCopy: boolean
|
|
126
|
+
order: number
|
|
127
|
+
/**
|
|
128
|
+
* 支持glob、正则表达式
|
|
129
|
+
*/
|
|
130
|
+
ignorePattern?: string
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface ReleaseConfig {
|
|
134
|
+
fileMap: FileMapConfig[]
|
|
135
|
+
ftpConfig: FTPConfig
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface FTPConfig {
|
|
139
|
+
host: string[]
|
|
140
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {expect, test} from "vitest";
|
|
2
|
+
import {minimatch} from "minimatch";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
test('minimatch',()=>{
|
|
6
|
+
let 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
|
+
})
|