1
- Notes go here
1
+ pp.js
2
+
3
+ Purpose:
4
+
5
+ This preprocessor is used to build JavaScript files together into a single file
6
+ while enabling various features.
7
+
8
+ I have elected to provide a suset of what the original C preprocessor does. I choose
9
+ to implement in nodejs because I am trying to learn node. I am in the middle of
10
+ building a couple of projects and found I have a need to frequently do this kind
11
+ of manipulation and my tools were limited.
12
+
13
+ Guiding principles:
14
+ 1) Unobtusive, I did not want any positional sensitivity so my code was still easy
15
+ to read.
16
+ 2) I wanted to use a marker that would not interfere with javascript in any way
17
+ 3) I wanted to easily see what file and what code was in effect and what was left
18
+ out
19
+ 4) I wanted to prevent infinite loops through inclusion
20
+ 5) A single source file could produce output suitable for testing, production,
21
+ and other environments
22
+
23
+ Commands:
24
+ Commands are not case sensitive, files names may be. Defined variable are case sensitive.
25
+ Commands are placed anywhere on a line they do no have to appear in the first column
26
+ Commands cannot follow code on the same line.
27
+ A processed file comments out the commands so they will not work. So the following
28
+ becomes:
29
+
30
+ //@include somefile.js -> // //@include somefile.js
31
+
32
+ e.g. Valid
33
+ //@include sample.js
34
+ //@include sample.js
35
+
36
+ The commands for the preprocessor are:
37
+ //@include filename.js
38
+
39
+ The include command will only a file to be included one. Please note that a comment
40
+ line will be inserted into the output file to indicate the source file. A check
41
+ is done to ensure that the same include file is not used more than once. pp.js will
42
+ throw an error if the same include sime is attempted in a single job.
43
+
44
+ //@define var,var,var
45
+
46
+ The define command creates a variable. Unlike the C preprocessor you cannot assign
47
+ a value. All test are simply for existance. More than one define can be done
48
+ at a time.
49
+
50
+ //@if var,var,var
51
+
52
+ The if command checks for the existance of a given variable. If more than one is
53
+ specified then the result is OR'd together. Which just means if one is define its
54
+ true.
55
+
56
+ //@else
57
+
58
+ Hopefully self explainitory.
59
+
60
+ //@endif
61
+
62
+ Hopefully self explainitory.
63
+
64
+ How to use:
65
+
66
+ usage: node pp.js with the following options
67
+
68
+ Source file(s) e.g. --src=file1.js,file2.js
69
+ --src *required
70
+ Destination to write the file e.g. --dst=output.js
71
+ --dst *required
72
+ Definition(s) to create e.g. --def=DEBUG,NODE,BROWSER
73
+ --def
74
+ Enable Debugging
75
+ --debug
76
+ Help. This Message.
77
+ --help
78
+
79
+ Tests:
80
+
81
+ Sample test file in:
82
+ FILE: test.js
83
+ /*
84
+ * a simple test of the if endif logic
85
+ *
86
+ */
87
+ //@define Hello
88
+
89
+ //@if Hello
90
+ This should show
91
+ //@else
92
+ This should be commented
93
+ //@endif
94
+
95
+ //@include nestedfile3.js
96
+
97
+ //@if DEBUG
98
+ This should be commented
99
+ //@else
100
+ This should show
101
+ //@endif
102
+
103
+ //@if DEBUG
104
+ //@if WIRE
105
+ This should be commented
106
+ //@else
107
+ This should be commented (because its nested out)
108
+ //@endif
109
+ //@else
110
+ This should show
111
+ //@endif
112
+
113
+ //@if DEBUG
114
+ This should be commented
115
+ //@endif
116
+ //@if DEBUG
117
+ //@include nofile.js
118
+ //@endif
119
+
120
+ FILE: nestedfile3.js
121
+ This is the nested file 3
122
+
123
+ //@if Hello
124
+ This should show
125
+ //@endif
126
+
127
+ Command
128
+
129
+ Result
130
+ /*
131
+ * a simple test of the if endif logic
132
+ *
133
+ */
134
+ // //@define Hello
135
+
136
+ // //@if Hello
137
+ This should show
138
+ // //@else
139
+ // This should be commented
140
+ // //@endif
141
+
142
+ // //@include nestedfile3.js
143
+
144
+ // //@if DEBUG
145
+ // This should be commented
146
+ // //@else
147
+ // This should show
148
+ // //@endif
149
+
150
+ // //@if DEBUG
151
+ // //@if WIRE
152
+ // This should be commented
153
+ // //@else
154
+ // This should be commented (because its nested out)
155
+ // //@endif
156
+ // //@else
157
+ This should show
158
+ // //@endif
159
+
160
+ // //@if DEBUG
161
+ // This should be commented
162
+ // //@endif
163
+ // //@if DEBUG
164
+ // //@include nofile.js
165
+ // //@endif
166
+
167
+ How to install:
168
+
169
+ npm install Node-JavaScript-Preprocessor
170
+
0 commit comments