add base url list
This commit is contained in:
		| @@ -43,10 +43,16 @@ const command = new Command('deploy') | ||||
|       // 获取directory,如果是文件夹,获取文件夹下所有文件,如果是文件,获取文件 | ||||
|       const stat = fs.statSync(directory); | ||||
|       let _relativeFiles = []; | ||||
|       let isDirectory = false; | ||||
|       if (stat.isDirectory()) { | ||||
|         isDirectory = true; | ||||
|         const gPath = path.join(directory, '**/*'); | ||||
|         const files = await glob(gPath, { cwd: pwd, ignore: ['node_modules/**/*'], onlyFiles: true }); | ||||
|         _relativeFiles = files.map((file) => path.relative(directory, file)); | ||||
|       } else if (stat.isFile()) { | ||||
|         const filename = path.basename(directory); | ||||
|         _relativeFiles = [filename]; | ||||
|       } | ||||
|       console.log('upload Files', _relativeFiles); | ||||
|       console.log('upload Files Key', key, version); | ||||
|       if (!yes) { | ||||
| @@ -62,11 +68,8 @@ const command = new Command('deploy') | ||||
|           return; | ||||
|         } | ||||
|       } | ||||
|       } else if (stat.isFile()) { | ||||
|         _relativeFiles = [path.relative(pwd, directory)]; | ||||
|       } | ||||
|  | ||||
|       const res = await uploadFiles(_relativeFiles, directory, { key, version }); | ||||
|       const uploadDirectory = isDirectory ? directory : path.dirname(directory); | ||||
|       const res = await uploadFiles(_relativeFiles, uploadDirectory, { key, version }); | ||||
|       if (res?.code === 200) { | ||||
|         console.log('File uploaded successfully!'); | ||||
|         res.data?.data?.files?.map?.((d) => { | ||||
|   | ||||
| @@ -9,9 +9,69 @@ const token = new Command('token').description('show token').action(async () => | ||||
|  | ||||
| app.addCommand(token); | ||||
|  | ||||
| const baseURL = new Command('baseURL').description('show baseURL').action(async () => { | ||||
| const baseURL = new Command('baseURL') | ||||
|   .alias('base') | ||||
|   .description('show baseURL') | ||||
|   .option('-a, --add <baseURL>', 'add baseURL') | ||||
|   .option('-r, --remove <number>', 'remove baseURL number') | ||||
|   .option('-s, --set <number>', 'set current baseURL') | ||||
|   .option('-l, --list', 'list baseURL') | ||||
|   .option('-c, --clear', 'clear baseURL') | ||||
|   .action(async (opts) => { | ||||
|     const config = getConfig(); | ||||
|   console.log('baseURL', config.baseURL); | ||||
|     let list = config.baseURLList || []; | ||||
|     const quineList = (list: string[]) => { | ||||
|       const newList = new Set(list); | ||||
|       return Array.from(newList); | ||||
|     }; | ||||
|     const showList = (list: string[]) => { | ||||
|       if (list.length === 0) { | ||||
|         console.log('expand baseURLList is empty'); | ||||
|         return; | ||||
|       } | ||||
|       console.log('----current baseURL:' + config.baseURL+'----\n'); | ||||
|       list.forEach((item, index) => { | ||||
|         console.log(`${index + 1}: ${item}`); | ||||
|       }); | ||||
|     }; | ||||
|     if (opts.add) { | ||||
|       list.push(opts.add); | ||||
|       list = quineList(list); | ||||
|       console.log('add baseURL success\n'); | ||||
|       writeConfig({ ...config, baseURLList: list }); | ||||
|       showList(list); | ||||
|       return; | ||||
|     } | ||||
|     if (opts.remove) { | ||||
|       const index = Number(opts.remove) - 1; | ||||
|       if (index < 0 || index >= list.length) { | ||||
|         console.log('index out of range'); | ||||
|         return; | ||||
|       } | ||||
|       list.splice(index, 1); | ||||
|       list = quineList(list); | ||||
|       showList(list); | ||||
|       writeConfig({ ...config, baseURLList: list }); | ||||
|       return; | ||||
|     } | ||||
|     if (opts.set) { | ||||
|       const index = Number(opts.set) - 1; | ||||
|       if (index < 0 || index >= list.length) { | ||||
|         console.log('index out of range'); | ||||
|       } | ||||
|       writeConfig({ ...config, baseURL: list[index] }); | ||||
|       console.log('set baseURL success:', list[index]); | ||||
|       return; | ||||
|     } | ||||
|     if (opts.list) { | ||||
|       showList(list); | ||||
|       return; | ||||
|     } | ||||
|     if (opts.clear) { | ||||
|       writeConfig({ ...config, baseURLList: [] }); | ||||
|       return; | ||||
|     } | ||||
|     console.log('current baseURL:', config.baseURL); | ||||
|   }); | ||||
| app.addCommand(baseURL); | ||||
|  | ||||
|   | ||||
| @@ -36,7 +36,7 @@ async function collectFileInfo(filePath: string, baseDir = '.'): Promise<any[]> | ||||
| // 解析 .npmignore 文件 | ||||
| async function loadNpmIgnore(cwd: string): Promise<ignore.Ignore> { | ||||
|   const npmIgnorePath = path.join(cwd, '.npmignore'); | ||||
|   const ig = ignore.default(); | ||||
|   const ig = ignore(); | ||||
|  | ||||
|   try { | ||||
|     const content = fs.readFileSync(npmIgnorePath, 'utf-8'); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user