forked from ResponsiveImagesCG/picture-element
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.js
executable file
·71 lines (64 loc) · 2.33 KB
/
gen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env node
var sys = require('sys'),
fs = require("fs"),
path = require('path'),
exec = require('child_process').exec,
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
today = new Date(),
pubdate = today.getDate() + ' ' + months[today.getMonth()] + ' ' + today.getFullYear(),
filter = '.w3c',
shortName = path.basename(process.cwd()),
output = 'index.html',
pubDir = process.cwd() + '/pub',
argv = require('optimist')
.usage('Usage: $0 [--w3c] [--pubdate \"dd Mon yyy\"] [--type ED|WD|CR|PR|REC]')
.default('pubdate', pubdate)
.default('type', 'ED')
.default('name', shortName)
.argv,
child, anolis;
if (argv.hasOwnProperty('w3c') && argv.w3c) {
//default to Working Draft
if (argv.type === 'ED') {
argv.type = 'WD';
}
//Take out all RICG stuff if we are targetting W3C
filter = '.ricg';
//e.g., "WD_21Dec2012.html"
output = 'pub/' + argv.type + '_' + argv.pubdate.split(' ').join('') + '.html';
//check that we have a pub directory
if(fs.existsSync(pubDir) === false){
fs.mkdirSync(pubDir);
}
}
anolis = 'anolis --w3c-compat --output-encoding=utf8' +
' --omit-optional-tags --quote-attr-values' +
' --w3c-status=' + argv.type +
' --pubdate=\"' + argv.pubdate + '\"'+
' --w3c-shortname=' + argv.name +
' --filter=\"'+ filter + '\"'+
' index.src.html ' + output;
exec(anolis, function(error, stdout, stderr) {
if (error) {
console.log('Something went wrong', error, stdout, stderr);
return;
}
showNotification();
});
function showNotification() {
var hasNotifier = 'command -v terminal-notifier >/dev/null 2>&1';
exec(hasNotifier, function(error, stdout, stderr) {
var command;
//No notifier, so abort
if (error !== null) {
console.log('Missing optional dependency: sudo gem install terminal-notifier');
return;
}
command = 'terminal-notifier '+
'-message \"Finished processing document.\" '+
'-title \"Anolis Processing done\" '+
'-execute \"open '+ process.cwd() + '/'+ output + '\" '+
'-group \"Anolis\"';
exec(command);
});
}