Browse Source

package.json scripts: use NodeJS instead of unix commands

develop
Alice Gaudon 3 weeks ago
parent
commit
60e32042f7
5 changed files with 54 additions and 5 deletions
  1. +1
    -0
      .eslintrc.json
  2. +5
    -5
      package.json
  3. +10
    -0
      scripts/clean.js
  4. +34
    -0
      scripts/dist.js
  5. +4
    -0
      scripts/prepare-sources.js

+ 1
- 0
.eslintrc.json View File

@ -86,6 +86,7 @@
},
"ignorePatterns": [
"jest.config.js",
"scripts/**/*",
"dist/**/*",
"config/**/*"
],


+ 5
- 5
package.json View File

@ -14,12 +14,12 @@
"types": "dist/index.d.ts",
"scripts": {
"test": "jest --verbose --runInBand",
"clean": "(test ! -d dist || rm -r dist)",
"prepareSources": "cp package.json src/",
"clean": "node scripts/clean.js",
"prepare-sources": "node scripts/prepare-sources.js",
"compile": "yarn clean && tsc",
"build": "yarn prepareSources && yarn compile && cp -r yarn.lock README.md config/ views/ dist/ && mkdir dist/types && cp src/types/* dist/types/",
"dev": "yarn prepareSources && concurrently -k -n \"Typescript,Node,Webpack,Maildev\" -p \"[{name}]\" -c \"blue,green,red,yellow\" \"tsc --watch\" \"nodemon\" \"maildev\"",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"build": "yarn prepare-sources && yarn compile && node scripts/dist.js",
"dev": "yarn prepare-sources && concurrently -k -n \"Typescript,Node,Webpack,Maildev\" -p \"[{name}]\" -c \"blue,green,red,yellow\" \"tsc --watch\" \"nodemon\" \"maildev\"",
"lint": "eslint .",
"release": "yarn build && yarn lint && yarn test && cd dist && yarn publish"
},
"devDependencies": {


+ 10
- 0
scripts/clean.js View File

@ -0,0 +1,10 @@
const fs = require('fs');
[
'dist',
].forEach(file => {
if (fs.existsSync(file)) {
console.log('Cleaning', file, '...');
fs.rmSync(file, {recursive: true});
}
});

+ 34
- 0
scripts/dist.js View File

@ -0,0 +1,34 @@
const fs = require('fs');
const path = require('path');
function copyRecursively(file, destination) {
const target = path.join(destination, path.basename(file));
if (fs.statSync(file).isDirectory()) {
console.log('mkdir', target);
fs.mkdirSync(target, {recursive: true});
fs.readdirSync(file).forEach(f => {
copyRecursively(path.join(file, f), target);
});
} else {
console.log('> cp ', target);
fs.copyFileSync(file, target);
}
}
[
'yarn.lock',
'README.md',
'config/',
'views/',
].forEach(file => {
copyRecursively(file, 'dist');
});
fs.mkdirSync('dist/types', {recursive: true});
fs.readdirSync('src/types').forEach(file => {
copyRecursively(path.join('src/types', file), 'dist/types');
});

+ 4
- 0
scripts/prepare-sources.js View File

@ -0,0 +1,4 @@
const fs = require('fs');
const path = require('path');
fs.copyFileSync('package.json', path.join('src', 'package.json'));

Loading…
Cancel
Save