deploy.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const copydir = require('copy-dir');
  2. const LineReader = require('n-readlines');
  3. const file = require('./src/file');
  4. const deploy = require('./deploy.json');
  5. // Constante
  6. const OUT = './dist/';
  7. // Creation dossier destination
  8. file.makedir(OUT);
  9. // Séparation de chaque programme
  10. deploy.programs.forEach(program => {
  11. // Création du dossier
  12. const distPath = OUT + program.name;
  13. file.makedir(distPath);
  14. // Copie des fichiers commun
  15. file.makedir(distPath + '/src');
  16. file.fs.readdirSync('./src').forEach(f => {
  17. if (!file.isDir('./src/' + f)) {
  18. file.fs.copyFile('./src/' + f, distPath + '/src/' + f, (err) => {
  19. if (err) throw err;
  20. });
  21. }
  22. });
  23. // Copie dossier propre à chaque programme
  24. copydir('./src/' + program.name, distPath + '/src/' + program.name, {
  25. utimes: true,
  26. mode: true,
  27. cover: true
  28. }, (err) => {
  29. if (err) throw err;
  30. });
  31. // Copie fichier main
  32. file.fs.copyFile(program.main, distPath + '/main.js', (err) => {
  33. if (err) throw err;
  34. });
  35. // Copie package.json
  36. const pckg = require('./package.json');
  37. pckg.scripts = program.scripts;
  38. pckg.version = program.version;
  39. program.rm_dependencies.forEach(elt => {
  40. delete pckg.dependencies[elt];
  41. });
  42. let json = JSON.stringify(pckg, null, 4);
  43. json = json.replace(new RegExp(program.main, 'g'), 'main.js');
  44. file.put(distPath + '/package.json', json);
  45. // Ecriture ReadMe
  46. file.put(distPath + '/README.md', readMe(program.part).replace(new RegExp(program.main, 'g'), 'main.js'));
  47. });
  48. // Fonction découpage readme
  49. function readMe(part) {
  50. const liner = new LineReader('./README.md');
  51. let data = '';
  52. let line = liner.next().toString();
  53. while (line !== 'false' && line.indexOf('## Partie ') === -1) {
  54. data += '\n' + line;
  55. line = liner.next().toString();
  56. }
  57. while (line !== 'false' && line.indexOf('## Partie ' + part) === -1) {
  58. line = liner.next().toString();
  59. }
  60. data += '\n' + line;
  61. line = liner.next().toString();
  62. while (line !== 'false' && line.indexOf('## Partie ') === -1) {
  63. data += '\n' + line;
  64. line = liner.next().toString();
  65. }
  66. if (line !== 'false') {
  67. liner.close();
  68. }
  69. return data;
  70. }