Skip to content

Commit

Permalink
Merge pull request #9 from okhiroyuki/feature/update-script
Browse files Browse the repository at this point in the history
update script
  • Loading branch information
okhiroyuki authored Aug 28, 2023
2 parents a122835 + a324fea commit 499c787
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 47 deletions.
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
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 499c787

Please sign in to comment.