浏览代码

script abstraction

Heydon Pickering 8 年之前
父节点
当前提交
6556968d32
共有 3 个文件被更改,包括 36 次插入2 次删除
  1. 11 0
      lib/build.js
  2. 23 0
      lib/clean.js
  3. 2 2
      package.json

+ 11 - 0
lib/build.js

@@ -0,0 +1,11 @@
+var exec = require('child_process').exec;
+var path = require('path');
+
+exec('rm -rfv ' + path.join(path.resolve('.'), 'docs', '*') + ' && hugo && sw-precache --root=docs && git add -A', function(error, stdout, stderr) {
+  console.log('Building...');
+  if (error !== null) {
+    console.error('Error building site.');
+    return;
+  }
+  console.log('Site built at /docs.');
+});

+ 23 - 0
lib/clean.js

@@ -0,0 +1,23 @@
+var exec = require('child_process').exec;
+var path = require('path');
+
+exec('rm -rf ' + path.join(path.resolve('.'), 'content') + ' && mkdir content && mkdir ' + path.join('content', 'patterns'), function(error, stdout, stderr) {
+  console.log('Initializing new project...');
+  if (error !== null) {
+    console.error('Error creating folder structure.');
+    return;
+  }
+  exec ('hugo new ' + path.join('patterns', 'pattern.md') + ' && hugo new _index.md && hugo new print-version.md --kind print-version', function(error, stdout, stderr) {
+    if (error !== null) {
+      console.error('Error creating new project files.');
+      return;
+    }
+    exec ('cat ' + path.join('themes', 'infusion', 'data', 'README_BLANK.md') + ' > README.md', function(error, stdout, stderr) {
+      if (error !== null) {
+        console.error('Error initializing README file.');
+        return;
+      }
+      console.log('New project ready. See patterns/pattern.md to get started.');
+    });
+  });
+});

+ 2 - 2
package.json

@@ -6,8 +6,8 @@
   "scripts": {
   "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1",
     "test": "echo \"Error: no test specified\" && exit 1",
     "serve": "hugo server --baseURL http://localhost:1313",
     "serve": "hugo server --baseURL http://localhost:1313",
-    "clean": "rm -rf content && mkdir content && mkdir content/patterns && hugo new patterns/pattern.md && hugo new _index.md && hugo new print-version.md --kind print-version && cat themes/infusion/data/README_BLANK.md > README.md",
-    "build": "rm -rfv docs/* && hugo && sw-precache --root=docs && git add -A",
+    "clean": "node lib/clean.js",
+    "build": "node lib/build.js",
     "update": "node lib/update.js"
     "update": "node lib/update.js"
   },
   },
   "pre-commit": [
   "pre-commit": [