Skip to content

Commit

Permalink
feat: Change to simple processing
Browse files Browse the repository at this point in the history
  • Loading branch information
okhiroyuki committed Aug 28, 2023
1 parent a122835 commit 6d5ebc4
Showing 1 changed file with 7 additions and 33 deletions.
40 changes: 7 additions & 33 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const fs = require('fs');
const archiver = require('archiver');
const childProcess = require('child_process');
const modclean = require('modclean');

const distDir = 'dist';
const targetDir = 'node_modules';
const distPath = 'dist/node_modules.zip';
const distPath = `${distDir}/${targetDir}.zip`;

const zipArchive = async () => {
const zipPath = `${targetDir}.zip`;
Expand All @@ -31,25 +30,6 @@ const zipArchive = async () => {
await archive.finalize();
}

const runNpm = (cmd, args) => {
return new Promise((resolve) => {
let n = childProcess.spawn(cmd,args);
n.stdout.setEncoding('utf-8');
n.stdout.on('data', (data) => {
console.log(`${data}`);
});

n.stderr.on('data', (data) => {
console.error(`${data}`);
});

n.on('close', (code) => {
console.log(`child process exited with code ${code}`);
resolve();
});
});
}

const clearDir = (dir) => {
if (fs.existsSync(dir)) {
fs.rmSync(dir, { recursive: true, force: true });
Expand All @@ -59,17 +39,11 @@ const clearDir = (dir) => {
(async() => {
clearDir(distDir);
fs.mkdirSync(distDir);
if( fs.existsSync( 'package-lock.json' ) ){
fs.unlinkSync('package-lock.json');
try {
await runNpm('npm',['i','--omit=dev']);
let mc = modclean({ignorePatterns:['example*', 'examples']});
mc.clean();
await zipArchive();
}catch(e){
console.error(e.stack);
}
}else{
console.log('Start with the first step (npm i)');
try {
let mc = modclean({ignorePatterns:['example*', 'examples']});
mc.clean();
await zipArchive();
}catch(e){
console.error(e.stack);
}
})();

0 comments on commit 6d5ebc4

Please sign in to comment.