1
+ #!/usr/bin/env node
2
+
3
+ const fs = require ( 'fs' ) ;
4
+ const path = require ( 'path' ) ;
5
+
6
+ const setup = require ( './setup.js' ) ;
7
+ const build = require ( './build.js' ) ;
8
+
9
+ // get script arguments
10
+ const args = process . argv . slice ( 2 ) ;
11
+
12
+ // get zine path from arguments
13
+ const zinePath = args . shift ( ) ;
14
+ if ( ! zinePath ) {
15
+ console . error ( 'Missing zine name!' ) ;
16
+ }
17
+
18
+ const cmd = args . shift ( ) ;
19
+ if ( ! cmd ) {
20
+ console . error ( 'Missing command for the script!' ) ;
21
+ }
22
+
23
+ const cssPath = path . join ( zinePath , 'css' ) ;
24
+ const partialsPath = path . join ( zinePath , 'partials' ) ;
25
+
26
+ // watch partials and CSS files for changes, rebuild
27
+ const watch = ( ) => {
28
+ console . log ( '\nWatching build files' ) ;
29
+ fs . watch ( partialsPath , ( event , file ) => {
30
+ console . log ( `Changes in: ${ file } ` ) ;
31
+ build . build ( zinePath , partialsPath , cssPath ) ;
32
+ } ) ;
33
+ fs . watch ( cssPath , ( event , file ) => {
34
+ console . log ( `Changes in: ${ file } ` ) ;
35
+ build . build ( zinePath , partialsPath , cssPath ) ;
36
+ } )
37
+ }
38
+
39
+ switch ( cmd ) {
40
+ // set up the directory for the zine
41
+ case 'setup' :
42
+ setup . setup ( zinePath , partialsPath , cssPath ) ;
43
+ break ;
44
+ // build zine files
45
+ case 'build' :
46
+ build . build ( zinePath , partialsPath , cssPath ) ;
47
+ break ;
48
+ // watch and build on changes
49
+ case 'dev' :
50
+ build . build ( zinePath , partialsPath , cssPath ) ;
51
+ watch ( ) ;
52
+ break ;
53
+ default :
54
+ console . error ( `Error: Command ${ cmd } not implemented!` )
55
+ break ;
56
+ }
57
+
58
+
59
+
60
+ // console.log(process.argv.slice(2));
61
+ // text.split(/\r?\n/).forEach(function (line) {
62
+ // console.log(line);
63
+ // });
64
+ // const text = fs.readFileSync('kitten', "utf8");
65
+ // fs.appendFileSync('kitten', '456', 'utf8');
66
+ // remove previous output file before generating (not necessary, overwritten)
67
+ // fs.unlinkSync(indexFile);
68
+
69
+ // const zineDir = path.parse(zinePath);
70
+ // const outputFile = zinePath.name();
0 commit comments