| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- const fs = require('fs');
- const path = require('path');
- const { exec } = require('child_process');
- const Promise = require('bluebird');
- const examplesDir = path.normalize(__dirname + '/../exemples/jquery');
- // const listJson = require('../exemples/liste.json');
- const beautify = require("json-beautify");
- Promise.promisifyAll(fs);
- // Promisified exec
- function execAsync(cmd) {
- return new Promise((resolve, reject) => {
- exec(cmd, (error, stdout, stderr) => {
- if (error) {
- return reject(error);
- }
- resolve({ stdout, stderr });
- });
- });
- }
- // Promisified exec of git mv src dst
- function gitMvAsync(src, dst) {
- var cmd = 'git mv ' + src + ' ' + dst;
- execAsync(cmd)
- .then(({stdout, stderr}) => {
- console.log(`stdout: ${stdout}`);
- console.log(`stderr: ${stderr}`);
- })
- .catch(error => {
- console.error(`exec error: ${error}`);
- throw error;
- });
- }
- // Promisified exec of git status
- // execAsync('git status')
- // .then(({stdout, stderr}) => {
- // console.log(`stdout: ${stdout}`);
- // console.log(`stderr: ${stderr}`);
- // })
- // .catch(error => {
- // console.error(`exec error: ${error}`);
- // });
- // rename all examples' html
- // fs.readdirAsync(examplesDir)
- // .then(dirContent => {
- // var excludes = ['liste.json', '.gitkeep', 'start-iframe.html', 'template.html'];
- // excludes.forEach(file => {
- // var idxInContent = dirContent.indexOf(file);
- // if(idxInContent !== -1) {
- // dirContent.splice(idxInContent, 1);
- // }
- // });
- // return dirContent;
- // })
- // .then(dirContent => Promise.map(dirContent, dir => {
- // const fullPath = examplesDir + '/' + dir;
- // const src = fullPath + '/contenu.html';
- // const dst = fullPath + '/example.html';
- // gitMvAsync(src, dst)
- // })
- // )
- // .catch(console.error);
- function writeExampleConfig(example) {
- // return new Promise((resolve, reject) => {
- const { slug, title } = example;
- const config = {
- title,
- html: ['example.html'],
- js: ['script.js'],
- css: [],
- libsCss: ['styles.css'],
- libsJs: ['jquery-3.2.1.min.js']
- };
- const configJson = beautify(config, null, 2, 100);
- // resolve(configJson);
- return fs.writeFileAsync(examplesDir + '/' + slug + '/config.json', configJson);
- // });
- }
- Promise.map(listJson, writeExampleConfig)
- .then(filesPerExample => console.log(filesPerExample));
|