@widget-js/cli 1.0.13 → 1.0.14
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/index.cjs +31 -11
- package/lib/index.js +31 -11
- package/package.json +1 -1
- package/release.json +7 -14
- package/src/index.ts +0 -1
- package/src/release/{ftp/ftp.ts → ftp.ts} +34 -10
- package/src/release/release.ts +1 -1
package/lib/index.cjs
CHANGED
|
@@ -294,7 +294,7 @@ async function copy(dist, src) {
|
|
|
294
294
|
// src/release/release.ts
|
|
295
295
|
var import_chalk3 = __toESM(require("chalk"), 1);
|
|
296
296
|
|
|
297
|
-
// src/release/ftp
|
|
297
|
+
// src/release/ftp.ts
|
|
298
298
|
var import_path2 = __toESM(require("path"), 1);
|
|
299
299
|
var import_fs4 = __toESM(require("fs"), 1);
|
|
300
300
|
var import_ssh_config = __toESM(require("@widget-js/ssh-config"), 1);
|
|
@@ -305,6 +305,14 @@ var import_inquirer3 = __toESM(require("inquirer"), 1);
|
|
|
305
305
|
var import_ora = __toESM(require("ora"), 1);
|
|
306
306
|
var process2 = __toESM(require("process"), 1);
|
|
307
307
|
var console2 = __toESM(require("console"), 1);
|
|
308
|
+
async function checkParentDir(ftpClient, file, onMkdir) {
|
|
309
|
+
let dir = import_path2.default.dirname(file);
|
|
310
|
+
const dirExists = await ftpClient.exists(dir);
|
|
311
|
+
if (!dirExists) {
|
|
312
|
+
onMkdir(dir);
|
|
313
|
+
await ftpClient.mkdir(dir, true);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
308
316
|
function ftpUpload() {
|
|
309
317
|
const file = import_path2.default.join(process2.cwd(), "release.json");
|
|
310
318
|
const releaseConfig = JSON.parse(import_fs4.default.readFileSync(file).toString());
|
|
@@ -331,19 +339,31 @@ function ftpUpload() {
|
|
|
331
339
|
passphrase: answer.password,
|
|
332
340
|
privateKey: key
|
|
333
341
|
});
|
|
342
|
+
releaseConfig.fileMap.sort((it1, it2) => it1.order - it2.order);
|
|
334
343
|
for (let item of releaseConfig.fileMap) {
|
|
335
344
|
if (typeof item.src == "string") {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
|
|
343
|
-
await ftpClient.uploadDir(localFile, item.dest);
|
|
345
|
+
if (item.remoteCopy) {
|
|
346
|
+
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
347
|
+
spinner.warn(`Create Dir: ${dir}`);
|
|
348
|
+
});
|
|
349
|
+
spinner.info(`Copying File: ${item.src} -> ${item.dest}`);
|
|
350
|
+
await ftpClient.rcopy(item.src, item.dest);
|
|
344
351
|
} else {
|
|
345
|
-
|
|
346
|
-
|
|
352
|
+
const localFile = import_path2.default.resolve(process2.cwd(), item.src);
|
|
353
|
+
if (!item.remoteCopy && !import_fs4.default.existsSync(localFile)) {
|
|
354
|
+
spinner.warn(`Skip not exists file:${localFile}`);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (import_fs4.default.lstatSync(localFile).isDirectory()) {
|
|
358
|
+
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
|
|
359
|
+
await ftpClient.uploadDir(localFile, item.dest);
|
|
360
|
+
} else {
|
|
361
|
+
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
362
|
+
spinner.warn(`Create Dir: ${dir}`);
|
|
363
|
+
});
|
|
364
|
+
spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
|
|
365
|
+
await ftpClient.put(localFile, item.dest);
|
|
366
|
+
}
|
|
347
367
|
}
|
|
348
368
|
} else {
|
|
349
369
|
await ftpClient.put(Buffer.from(JSON.stringify(item.src), "utf-8"), item.dest);
|
package/lib/index.js
CHANGED
|
@@ -273,7 +273,7 @@ async function copy(dist, src) {
|
|
|
273
273
|
// src/release/release.ts
|
|
274
274
|
import chalk3 from "chalk";
|
|
275
275
|
|
|
276
|
-
// src/release/ftp
|
|
276
|
+
// src/release/ftp.ts
|
|
277
277
|
import path2 from "path";
|
|
278
278
|
import fs4 from "fs";
|
|
279
279
|
import SSHConfig from "@widget-js/ssh-config";
|
|
@@ -284,6 +284,14 @@ import inquirer3 from "inquirer";
|
|
|
284
284
|
import ora from "ora";
|
|
285
285
|
import * as process2 from "process";
|
|
286
286
|
import * as console2 from "console";
|
|
287
|
+
async function checkParentDir(ftpClient, file, onMkdir) {
|
|
288
|
+
let dir = path2.dirname(file);
|
|
289
|
+
const dirExists = await ftpClient.exists(dir);
|
|
290
|
+
if (!dirExists) {
|
|
291
|
+
onMkdir(dir);
|
|
292
|
+
await ftpClient.mkdir(dir, true);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
287
295
|
function ftpUpload() {
|
|
288
296
|
const file = path2.join(process2.cwd(), "release.json");
|
|
289
297
|
const releaseConfig = JSON.parse(fs4.readFileSync(file).toString());
|
|
@@ -310,19 +318,31 @@ function ftpUpload() {
|
|
|
310
318
|
passphrase: answer.password,
|
|
311
319
|
privateKey: key
|
|
312
320
|
});
|
|
321
|
+
releaseConfig.fileMap.sort((it1, it2) => it1.order - it2.order);
|
|
313
322
|
for (let item of releaseConfig.fileMap) {
|
|
314
323
|
if (typeof item.src == "string") {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
|
|
322
|
-
await ftpClient.uploadDir(localFile, item.dest);
|
|
324
|
+
if (item.remoteCopy) {
|
|
325
|
+
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
326
|
+
spinner.warn(`Create Dir: ${dir}`);
|
|
327
|
+
});
|
|
328
|
+
spinner.info(`Copying File: ${item.src} -> ${item.dest}`);
|
|
329
|
+
await ftpClient.rcopy(item.src, item.dest);
|
|
323
330
|
} else {
|
|
324
|
-
|
|
325
|
-
|
|
331
|
+
const localFile = path2.resolve(process2.cwd(), item.src);
|
|
332
|
+
if (!item.remoteCopy && !fs4.existsSync(localFile)) {
|
|
333
|
+
spinner.warn(`Skip not exists file:${localFile}`);
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (fs4.lstatSync(localFile).isDirectory()) {
|
|
337
|
+
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
|
|
338
|
+
await ftpClient.uploadDir(localFile, item.dest);
|
|
339
|
+
} else {
|
|
340
|
+
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
341
|
+
spinner.warn(`Create Dir: ${dir}`);
|
|
342
|
+
});
|
|
343
|
+
spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
|
|
344
|
+
await ftpClient.put(localFile, item.dest);
|
|
345
|
+
}
|
|
326
346
|
}
|
|
327
347
|
} else {
|
|
328
348
|
await ftpClient.put(Buffer.from(JSON.stringify(item.src), "utf-8"), item.dest);
|
package/package.json
CHANGED
package/release.json
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"fileMap": [
|
|
3
3
|
{
|
|
4
|
-
"src": "
|
|
5
|
-
"dest": "/www/wwwroot/template/"
|
|
6
|
-
|
|
7
|
-
{
|
|
8
|
-
"src": {
|
|
9
|
-
"version": "0.1.0",
|
|
10
|
-
"createdAt": "",
|
|
11
|
-
"releaseNote": "1.增加版本更新",
|
|
12
|
-
"downloadLink": "https://download.tool-vip.com/youlu/update.zip",
|
|
13
|
-
"updateElectron": false
|
|
14
|
-
},
|
|
15
|
-
"dest": "/www/wwwroot/template/version.json"
|
|
4
|
+
"src": ".gitignore",
|
|
5
|
+
"dest": "/www/wwwroot/template/aa/.gitignore",
|
|
6
|
+
"order": 0
|
|
16
7
|
},
|
|
17
8
|
{
|
|
18
|
-
"src": "
|
|
19
|
-
"dest": "/www/wwwroot/template/.
|
|
9
|
+
"src": "/www/wwwroot/template/aa/.gitignore",
|
|
10
|
+
"dest": "/www/wwwroot/template/bbb/.gitignorexxx",
|
|
11
|
+
"remoteCopy": true,
|
|
12
|
+
"order": 1
|
|
20
13
|
}
|
|
21
14
|
],
|
|
22
15
|
"ftpConfig": {
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,6 @@ import release from './release/release'
|
|
|
8
8
|
import {fileURLToPath} from 'url'
|
|
9
9
|
import figlet from 'figlet'
|
|
10
10
|
import gradient from 'gradient-string'
|
|
11
|
-
import {ftpUpload} from './release/ftp/ftp'
|
|
12
11
|
|
|
13
12
|
const __filename = fileURLToPath(import.meta.url)
|
|
14
13
|
const __dirname = path.dirname(__filename)
|
|
@@ -12,6 +12,16 @@ import * as console from 'console'
|
|
|
12
12
|
interface PasswordAnswer {
|
|
13
13
|
password: string
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
async function checkParentDir(ftpClient: Client, file: string, onMkdir: (dir: string) => void) {
|
|
17
|
+
let dir = path.dirname(file)
|
|
18
|
+
const dirExists = await ftpClient.exists(dir)
|
|
19
|
+
if (!dirExists) {
|
|
20
|
+
onMkdir(dir)
|
|
21
|
+
await ftpClient.mkdir(dir, true)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
15
25
|
export function ftpUpload() {
|
|
16
26
|
// 读取
|
|
17
27
|
const file = path.join(process.cwd(), 'release.json')
|
|
@@ -41,20 +51,32 @@ export function ftpUpload() {
|
|
|
41
51
|
passphrase: answer.password,
|
|
42
52
|
privateKey: key,
|
|
43
53
|
})
|
|
54
|
+
releaseConfig.fileMap.sort((it1, it2) => it1.order - it2.order)
|
|
44
55
|
// upload files
|
|
45
56
|
for (let item of releaseConfig.fileMap) {
|
|
46
57
|
if (typeof item.src == 'string') {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`)
|
|
54
|
-
await ftpClient.uploadDir(localFile, item.dest)
|
|
58
|
+
if (item.remoteCopy) {
|
|
59
|
+
await checkParentDir(ftpClient, item.dest, dir => {
|
|
60
|
+
spinner.warn(`Create Dir: ${dir}`)
|
|
61
|
+
})
|
|
62
|
+
spinner.info(`Copying File: ${item.src} -> ${item.dest}`)
|
|
63
|
+
await ftpClient.rcopy(item.src, item.dest)
|
|
55
64
|
} else {
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
const localFile = path.resolve(process.cwd(), item.src as string)
|
|
66
|
+
if (!item.remoteCopy && !fs.existsSync(localFile)) {
|
|
67
|
+
spinner.warn(`Skip not exists file:${localFile}`)
|
|
68
|
+
continue
|
|
69
|
+
}
|
|
70
|
+
if (fs.lstatSync(localFile).isDirectory()) {
|
|
71
|
+
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`)
|
|
72
|
+
await ftpClient.uploadDir(localFile, item.dest)
|
|
73
|
+
} else {
|
|
74
|
+
await checkParentDir(ftpClient, item.dest, dir => {
|
|
75
|
+
spinner.warn(`Create Dir: ${dir}`)
|
|
76
|
+
})
|
|
77
|
+
spinner.info(`Uploading File: ${localFile} -> ${item.dest}`)
|
|
78
|
+
await ftpClient.put(localFile, item.dest)
|
|
79
|
+
}
|
|
58
80
|
}
|
|
59
81
|
} else {
|
|
60
82
|
await ftpClient.put(Buffer.from(JSON.stringify(item.src), 'utf-8'), item.dest)
|
|
@@ -73,6 +95,8 @@ export interface ReleaseConfig {
|
|
|
73
95
|
fileMap: {
|
|
74
96
|
src: string | object
|
|
75
97
|
dest: string
|
|
98
|
+
remoteCopy: boolean
|
|
99
|
+
order: number
|
|
76
100
|
}[]
|
|
77
101
|
ftpConfig: FTPConfig
|
|
78
102
|
}
|
package/src/release/release.ts
CHANGED
|
@@ -4,7 +4,7 @@ import promptChecker from '../promts/promptChecker.js'
|
|
|
4
4
|
import zipDirectory from './update-zip.js'
|
|
5
5
|
import {copy, put} from './oss.js'
|
|
6
6
|
import chalk from 'chalk'
|
|
7
|
-
import {ftpUpload} from './ftp
|
|
7
|
+
import {ftpUpload} from './ftp'
|
|
8
8
|
|
|
9
9
|
async function delay(time: number) {
|
|
10
10
|
return new Promise<void>((resolve, reject) => {
|