feat: 添加publish
This commit is contained in:
@@ -65,7 +65,7 @@ async function getFiles(cwd: string, patterns: string[]): Promise<string[]> {
|
||||
return filteredFiles;
|
||||
}
|
||||
|
||||
const pack = async () => {
|
||||
export const pack = async () => {
|
||||
const cwd = process.cwd();
|
||||
const collection: Record<string, any> = {};
|
||||
const packageJsonPath = path.join(cwd, 'package.json');
|
||||
@@ -120,6 +120,7 @@ const pack = async () => {
|
||||
collection.files = allFiles;
|
||||
collection.packageJson = packageJson;
|
||||
collection.totalSize = totalSize;
|
||||
collection.tags = packageJson.app?.tags || packageJson.keywords || [];
|
||||
|
||||
console.log('\nTarball Details');
|
||||
console.log(`name: ${packageJson.name}`);
|
||||
@@ -147,7 +148,7 @@ const pack = async () => {
|
||||
}
|
||||
return { collection, outputFilePath };
|
||||
};
|
||||
const packByIgnore = async () => {
|
||||
export const packByIgnore = async () => {
|
||||
let collection: Record<string, any> = {};
|
||||
const cwd = process.cwd();
|
||||
const patterns = ['**/*']; // 匹配所有文件
|
||||
@@ -184,6 +185,7 @@ const packByIgnore = async () => {
|
||||
collection.files = allFiles;
|
||||
collection.packageJson = packageJson;
|
||||
collection.totalSize = totalSize;
|
||||
collection.tags = packageJson.app?.tags || packageJson.keywords || [];
|
||||
|
||||
console.log('\nTarball Details');
|
||||
console.log(`package size: ${packageSize}`);
|
||||
@@ -208,6 +210,22 @@ const packByIgnore = async () => {
|
||||
}
|
||||
return { collection, outputFilePath };
|
||||
};
|
||||
export const packLib = async (ignore: boolean = false) => {
|
||||
if (ignore) {
|
||||
return await packByIgnore();
|
||||
}
|
||||
return await pack();
|
||||
};
|
||||
export const unpackLib = async (filePath: string, cwd: string) => {
|
||||
try {
|
||||
await tar.x({
|
||||
file: filePath,
|
||||
cwd: cwd,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error extracting tarball:', error);
|
||||
}
|
||||
};
|
||||
const publishCommand = new Command('publish')
|
||||
.description('发布应用')
|
||||
.option('-k, --key <key>', '应用 key')
|
||||
@@ -276,12 +294,7 @@ const packCommand = new Command('pack')
|
||||
.option('-i, --ignore', '使用 .npmignore 文件模式去忽略文件进行打包, 不需要package.json中的files字段')
|
||||
.option('-p, --publish', '打包并发布')
|
||||
.action(async (opts) => {
|
||||
let value: { collection: Record<string, any>; outputFilePath: string };
|
||||
if (opts.ignore) {
|
||||
value = await packByIgnore();
|
||||
} else {
|
||||
value = await pack();
|
||||
}
|
||||
let value: { collection: Record<string, any>; outputFilePath: string } = await packLib(opts.ignore);
|
||||
if (opts.publish && value?.collection) {
|
||||
console.log('\n\npublish');
|
||||
const { collection, outputFilePath } = value;
|
||||
|
||||
Reference in New Issue
Block a user