migrate_old.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const fs = require('fs');
  2. const path = require('path');
  3. const { exec } = require('child_process');
  4. const Promise = require('bluebird');
  5. const examplesDir = path.normalize(__dirname + '/../exemples');
  6. const listJson = require('./exemples/liste.json');
  7. Promise.promisifyAll(fs);
  8. // Promisified exec
  9. function execAsync(cmd) {
  10. return new Promise((resolve, reject) => {
  11. exec(cmd, (error, stdout, stderr) => {
  12. if (error) {
  13. return reject(error);
  14. }
  15. resolve({ stdout, stderr });
  16. });
  17. });
  18. }
  19. // Promisified exec of git mv src dst
  20. function gitMvAsync(src, dst) {
  21. var cmd = 'git mv ' + src + ' ' + dst;
  22. execAsync(cmd)
  23. .then(({stdout, stderr}) => {
  24. console.log(`stdout: ${stdout}`);
  25. console.log(`stderr: ${stderr}`);
  26. })
  27. .catch(error => {
  28. console.error(`exec error: ${error}`);
  29. throw error;
  30. });
  31. }
  32. // execAsync('git status')
  33. // .then(({stdout, stderr}) => {
  34. // console.log(`stdout: ${stdout}`);
  35. // console.log(`stderr: ${stderr}`);
  36. // })
  37. // .catch(error => {
  38. // console.error(`exec error: ${error}`);
  39. // });
  40. // rename all examples' html
  41. // fs.readdirAsync(examplesDir)
  42. // .then(dirContent => {
  43. // var excludes = ['liste.json', '.gitkeep', 'start-iframe.html', 'template.html'];
  44. // excludes.forEach(file => {
  45. // var idxInContent = dirContent.indexOf(file);
  46. // if(idxInContent !== -1) {
  47. // dirContent.splice(idxInContent, 1);
  48. // }
  49. // });
  50. // return dirContent;
  51. // })
  52. // .then(dirContent => Promise.map(dirContent, dir => {
  53. // const fullPath = examplesDir + '/' + dir;
  54. // const src = fullPath + '/contenu.html';
  55. // const dst = fullPath + '/example.html';
  56. // gitMvAsync(src, dst)
  57. // })
  58. // )
  59. // .catch(console.error);