Comparing version 2.0.3 to 2.1.0
@@ -9,2 +9,3 @@ 'use strict'; | ||
help: { abbr: 'h', flag: true, help: 'Display this help message' }, | ||
watch: { abbr: 'w', flag: true, help: 'Rebuild when files change' }, | ||
biblio: { abbr: 'b', metavar: 'FILE', help: 'Write a biblio file to FILE' }, | ||
@@ -11,0 +12,0 @@ css: { metavar: 'FILE', help: 'Write Emu CSS dependencies to FILE' }, |
@@ -12,2 +12,4 @@ #!/usr/bin/env node | ||
const readFile = Promise.promisify(fs.readFile); | ||
const utils = require('../lib/utils'); | ||
const debounce = require('promise-debounce'); | ||
@@ -18,20 +20,60 @@ function fetch(path) { | ||
ecmarkup.build(args.infile, fetch, args).then(function (spec) { | ||
if (args.biblio) { | ||
fs.writeFileSync(args.biblio, JSON.stringify(spec.exportBiblio()), 'utf8'); | ||
} | ||
const build = debounce(function build() { | ||
return ecmarkup.build(args.infile, fetch, args).then(function (spec) { | ||
if (args.biblio) { | ||
if (args.verbose) { | ||
utils.logVerbose('Writing biblio file to ' + args.biblio); | ||
} | ||
fs.writeFileSync(args.biblio, JSON.stringify(spec.exportBiblio()), 'utf8'); | ||
} | ||
if (args.outfile) { | ||
fs.writeFileSync(args.outfile, spec.toHTML(), 'utf8'); | ||
} else { | ||
process.stdout.write(spec.toHTML()); | ||
} | ||
if (args.outfile) { | ||
if (args.verbose) { | ||
utils.logVerbose('Writing output to ' + args.outfile); | ||
} | ||
fs.writeFileSync(args.outfile, spec.toHTML(), 'utf8'); | ||
} else { | ||
process.stdout.write(spec.toHTML()); | ||
} | ||
if (args.css) { | ||
fs.writeFileSync(args.css, fs.readFileSync(Path.join(__dirname, '../css/elements.css'))); | ||
} | ||
if (args.css) { | ||
if (args.verbose) { | ||
utils.logVerbose('Writing css file to ' + args.css); | ||
} | ||
fs.writeFileSync(args.css, fs.readFileSync(Path.join(__dirname, '../css/elements.css'))); | ||
} | ||
if (args.js) { | ||
fs.writeFileSync(args.js, fs.readFileSync(Path.join(__dirname, '../js/menu.js'))); | ||
} | ||
if (args.js) { | ||
if (args.verbose) { | ||
utils.logVerbose('Writing css file to ' + args.css); | ||
} | ||
fs.writeFileSync(args.js, fs.readFileSync(Path.join(__dirname, '../js/menu.js'))); | ||
} | ||
return spec; | ||
}); | ||
}); | ||
if (args.watch) { | ||
let watching = {}; | ||
build().then(function(spec) { | ||
let toWatch = spec.imports.concat(args.infile); | ||
// remove any files that we're no longer watching | ||
Object.keys(watching).forEach(function(file) { | ||
if (toWatch.indexOf(file) === -1) { | ||
watching[file].close(); | ||
delete watching[file]; | ||
} | ||
}); | ||
// watch any new files | ||
toWatch.forEach(function(file) { | ||
if (!watching[file]) { | ||
watching[file] = fs.watch(file, build); | ||
} | ||
}); | ||
}); | ||
} else { | ||
build(); | ||
} |
@@ -11,2 +11,3 @@ 'use strict'; | ||
const importPath = Path.join(rootDir || this.spec.rootDir, href); | ||
this.spec.imports.push(importPath); | ||
@@ -13,0 +14,0 @@ return this.spec.fetch(importPath) |
@@ -41,2 +41,3 @@ 'use strict'; | ||
this.subclauses = []; | ||
this.imports = []; | ||
this._numberer = ClauseNumbers.iterator(); | ||
@@ -81,6 +82,6 @@ this._figureCounts = { | ||
this._log('Building ' + selector + '...'); | ||
let elems; | ||
if (typeof selector === 'string') { | ||
this._log('Building ' + selector + '...'); | ||
elems = this.doc.querySelectorAll(selector); | ||
@@ -162,3 +163,3 @@ } else { | ||
} catch (e) { | ||
console.log('Warning: metadata block failed to parse'); | ||
utils.logWarning('metadata block failed to parse'); | ||
return; | ||
@@ -200,3 +201,3 @@ } finally { | ||
if (!this.opts.location) { | ||
console.log('Warning: no spec location specified. Biblio not generated. Try --location or setting the location in the document\'s metadata block.'); | ||
utils.logWarning('no spec location specified. Biblio not generated. Try --location or setting the location in the document\'s metadata block.'); | ||
return {}; | ||
@@ -284,5 +285,5 @@ } | ||
_log() { | ||
_log(str) { | ||
if (!this.opts.verbose) return; | ||
console.log.apply(console, arguments); | ||
utils.logVerbose(str); | ||
} | ||
@@ -289,0 +290,0 @@ }; |
@@ -5,2 +5,3 @@ 'use strict'; | ||
const Promise = require('bluebird'); | ||
const chalk = require('chalk'); | ||
@@ -60,1 +61,11 @@ exports.htmlToDoc = function (html) { | ||
exports.logVerbose = function(str) { | ||
let dateString = (new Date()).toISOString(); | ||
console.log(chalk.gray('[' + dateString + '] ') + str); | ||
}; | ||
exports.logWarning = function(str) { | ||
let dateString = (new Date()).toISOString(); | ||
console.log(chalk.gray('[' + dateString + '] ') + chalk.red('Warning: ' + str)); | ||
}; |
@@ -12,3 +12,3 @@ 'use strict'; | ||
if (href && aoid) { | ||
console.log('Warning: xref can\'t have both href and aoid.'); | ||
utils.logWarning('xref can\'t have both href and aoid.'); | ||
return; | ||
@@ -18,3 +18,3 @@ } | ||
if (!href && !aoid) { | ||
console.log('Warning: xref has no href or aoid.'); | ||
utils.logWarning('xref has no href or aoid.'); | ||
return; | ||
@@ -25,3 +25,3 @@ } | ||
if (href[0] !== '#') { | ||
console.log('Warning: xref to anything other than a fragment id is not supported (is ' + href + '). Try href="#sec-id" instead.'); | ||
utils.logWarning('xref to anything other than a fragment id is not supported (is ' + href + '). Try href="#sec-id" instead.'); | ||
return; | ||
@@ -34,3 +34,3 @@ } | ||
if (!entry) { | ||
console.log('Warning: can\'t find clause, production, note or example with id ' + href); | ||
utils.logWarning('can\'t find clause, production, note or example with id ' + href); | ||
return; | ||
@@ -59,3 +59,3 @@ } | ||
default: | ||
console.log('Warning: found unknown biblio entry (this is a bug, please file it)'); | ||
utils.logWarning('found unknown biblio entry (this is a bug, please file it)'); | ||
} | ||
@@ -70,3 +70,3 @@ } else if (aoid) { | ||
console.log('Warning: can\'t find abstract op with aoid ' + aoid); | ||
utils.logWarning('can\'t find abstract op with aoid ' + aoid); | ||
} | ||
@@ -111,3 +111,3 @@ | ||
if (clauseEntry.type !== 'clause') { | ||
console.log('Warning: could not find parent clause for ' + type + ' id ' + entry.id); | ||
utils.logWarning('could not find parent clause for ' + type + ' id ' + entry.id); | ||
} | ||
@@ -114,0 +114,0 @@ |
{ | ||
"name": "ecmarkup", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"description": "Custom element definitions and core utilities for markup that specifies ECMAScript and related technologies.", | ||
@@ -36,2 +36,3 @@ "main": "lib/ecmarkup.js", | ||
"bluebird": "^2.6.4", | ||
"chalk": "^1.1.1", | ||
"ecmarkdown": "^3.0.1", | ||
@@ -43,3 +44,4 @@ "grammarkdown": "^0.1.3", | ||
"jsdom": "^5.0.1", | ||
"nomnom": "^1.8.1" | ||
"nomnom": "^1.8.1", | ||
"promise-debounce": "^1.0.1" | ||
}, | ||
@@ -46,0 +48,0 @@ "devDependencies": { |
460195
72
2567
10
+ Addedchalk@^1.1.1
+ Addedpromise-debounce@^1.0.1
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedpromise-debounce@1.0.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)