diff --git a/README.md b/README.md index 6870444..196ca47 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,7 @@ Check Youtube👇 -[![](http://img.youtube.com/vi/s_MvkH3IXrM/0.jpg)](http://www.youtube.com/watch?v=s_MvkH3IXrM "") - +[![youtube](http://img.youtube.com/vi/s_MvkH3IXrM/0.jpg)](http://www.youtube.com/watch?v=s_MvkH3IXrM "") ## Installation @@ -18,20 +17,16 @@ git clone https://github.com/okhiroyuki/redmobile-modules-generator.git ## Usage -First, do `npm i`. - -Next, Install the Node-RED Custom Node you want to use with the npm command. - -Sample: - -```bash -// Add any module -npm i node-red-contrib-telegrambot -``` +1. `npm i` +1. Install the Node-RED Custom Node you want to use with the npm command. -Finally, do `npm run build`. + ```bash + // sample + npm i node-red-contrib-telegrambot + ``` -The `node_modules.zip` file will be generated directly under the dist folder. +1. `npm run build` +1. The `node_modules.zip` file will be generated directly under the dist folder. ## How to apply it to Redmobile diff --git a/main.js b/main.js index a4b7cb8..3016845 100644 --- a/main.js +++ b/main.js @@ -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`; @@ -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 }); @@ -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); } })();