-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathREADME
More file actions
172 lines (132 loc) · 3.88 KB
/
README
File metadata and controls
172 lines (132 loc) · 3.88 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
Purpose:
This preprocessor is used to build JavaScript files together into a single file
while enabling various features.
I have elected to provide a suset of what the original C preprocessor does. I choose
to implement in nodejs because I am trying to learn node. I am in the middle of
building a couple of projects and found I have a need to frequently do this kind
of manipulation and my tools were limited.
Guiding principles:
1) Unobtusive, I did not want any positional sensitivity so my code was still easy
to read.
2) I wanted to use a marker that would not interfere with javascript in any way
3) I wanted to easily see what file and what code was in effect and what was left
out
4) I wanted to prevent infinite loops through inclusion
5) A single source file could produce output suitable for testing, production,
and other environments
Commands:
Commands are not case sensitive, files names may be. Defined variable are case sensitive.
Commands are placed anywhere on a line they do no have to appear in the first column
Commands cannot follow code on the same line.
A processed file comments out the commands so they will not work. So the following
becomes:
//@include somefile.js -> // //@include somefile.js
e.g. Valid
//@include sample.js
//@include sample.js
The commands for the preprocessor are:
//@include filename.js
The include command will only a file to be included one. Please note that a comment
line will be inserted into the output file to indicate the source file. A check
is done to ensure that the same include file is not used more than once. pp.js will
throw an error if the same include sime is attempted in a single job.
//@define var,var,var
The define command creates a variable. Unlike the C preprocessor you cannot assign
a value. All test are simply for existance. More than one define can be done
at a time.
//@if var,var,var
The if command checks for the existance of a given variable. If more than one is
specified then the result is OR'd together. Which just means if one is define its
true.
//@else
Hopefully self explainitory.
//@endif
Hopefully self explainitory.
How to use:
usage: npm start Node-JavaScript-Preprocessor with the following options
Source file(s) e.g. --src=file1.js,file2.js
--src *required
Destination to write the file e.g. --dst=output.js
--dst *required
Definition(s) to create e.g. --def=DEBUG,NODE,BROWSER
--def
Enable Debugging
--debug
Help. This Message.
--help
Tests:
Sample test file in:
FILE: test.js
/*
* a simple test of the if endif logic
*
*/
//@define Hello
//@if Hello
This should show
//@else
This should be commented
//@endif
//@include nestedfile3.js
//@if DEBUG
This should be commented
//@else
This should show
//@endif
//@if DEBUG
//@if WIRE
This should be commented
//@else
This should be commented (because its nested out)
//@endif
//@else
This should show
//@endif
//@if DEBUG
This should be commented
//@endif
//@if DEBUG
//@include nofile.js
//@endif
FILE: nestedfile3.js
This is the nested file 3
//@if Hello
This should show
//@endif
Command
Result
/*
* a simple test of the if endif logic
*
*/
// //@define Hello
// //@if Hello
This should show
// //@else
// This should be commented
// //@endif
// //@include nestedfile3.js
// //@if DEBUG
// This should be commented
// //@else
// This should show
// //@endif
// //@if DEBUG
// //@if WIRE
// This should be commented
// //@else
// This should be commented (because its nested out)
// //@endif
// //@else
This should show
// //@endif
// //@if DEBUG
// This should be commented
// //@endif
// //@if DEBUG
// //@include nofile.js
// //@endif
How to install:
npm install Node-JavaScript-Preprocessor
To run:
npm start Node-JavaScript-Preprocessor