AIx_Smarttalk_WS/updatePackageJsonName.js

15 lines
541 B
JavaScript

const fs = require('fs');
const path = require('path');
const { env } = require('process');
// 读取当前的package.json文件
const packageJsonPath = path.join(__dirname, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
console.log(env)
let res = env.npm_lifecycle_event.replace("build", "").replace(":", "");
res = res?"-" + res:"";
packageJson.name = "aix-win-ws" + res
// 将修改后的内容写回package.json文件
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));