deploy.js 2.4 KB

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