Ver código fonte

create util to reset untracked examples and repos

Benoît Hubert 8 anos atrás
pai
commit
695a62e6b0
3 arquivos alterados com 55 adições e 14 exclusões
  1. 14 0
      lib/execAsync.js
  2. 40 0
      lib/resetExampleRepos.js
  3. 1 14
      utils/migrate_old.js

+ 14 - 0
lib/execAsync.js

@@ -0,0 +1,14 @@
+const Promise  = require('bluebird');
+const { exec } = require('child_process');
+
+// Promisified exec
+module.exports = function execAsync(cmd) {
+  return new Promise((resolve, reject) => {
+    exec(cmd, (error, stdout, stderr) => {
+      if (error) {
+        return reject(error);
+      }
+      resolve({ stdout, stderr });
+    });
+  });
+}

+ 40 - 0
lib/resetExampleRepos.js

@@ -0,0 +1,40 @@
+const path        = require('path');
+const execAsync   = require('./execAsync');
+const appRoot     = path.normalize(__dirname + '/..');
+const isTesting   = process.env.NODE_ENV === 'testing';
+const examplesDir = ! isTesting ? appRoot + '/exemples' :
+  appRoot + '/test/integration/test-examples';
+
+// Promisified exec of git mv src dst
+function gitStatusAsync(src, dst) {
+  var cmd = 'git status ' + examplesDir;
+  return execAsync(cmd)
+  // .then(({ stdout, stderr }) => {
+  //   // console.log(`stdout: ${stdout}`);
+  //   // console.log(`stderr: ${stderr}`);
+  // })
+  .catch(error => {
+    console.error(`exec error: ${error}`);
+    throw error;
+  });  
+}
+
+function getUntrackedReposAndExamples() {
+  gitStatusAsync()
+  .then(({ stdout }) => {
+    let idx = stdout.indexOf('Untracked files:');
+    const output = stdout.substr(idx);
+    let lines = output.split('\n');
+
+    lines.splice(0, 3);
+    idx = 0;
+    while(lines[idx]) idx++;
+    lines.splice(idx, lines.length - idx);
+    lines.forEach((line, i) => {
+      lines[i] = line.trim();
+    });
+    console.log(lines);
+  });
+}
+
+getUntrackedReposAndExamples()

+ 1 - 14
utils/migrate_old.js

@@ -1,25 +1,12 @@
 const fs          = require('fs');
 const path        = require('path');
-const { exec }    = require('child_process');
 const Promise     = require('bluebird');
+const execAsync   = require('../lib/execAsync');
 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;