mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-04-27 14:57:40 +00:00
update build.js for recent versions of node
This commit is contained in:
parent
116fdff80b
commit
24fa5f6925
1 changed files with 6 additions and 16 deletions
22
build.js
22
build.js
|
|
@ -1,19 +1,8 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var constants
|
var fs = require('fs')
|
||||||
, fs = require('fs')
|
|
||||||
, path = require('path')
|
, path = require('path')
|
||||||
, mustache = require('mustache')
|
, mustache = require('mustache')
|
||||||
, EEXIST
|
|
||||||
, ENOENT
|
|
||||||
|
|
||||||
try {
|
|
||||||
constants = require('constants')
|
|
||||||
} catch (e) {
|
|
||||||
constants = process
|
|
||||||
}
|
|
||||||
EEXIST = constants.EEXIST
|
|
||||||
ENOENT = constants.ENOENT
|
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
var ctx = {}
|
var ctx = {}
|
||||||
|
|
@ -30,9 +19,9 @@ function main() {
|
||||||
fs.readFile(path.join(__dirname, 'templates', 'proj', 'index.html'), function(err, tpl) {
|
fs.readFile(path.join(__dirname, 'templates', 'proj', 'index.html'), function(err, tpl) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
fs.mkdir(path.join(__dirname, 'proj'), 0775, function(err) {
|
fs.mkdir(path.join(__dirname, 'proj'), 0775, function(err) {
|
||||||
if (err && err.errno !== EEXIST) throw err
|
if (err && err.code !== 'EEXIST') throw err
|
||||||
fs.unlink(index, function(err) {
|
fs.unlink(index, function(err) {
|
||||||
if (err && err.errno !== ENOENT) throw err
|
if (err && err.code !== 'ENOENT') throw err
|
||||||
var vals = { names: names }
|
var vals = { names: names }
|
||||||
, html = mustache.to_html(tpl.toString(), vals)
|
, html = mustache.to_html(tpl.toString(), vals)
|
||||||
fs.writeFile(index, html, function(err) {
|
fs.writeFile(index, html, function(err) {
|
||||||
|
|
@ -56,10 +45,11 @@ function main() {
|
||||||
function buildProject(name, project, ctx) {
|
function buildProject(name, project, ctx) {
|
||||||
var dir = path.join(__dirname, 'proj', name)
|
var dir = path.join(__dirname, 'proj', name)
|
||||||
, index = path.join(dir, 'index.html')
|
, index = path.join(dir, 'index.html')
|
||||||
|
fs.statSync(dir)
|
||||||
fs.mkdir(dir, 0775, function(err) {
|
fs.mkdir(dir, 0775, function(err) {
|
||||||
if (err && err.errno !== EEXIST) throw err
|
if (err && err.code !== 'EEXIST') throw err
|
||||||
fs.unlink(index, function(err) {
|
fs.unlink(index, function(err) {
|
||||||
if (err && err.errno !== ENOENT) throw err
|
if (err && err.code !== 'ENOENT') throw err
|
||||||
project.name = name
|
project.name = name
|
||||||
fs.writeFile(index, mustache.to_html(ctx.template, project), function(err) {
|
fs.writeFile(index, mustache.to_html(ctx.template, project), function(err) {
|
||||||
if (err) console.error('error: ', err.message)
|
if (err) console.error('error: ', err.message)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue