@widget-js/cli 1.0.13 → 1.0.15

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 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/ftp.ts
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,36 @@ function ftpUpload() {
331
339
  passphrase: answer.password,
332
340
  privateKey: key
333
341
  });
342
+ releaseConfig.fileMap.sort((it1, it2) => (it1.order ?? 0) - (it2.order ?? 0));
334
343
  for (let item of releaseConfig.fileMap) {
335
344
  if (typeof item.src == "string") {
336
- const localFile = import_path2.default.resolve(process2.cwd(), item.src);
337
- if (!import_fs4.default.existsSync(localFile)) {
338
- spinner.warn(`Skip not exists file:${localFile}`);
339
- continue;
340
- }
341
- if (import_fs4.default.lstatSync(localFile).isDirectory()) {
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
+ let destExists = await ftpClient.exists(item.dest);
350
+ if (destExists) {
351
+ spinner.warn(`Delete exists file:${item.dest}`);
352
+ await ftpClient.delete(item.dest);
353
+ }
354
+ spinner.info(`Copying File: ${item.src} -> ${item.dest}`);
355
+ await ftpClient.rcopy(item.src, item.dest);
344
356
  } else {
345
- spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
346
- await ftpClient.put(localFile, item.dest);
357
+ const localFile = import_path2.default.resolve(process2.cwd(), item.src);
358
+ if (!item.remoteCopy && !import_fs4.default.existsSync(localFile)) {
359
+ spinner.warn(`Skip not exists file:${localFile}`);
360
+ continue;
361
+ }
362
+ if (import_fs4.default.lstatSync(localFile).isDirectory()) {
363
+ spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
364
+ await ftpClient.uploadDir(localFile, item.dest);
365
+ } else {
366
+ await checkParentDir(ftpClient, item.dest, (dir) => {
367
+ spinner.warn(`Create Dir: ${dir}`);
368
+ });
369
+ spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
370
+ await ftpClient.put(localFile, item.dest);
371
+ }
347
372
  }
348
373
  } else {
349
374
  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/ftp.ts
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,36 @@ function ftpUpload() {
310
318
  passphrase: answer.password,
311
319
  privateKey: key
312
320
  });
321
+ releaseConfig.fileMap.sort((it1, it2) => (it1.order ?? 0) - (it2.order ?? 0));
313
322
  for (let item of releaseConfig.fileMap) {
314
323
  if (typeof item.src == "string") {
315
- const localFile = path2.resolve(process2.cwd(), item.src);
316
- if (!fs4.existsSync(localFile)) {
317
- spinner.warn(`Skip not exists file:${localFile}`);
318
- continue;
319
- }
320
- if (fs4.lstatSync(localFile).isDirectory()) {
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
+ let destExists = await ftpClient.exists(item.dest);
329
+ if (destExists) {
330
+ spinner.warn(`Delete exists file:${item.dest}`);
331
+ await ftpClient.delete(item.dest);
332
+ }
333
+ spinner.info(`Copying File: ${item.src} -> ${item.dest}`);
334
+ await ftpClient.rcopy(item.src, item.dest);
323
335
  } else {
324
- spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
325
- await ftpClient.put(localFile, item.dest);
336
+ const localFile = path2.resolve(process2.cwd(), item.src);
337
+ if (!item.remoteCopy && !fs4.existsSync(localFile)) {
338
+ spinner.warn(`Skip not exists file:${localFile}`);
339
+ continue;
340
+ }
341
+ if (fs4.lstatSync(localFile).isDirectory()) {
342
+ spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
343
+ await ftpClient.uploadDir(localFile, item.dest);
344
+ } else {
345
+ await checkParentDir(ftpClient, item.dest, (dir) => {
346
+ spinner.warn(`Create Dir: ${dir}`);
347
+ });
348
+ spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
349
+ await ftpClient.put(localFile, item.dest);
350
+ }
326
351
  }
327
352
  } else {
328
353
  await ftpClient.put(Buffer.from(JSON.stringify(item.src), "utf-8"), item.dest);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widget-js/cli",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "main": "lib/index.js",
5
5
  "author": "Neo Fu",
6
6
  "license": "MIT",
package/release.json CHANGED
@@ -1,22 +1,13 @@
1
1
  {
2
2
  "fileMap": [
3
3
  {
4
- "src": "./template",
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"
16
6
  },
17
7
  {
18
- "src": ".gitignore",
19
- "dest": "/www/wwwroot/template/.gitignore"
8
+ "src": "/www/wwwroot/template/aa/.gitignore",
9
+ "dest": "/www/wwwroot/template/bbb/.gitignorexxx",
10
+ "remoteCopy": true
20
11
  }
21
12
  ],
22
13
  "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,37 @@ export function ftpUpload() {
41
51
  passphrase: answer.password,
42
52
  privateKey: key,
43
53
  })
54
+ releaseConfig.fileMap.sort((it1, it2) => (it1.order ?? 0) - (it2.order ?? 0))
44
55
  // upload files
45
56
  for (let item of releaseConfig.fileMap) {
46
57
  if (typeof item.src == 'string') {
47
- const localFile = path.resolve(process.cwd(), item.src as string)
48
- if (!fs.existsSync(localFile)) {
49
- spinner.warn(`Skip not exists file:${localFile}`)
50
- continue
51
- }
52
- if (fs.lstatSync(localFile).isDirectory()) {
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
+ let destExists = await ftpClient.exists(item.dest)
63
+ if (destExists) {
64
+ spinner.warn(`Delete exists file:${item.dest}`)
65
+ await ftpClient.delete(item.dest)
66
+ }
67
+ spinner.info(`Copying File: ${item.src} -> ${item.dest}`)
68
+ await ftpClient.rcopy(item.src, item.dest)
55
69
  } else {
56
- spinner.info(`Uploading File: ${localFile} -> ${item.dest}`)
57
- await ftpClient.put(localFile, item.dest)
70
+ const localFile = path.resolve(process.cwd(), item.src as string)
71
+ if (!item.remoteCopy && !fs.existsSync(localFile)) {
72
+ spinner.warn(`Skip not exists file:${localFile}`)
73
+ continue
74
+ }
75
+ if (fs.lstatSync(localFile).isDirectory()) {
76
+ spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`)
77
+ await ftpClient.uploadDir(localFile, item.dest)
78
+ } else {
79
+ await checkParentDir(ftpClient, item.dest, dir => {
80
+ spinner.warn(`Create Dir: ${dir}`)
81
+ })
82
+ spinner.info(`Uploading File: ${localFile} -> ${item.dest}`)
83
+ await ftpClient.put(localFile, item.dest)
84
+ }
58
85
  }
59
86
  } else {
60
87
  await ftpClient.put(Buffer.from(JSON.stringify(item.src), 'utf-8'), item.dest)
@@ -73,6 +100,8 @@ export interface ReleaseConfig {
73
100
  fileMap: {
74
101
  src: string | object
75
102
  dest: string
103
+ remoteCopy: boolean
104
+ order: number
76
105
  }[]
77
106
  ftpConfig: FTPConfig
78
107
  }
@@ -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/ftp'
7
+ import {ftpUpload} from './ftp'
8
8
 
9
9
  async function delay(time: number) {
10
10
  return new Promise<void>((resolve, reject) => {