axios-miniprogram/scripts/publish.ts

47 lines
838 B
TypeScript
Raw Normal View History

2023-04-05 08:40:00 +08:00
import fs from 'node:fs';
2023-03-25 23:31:27 +08:00
import consola from 'consola';
2023-04-05 08:40:00 +08:00
import { exec, pkgPath, getPkgJSON } from './utils';
2023-03-25 23:31:27 +08:00
2023-04-05 08:40:00 +08:00
const pkg = getPkgJSON();
2023-03-25 23:31:27 +08:00
main();
function main() {
2023-04-05 08:40:00 +08:00
consola.info('Generate publish pkg');
generatePublishPkg();
2023-03-25 23:31:27 +08:00
let command = 'npm publish --access public';
2023-04-05 08:40:00 +08:00
const preid = pkg.version.match(/\d-(.+)\.\d$/)?.[1];
2023-03-25 23:31:27 +08:00
if (preid) {
command += ` --tag ${preid}`;
}
consola.info('Publish NPM');
exec(command);
}
2023-04-05 08:40:00 +08:00
function generatePublishPkg() {
2023-05-14 20:55:47 +08:00
const publishPkg: AnyObject = {};
2023-04-05 08:40:00 +08:00
[
'name',
'version',
'description',
'main',
'module',
'types',
'files',
'repository',
'keywords',
'author',
'bugs',
'homepage',
'license',
].forEach((key) => {
publishPkg[key] = pkg[key];
});
fs.writeFileSync(pkgPath, JSON.stringify(publishPkg, null, 2) + '\n');
}