add base url list
This commit is contained in:
parent
ce84ab4902
commit
5a691bc350
@ -43,10 +43,16 @@ const command = new Command('deploy')
|
|||||||
// 获取directory,如果是文件夹,获取文件夹下所有文件,如果是文件,获取文件
|
// 获取directory,如果是文件夹,获取文件夹下所有文件,如果是文件,获取文件
|
||||||
const stat = fs.statSync(directory);
|
const stat = fs.statSync(directory);
|
||||||
let _relativeFiles = [];
|
let _relativeFiles = [];
|
||||||
|
let isDirectory = false;
|
||||||
if (stat.isDirectory()) {
|
if (stat.isDirectory()) {
|
||||||
|
isDirectory = true;
|
||||||
const gPath = path.join(directory, '**/*');
|
const gPath = path.join(directory, '**/*');
|
||||||
const files = await glob(gPath, { cwd: pwd, ignore: ['node_modules/**/*'], onlyFiles: true });
|
const files = await glob(gPath, { cwd: pwd, ignore: ['node_modules/**/*'], onlyFiles: true });
|
||||||
_relativeFiles = files.map((file) => path.relative(directory, file));
|
_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', _relativeFiles);
|
||||||
console.log('upload Files Key', key, version);
|
console.log('upload Files Key', key, version);
|
||||||
if (!yes) {
|
if (!yes) {
|
||||||
@ -62,11 +68,8 @@ const command = new Command('deploy')
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (stat.isFile()) {
|
const uploadDirectory = isDirectory ? directory : path.dirname(directory);
|
||||||
_relativeFiles = [path.relative(pwd, directory)];
|
const res = await uploadFiles(_relativeFiles, uploadDirectory, { key, version });
|
||||||
}
|
|
||||||
|
|
||||||
const res = await uploadFiles(_relativeFiles, directory, { key, version });
|
|
||||||
if (res?.code === 200) {
|
if (res?.code === 200) {
|
||||||
console.log('File uploaded successfully!');
|
console.log('File uploaded successfully!');
|
||||||
res.data?.data?.files?.map?.((d) => {
|
res.data?.data?.files?.map?.((d) => {
|
||||||
|
@ -9,10 +9,70 @@ const token = new Command('token').description('show token').action(async () =>
|
|||||||
|
|
||||||
app.addCommand(token);
|
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();
|
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);
|
app.addCommand(baseURL);
|
||||||
|
|
||||||
const setBaseURL = new Command('setBaseURL').description('set baseURL').action(async () => {
|
const setBaseURL = new Command('setBaseURL').description('set baseURL').action(async () => {
|
||||||
|
@ -36,7 +36,7 @@ async function collectFileInfo(filePath: string, baseDir = '.'): Promise<any[]>
|
|||||||
// 解析 .npmignore 文件
|
// 解析 .npmignore 文件
|
||||||
async function loadNpmIgnore(cwd: string): Promise<ignore.Ignore> {
|
async function loadNpmIgnore(cwd: string): Promise<ignore.Ignore> {
|
||||||
const npmIgnorePath = path.join(cwd, '.npmignore');
|
const npmIgnorePath = path.join(cwd, '.npmignore');
|
||||||
const ig = ignore.default();
|
const ig = ignore();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const content = fs.readFileSync(npmIgnorePath, 'utf-8');
|
const content = fs.readFileSync(npmIgnorePath, 'utf-8');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user