mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-04-27 14:57:40 +00:00
minor improvements to build script
This commit is contained in:
parent
1c7e95f79c
commit
b9609d9b24
1 changed files with 9 additions and 9 deletions
18
build.js
18
build.js
|
|
@ -6,8 +6,6 @@ var constants
|
||||||
, mustache = require('mustache')
|
, mustache = require('mustache')
|
||||||
, EEXIST
|
, EEXIST
|
||||||
, ENOENT
|
, ENOENT
|
||||||
, _template
|
|
||||||
, _n = 0
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
constants = require('constants')
|
constants = require('constants')
|
||||||
|
|
@ -18,9 +16,10 @@ EEXIST = constants.EEXIST
|
||||||
ENOENT = constants.ENOENT
|
ENOENT = constants.ENOENT
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
|
var ctx = {}
|
||||||
fs.readFile(path.join(__dirname, 'templates', 'proj', 'proj', 'index.html'), function(err, html) {
|
fs.readFile(path.join(__dirname, 'templates', 'proj', 'proj', 'index.html'), function(err, html) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
_template = html.toString()
|
ctx.template = html.toString()
|
||||||
fs.readFile(path.join(__dirname, 'projects.json'), function(err, json) {
|
fs.readFile(path.join(__dirname, 'projects.json'), function(err, json) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
var projects = JSON.parse(json)
|
var projects = JSON.parse(json)
|
||||||
|
|
@ -47,15 +46,16 @@ function main() {
|
||||||
})
|
})
|
||||||
|
|
||||||
// write project pages
|
// write project pages
|
||||||
|
ctx.n = 0
|
||||||
names.forEach(function(name) {
|
names.forEach(function(name) {
|
||||||
_n += 1
|
ctx.n += 1
|
||||||
buildProject(name, projects[name])
|
buildProject(name, projects[name], ctx)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildProject(name, project) {
|
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.mkdir(dir, 0775, function(err) {
|
fs.mkdir(dir, 0775, function(err) {
|
||||||
|
|
@ -63,11 +63,11 @@ function buildProject(name, project) {
|
||||||
fs.unlink(index, function(err) {
|
fs.unlink(index, function(err) {
|
||||||
if (err && err.errno !== ENOENT) throw err
|
if (err && err.errno !== ENOENT) throw err
|
||||||
project.name = name
|
project.name = name
|
||||||
fs.writeFile(index, mustache.to_html(_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)
|
||||||
_n -= 1
|
ctx.n -= 1
|
||||||
console.log('* ' + name + (err ? ' (failed)' : ''))
|
console.log('* ' + name + (err ? ' (failed)' : ''))
|
||||||
if (_n === 0) console.log('done')
|
if (ctx.n === 0) console.log('done projects')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue