migrate_old.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. const fs = require('fs');
  2. const path = require('path');
  3. const Promise = require('bluebird');
  4. const execAsync = require('../lib/execAsync');
  5. const examplesDir = path.normalize(__dirname + '/../exemples/jquery');
  6. // const listJson = require('../exemples/liste.json');
  7. const beautify = require("json-beautify");
  8. Promise.promisifyAll(fs);
  9. // Promisified exec of git mv src dst
  10. function gitMvAsync(src, dst) {
  11. var cmd = 'git mv ' + src + ' ' + dst;
  12. execAsync(cmd)
  13. .then(({stdout, stderr}) => {
  14. console.log(`stdout: ${stdout}`);
  15. console.log(`stderr: ${stderr}`);
  16. })
  17. .catch(error => {
  18. console.error(`exec error: ${error}`);
  19. throw error;
  20. });
  21. }
  22. // Promisified exec of git status
  23. // execAsync('git status')
  24. // .then(({stdout, stderr}) => {
  25. // console.log(`stdout: ${stdout}`);
  26. // console.log(`stderr: ${stderr}`);
  27. // })
  28. // .catch(error => {
  29. // console.error(`exec error: ${error}`);
  30. // });
  31. // rename all examples' html
  32. // fs.readdirAsync(examplesDir)
  33. // .then(dirContent => {
  34. // var excludes = ['liste.json', '.gitkeep', 'start-iframe.html', 'template.html'];
  35. // excludes.forEach(file => {
  36. // var idxInContent = dirContent.indexOf(file);
  37. // if(idxInContent !== -1) {
  38. // dirContent.splice(idxInContent, 1);
  39. // }
  40. // });
  41. // return dirContent;
  42. // })
  43. // .then(dirContent => Promise.map(dirContent, dir => {
  44. // const fullPath = examplesDir + '/' + dir;
  45. // const src = fullPath + '/contenu.html';
  46. // const dst = fullPath + '/example.html';
  47. // gitMvAsync(src, dst)
  48. // })
  49. // )
  50. // .catch(console.error);
  51. function writeExampleConfig(slug) {
  52. var config = require(examplesDir + '/' + slug + '/config.json');
  53. var { title, category, html, js, css, libsJs, libsCss } = config;
  54. config = { title, category, html, js, css, libsJs, libsCss };
  55. // console.log(exampleConfig)
  56. // return new Promise((resolve, reject) => {
  57. // const { slug, title } = example;
  58. // const config = {
  59. // title,
  60. // html: ['example.html'],
  61. // js: ['script.js'],
  62. // css: [],
  63. // libsCss: ['styles.css'],
  64. // libsJs: ['jquery-3.2.1.min.js']
  65. // };
  66. const configJson = beautify(config, null, 2, 100);
  67. // // resolve(configJson);
  68. return fs.writeFileAsync(examplesDir + '/' + slug + '/config.json', configJson);
  69. // });
  70. }
  71. fs.readdirAsync(examplesDir)
  72. .then(dirContent => {
  73. var excludes = ['liste.json', '.gitkeep', 'repo-config.json'];
  74. excludes.forEach(file => {
  75. var idxInContent = dirContent.indexOf(file);
  76. if(idxInContent !== -1) {
  77. dirContent.splice(idxInContent, 1);
  78. }
  79. });
  80. return dirContent;
  81. })
  82. .then(exampleList => Promise.map(exampleList, writeExampleConfig))
  83. .then(filesPerExample => console.log(filesPerExample));