update add update
This commit is contained in:
@@ -36,8 +36,9 @@ async function collectFileInfo(filePath: string, baseDir = '.'): Promise<any[]>
|
||||
* @param files 文件列表, 或者文件夹列表
|
||||
* @param cwd 当前工作目录
|
||||
* @param packDist 打包目录 pack-dist
|
||||
* @param mergeDist 是否合并 dist 目录到 pack-dist 中
|
||||
*/
|
||||
export const copyFilesToPackDist = async (files: string[], cwd: string, packDist = 'pack-dist') => {
|
||||
export const copyFilesToPackDist = async (files: string[], cwd: string, packDist = 'pack-dist', mergeDist = true) => {
|
||||
const packDistPath = path.join(cwd, packDist);
|
||||
if (!fileIsExist(packDistPath)) {
|
||||
fs.mkdirSync(packDistPath, { recursive: true });
|
||||
@@ -47,10 +48,12 @@ export const copyFilesToPackDist = async (files: string[], cwd: string, packDist
|
||||
files.forEach((file) => {
|
||||
const stat = fs.statSync(path.join(cwd, file));
|
||||
let outputFile = file;
|
||||
if (file.startsWith('dist/')) {
|
||||
outputFile = file.replace(/^dist\//, '');
|
||||
} else if (file === 'dist') {
|
||||
outputFile = '';
|
||||
if (mergeDist) {
|
||||
if (file.startsWith('dist/')) {
|
||||
outputFile = file.replace(/^dist\//, '');
|
||||
} else if (file === 'dist') {
|
||||
outputFile = '';
|
||||
}
|
||||
}
|
||||
if (stat.isDirectory()) {
|
||||
fs.cpSync(path.join(cwd, file), path.join(packDistPath, outputFile), { recursive: true });
|
||||
@@ -93,9 +96,11 @@ ${filesString}
|
||||
fs.writeFileSync(indexHtmlPath, indexHtmlContent);
|
||||
}
|
||||
};
|
||||
export const pack = async (opts: { packDist?: string }) => {
|
||||
|
||||
export const pack = async (opts: { packDist?: string, mergeDist?: boolean }) => {
|
||||
const cwd = process.cwd();
|
||||
const collection: Record<string, any> = {};
|
||||
const mergeDist = opts.mergeDist !== false;
|
||||
const packageJsonPath = path.join(cwd, 'package.json');
|
||||
if (!fileIsExist(packageJsonPath)) {
|
||||
console.error('package.json not found');
|
||||
@@ -150,7 +155,7 @@ export const pack = async (opts: { packDist?: string }) => {
|
||||
console.log(`version: ${packageJson.version}`);
|
||||
console.log(`total files: ${allFiles.length}`);
|
||||
try {
|
||||
copyFilesToPackDist(filesToInclude, cwd, opts.packDist);
|
||||
copyFilesToPackDist(filesToInclude, cwd, opts.packDist, mergeDist);
|
||||
} catch (error) {
|
||||
console.error('Error creating tarball:', error);
|
||||
}
|
||||
@@ -173,17 +178,6 @@ export const getPackageInfo = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 打包应用
|
||||
* @returns 打包结果
|
||||
*/
|
||||
export const packLib = async ({
|
||||
packDist = 'pack-dist',
|
||||
}: {
|
||||
packDist?: string;
|
||||
}): Promise<{ collection: Record<string, any>; dir: string }> => {
|
||||
return await pack({ packDist });
|
||||
};
|
||||
const publishCommand = new Command('publish')
|
||||
.description('发布应用')
|
||||
.option('-k, --key <key>', '应用 key')
|
||||
@@ -199,21 +193,6 @@ const deployLoadFn = async (id: string, fileKey: string, force = false, install
|
||||
console.error(chalk.red('id is required'));
|
||||
return;
|
||||
}
|
||||
// pkg: {
|
||||
// name: 'mark',
|
||||
// version: '0.0.2',
|
||||
// description: '',
|
||||
// main: 'dist/app.mjs',
|
||||
// app: [Object],
|
||||
// files: [Array],
|
||||
// scripts: [Object],
|
||||
// keywords: [Array],
|
||||
// author: 'abearxiong <xiongxiao@xiongxiao.me>',
|
||||
// license: 'MIT',
|
||||
// type: 'module',
|
||||
// devDependencies: [Object],
|
||||
// dependencies: [Object]
|
||||
// },
|
||||
let appKey = '';
|
||||
let version = '';
|
||||
if (id && id.includes('/')) {
|
||||
@@ -253,10 +232,13 @@ const packCommand = new Command('pack')
|
||||
.option('-p, --publish', '打包并发布')
|
||||
.option('-u, --update', '发布后显示更新命令, show command for deploy to server')
|
||||
.option('-d, --packDist <dist>', '打包到的目录')
|
||||
.option('-y, --yes', '确定,直接打包', true)
|
||||
.option('-m, --mergeDist <mergeDist>', '合并 dist 目录到 pack-dist 中', "true")
|
||||
.option('-y, --yes <yes>', '确定,直接打包', "true")
|
||||
.option('-c, --clean', '清理 package.json中的 devDependencies')
|
||||
.action(async (opts) => {
|
||||
const packDist = opts.packDist || 'pack-dist';
|
||||
const mergeDist = opts.mergeDist === "true";
|
||||
const yes = opts.yes === "true";
|
||||
const packageInfo = await getPackageInfo();
|
||||
if (!packageInfo) {
|
||||
console.error('Invalid package.json:');
|
||||
@@ -297,8 +279,9 @@ const packCommand = new Command('pack')
|
||||
]);
|
||||
appKey = answers.appKey || appKey;
|
||||
}
|
||||
let value = await packLib({
|
||||
let value = await pack({
|
||||
packDist,
|
||||
mergeDist
|
||||
});
|
||||
if (opts?.clean) {
|
||||
const newPackageJson = { ...packageInfo };
|
||||
@@ -317,7 +300,7 @@ const packCommand = new Command('pack')
|
||||
if (opts.update) {
|
||||
deployCommand.push('-s');
|
||||
}
|
||||
if (opts.yes) {
|
||||
if (yes) {
|
||||
deployCommand.push('-y', 'yes');
|
||||
}
|
||||
console.log(chalk.blue('deploy doing: '), deployCommand.slice(2).join(' '), '\n');
|
||||
|
||||
Reference in New Issue
Block a user