Based on node.js, complete the installation, packaging, compression, deletion and other functions of multiple application packages of H5
step:
- Create a new folder (for example: h5-applications), and create a new serve file in this directory to store node.js.
- Put multiple H5 application packages in the h5-applications directory. Each application should contain a package.json file, which is used to define information such as project dependencies and packaging commands.
- Write a Node.js script that can read multiple application packages in the upper-level directory and traverse the file name of each application package.
- For each application package, use multi-threaded pnpm or yarn to download dependencies according to the package.json file, and execute the packaging command.
- After the packaging is successful, compress the generated dist folder into a zip package and upload it to the gitee server.
Detailed code:
- Under the serve folder, create a new
build.js
file and executenode build.js
Main functions: install dependencies, package, compress files
const fs = require('fs');
const path = require('path');
// 第一步,导入必要的模块
const archiver = require('archiver');
const {
execSync } = require('child_process');
const appsDir = path.join(__dirname, '../project'); // 上级目录
console.log(appsDir)
const apps = fs.readdirSync(appsDir).filter(name => {
const dir = path.join(appsDir, name);
return fs.statSync(dir).isDirectory();
});
console.log('全部文件列表:', apps)
// 获取所有应用包名称
// const giteeUrl = 'https://gitee.com/YOUR_USERNAME/YOUR_REPO.git';
let newapps = apps.filter(item => {
return item !== 'serve'
})
newapps.forEach(name => {
// const appPath = path.join(appsDir, name);
const appPath = path.join(appsDir, `${
name}/源码包`);
console.log(appPath)