-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbin
More file actions
executable file
·96 lines (76 loc) · 2.29 KB
/
bin
File metadata and controls
executable file
·96 lines (76 loc) · 2.29 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env node
var core = require('canner-core');
var argv = require('minimist')(process.argv.slice(2));
var fs = require('fs-extra');
var path = require('path');
var load = argv._[0];
var project = argv._[1];
var w = argv.w;
var minify = argv.m;
var i;
var twstat = {};
twstat.build = function(load, w) {
var json_root = path.dirname(load);
var posts = require(path.resolve(process.cwd(), load));
if(!w) {
// build
fn = core.build(posts, {
cwd: json_root,
output: json_root,
minify: minify
});
} else {
// watch
fn = core.watch(posts, {
cwd: json_root,
serve: json_root,
output: json_root,
minify: minify,
reloader: function() {
return posts;
}
});
}
};
twstat.init = function(load, project) {
var list_path = path.join(process.cwd(), 'lists.json');
var lists = require(list_path);
lists.data.page.unshift({
"title": project,
"url": project,
"img": "images/" + project + ".png",
"description": "Project description",
"author": "Your Name"
});
var new_file = path.join(process.cwd(), project, 'index.hbs');
var js = path.join(process.cwd(), project, 'js', 'index.js');
var css = path.join(process.cwd(), project, 'css','style.css');
if(!fs.existsSync(new_file)) {
fs.copy(path.join(__dirname, './init/init.hbs'), new_file, function(err) {
if(err) return console.error(err);
});
fs.copy(path.join(__dirname, './init/js/index.js'), js, function(err) {
if(err) return console.error(err);
});
fs.copy(path.join(__dirname, './init/css/style.css'), css, function(err) {
if(err) return console.error(err);
});
}
console.log('Init your project: ' + new_file);
fs.writeFileSync(list_path, JSON.stringify(lists, null, 2));
console.log('Add your project to lists.json: ' + list_path);
};
if(load === 'init' && project) {
// init project
twstat.init(load, project);
} else if (load === 'init' && !project) {
console.log("Usage: twstat init <project name>");
} else {
if (path.extname(load) === '.js' && w) {
twstat.build(load, w);
} else if (path.extname(load) === '.js' && !w) {
twstat.build(load);
} else {
console.log("Usage: twstat <twstat configuration file>");
}
}