roll-right 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +467 -219
- package/bin/index.js +181 -93
- package/docs/rr-background.md +35 -0
- package/historical/old_index.js +95 -0
- package/index.js +0 -6
- package/lib/PreStagingSubsitutions.js +64 -0
- package/lib/SkelToTemplate.js +4005 -0
- package/lib/TemplateToPreStaging.js +433 -0
- package/lib/bundle_directives.js +48 -0
- package/lib/html_directives.js +52 -0
- package/lib/mod_utils.js +1 -2
- package/lib/phase1.js +8 -68
- package/lib/phase2.js +13 -11
- package/lib/rr_utils.js +7 -15
- package/lib/sys_utils.js +36 -0
- package/lib/utils.js +350 -42
- package/package.json +10 -7
- package/test/index.js +30 -2
- package/testme.txt +3885 -0
- package/tools/genpage.js +34 -11
- package/tools/subst_to_vars.js +48 -0
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const fos = require('extra-file-class')()
|
|
4
|
+
let ParseUtils = require('../lib/utils')
|
|
5
|
+
let parse_util = new ParseUtils()
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const SkelToTemplate = require('../lib/SkelToTemplate')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @class TemplatesToPreStaging
|
|
12
|
+
*
|
|
13
|
+
* This class extends SkelToTemplate with operations specific to phase 2.
|
|
14
|
+
*
|
|
15
|
+
* This is mostly about creating substitution files and merging them with existing susbt files.
|
|
16
|
+
*
|
|
17
|
+
* Also, the .db files, which are used to make subst file entries, are loaded from specialized
|
|
18
|
+
* templates for the concerns.
|
|
19
|
+
*
|
|
20
|
+
* This phase will generate (** may regenerate) templates after taking into consideration the customization of the db.
|
|
21
|
+
* The db in question is the db generated from entries in the name_drop.db. These db's are called `_calc.db` files
|
|
22
|
+
* since they are made for files::calc entries in the skeleton.
|
|
23
|
+
*
|
|
24
|
+
* A file such as index_calc.db will have entries that are merged into the subst file for the website.
|
|
25
|
+
*
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
class TemplatesToPreStaging extends SkelToTemplate {
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param {object} conf
|
|
34
|
+
*/
|
|
35
|
+
constructor(conf) {
|
|
36
|
+
super(conf)
|
|
37
|
+
this.concern_to_odir = {}
|
|
38
|
+
let outputs = conf.outputs
|
|
39
|
+
if ( outputs && Array.isArray(outputs) ) {
|
|
40
|
+
outputs = JSON.parse(JSON.stringify(outputs))
|
|
41
|
+
for ( let ogroup of outputs ) {
|
|
42
|
+
let dir_form = ogroup.targets.dir_form
|
|
43
|
+
for ( let concern of ogroup.targets.concerns ) {
|
|
44
|
+
this.concern_to_odir[concern] = dir_form.replace("@concern",concern)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param {string} data
|
|
54
|
+
* @returns {Array}
|
|
55
|
+
*/
|
|
56
|
+
find_substitutions_vars(data) {
|
|
57
|
+
let found_vars = {}
|
|
58
|
+
let var_starts = data.split("{{")
|
|
59
|
+
var_starts.shift()
|
|
60
|
+
for ( let dstart of var_starts ) {
|
|
61
|
+
let add_brace = dstart[0] === "{" ? 1 : 0
|
|
62
|
+
let a_var = dstart.substring(0,dstart.indexOf("}}") + add_brace)
|
|
63
|
+
a_var = parse_util.remove_white(a_var)
|
|
64
|
+
found_vars[a_var] = ""
|
|
65
|
+
}
|
|
66
|
+
return found_vars
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
*
|
|
72
|
+
* Loads the top level file concerns named DB, mapping concerns to DB files associated with each template.
|
|
73
|
+
*
|
|
74
|
+
* This method continues on to load all the DB file mentioned in the `concerns_named.db` file.
|
|
75
|
+
*
|
|
76
|
+
* The DB files are the name_drop.db's for each file. e.g. [websites]/@target/@concern/templates/index_calc.db
|
|
77
|
+
*
|
|
78
|
+
*/
|
|
79
|
+
async load_concerns_namer_dbs() {
|
|
80
|
+
//
|
|
81
|
+
let db_locations = `[websites]/${this.project_dir}/concerns_named.db`
|
|
82
|
+
db_locations = this.paths.compile_one_path(db_locations)
|
|
83
|
+
//
|
|
84
|
+
let all_concerns_db = await fos.load_json_data_at_path(db_locations)
|
|
85
|
+
|
|
86
|
+
for ( let files of Object.values(all_concerns_db) ) {
|
|
87
|
+
for ( let file in files ) {
|
|
88
|
+
files[file] = await fos.load_json_data_at_path(file)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
this.all_concerns_namer_db = all_concerns_db
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Phase 2 operation...
|
|
97
|
+
*
|
|
98
|
+
* Analyze data (files) top find variables.
|
|
99
|
+
*
|
|
100
|
+
* Create variable to value objects associated with the files that a concern will
|
|
101
|
+
* require. Make sure the directories that will hold the subst file will exists
|
|
102
|
+
* before the files are created in an ensuing method call.
|
|
103
|
+
*
|
|
104
|
+
* The following applies to the entries of the map that is returned:
|
|
105
|
+
*
|
|
106
|
+
// Prepares an entry for each file in a subdirectory of the concern.
|
|
107
|
+
// A set of variables found in the file will be identified and listed in
|
|
108
|
+
// the *variables* field. The output file is the file to be found in staging.
|
|
109
|
+
// The source directory will likely be the *static* directory which will hold
|
|
110
|
+
// assets used in the site/app pages of the concern. The subst file, containing
|
|
111
|
+
// values and substitution maps for the file to be output will be named here as
|
|
112
|
+
// the 'subst' file.
|
|
113
|
+
|
|
114
|
+
*
|
|
115
|
+
* @param {object} concerns
|
|
116
|
+
* @returns {object}
|
|
117
|
+
*/
|
|
118
|
+
async prepare_files_and_substitutions(concerns) {
|
|
119
|
+
let all_c_vars = {}
|
|
120
|
+
await this.load_concerns_namer_dbs()
|
|
121
|
+
//
|
|
122
|
+
for ( let concern in concerns ) {
|
|
123
|
+
let concerns_dir = `[websites]/${concern}/`
|
|
124
|
+
concerns_dir = this.concern_to_odir[concern]
|
|
125
|
+
concerns_dir = this.paths.dirname(concerns_dir)
|
|
126
|
+
concerns_dir = this.paths.compile_one_path(concerns_dir)
|
|
127
|
+
let targeted_files = Object.values(concerns[concern])
|
|
128
|
+
let concerns_vars = {}
|
|
129
|
+
let concerns_files = {}
|
|
130
|
+
for ( let pair of targeted_files ) {
|
|
131
|
+
let keys = Object.keys(pair)
|
|
132
|
+
//
|
|
133
|
+
for ( let ky of keys ) {
|
|
134
|
+
//
|
|
135
|
+
let afile = `${concerns_dir}/${this.created_dir}${ky}`
|
|
136
|
+
//
|
|
137
|
+
let data = pair[ky]
|
|
138
|
+
if ( (typeof data === "undefined") || (data.length === 0) ) {
|
|
139
|
+
data = await fos.load_data_at_path(afile)
|
|
140
|
+
}
|
|
141
|
+
let data_vars = this.find_substitutions_vars(data)
|
|
142
|
+
//
|
|
143
|
+
// keep adding to the concerns vars, gathering from all the files.
|
|
144
|
+
concerns_vars = Object.assign(concerns_vars,data_vars)
|
|
145
|
+
//
|
|
146
|
+
let subst_src = `${concerns_dir}/static`
|
|
147
|
+
//
|
|
148
|
+
let subst_file = `${subst_src}/${concern}.subst`
|
|
149
|
+
let ofile = `${concerns_dir}/pre-staging/${ky}`
|
|
150
|
+
ofile = ofile.replace(".tmplt",".html")
|
|
151
|
+
//
|
|
152
|
+
// Prepares an entry for each file in a subdirectory of the concern.
|
|
153
|
+
// A set of variables found in the file will be identified and listed in
|
|
154
|
+
// the *variables* field. The output file is the file to be found in staging.
|
|
155
|
+
// The source directory will likely be the *static* directory which will hold
|
|
156
|
+
// assets used in the site/app pages of the concern. The subst file, containing
|
|
157
|
+
// values and substitution maps for the file to be output will be named here as
|
|
158
|
+
// the 'subst' file.
|
|
159
|
+
//
|
|
160
|
+
concerns_files[ky] = {
|
|
161
|
+
"subst" : subst_file,
|
|
162
|
+
"output" : ofile,
|
|
163
|
+
"source_dir" : subst_src,
|
|
164
|
+
"variables" : data_vars
|
|
165
|
+
}
|
|
166
|
+
//
|
|
167
|
+
await fos.ensure_directories(afile,false,true)
|
|
168
|
+
await fos.ensure_directories(subst_file,false,true)
|
|
169
|
+
await fos.ensure_directories(subst_src)
|
|
170
|
+
//
|
|
171
|
+
// load the namer db's generated for each file during phase 1.
|
|
172
|
+
// It is expected by this time.
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// this is the high level directive for substitution on the file.
|
|
176
|
+
// Each concern will map the individual files and will track all the
|
|
177
|
+
// subsitution variables required by the site.
|
|
178
|
+
all_c_vars[concern] = {
|
|
179
|
+
"variables" : concerns_vars,
|
|
180
|
+
"files" : concerns_files
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return all_c_vars
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
*
|
|
189
|
+
* Given all the variables found in a file, for a concern,
|
|
190
|
+
* this method creates JSON structured files (`.subst`)
|
|
191
|
+
* A subst file is created for each file that a concern needs
|
|
192
|
+
* for basic static pages and framework pages.
|
|
193
|
+
*
|
|
194
|
+
* Called by `publish_subs_defs`.
|
|
195
|
+
*
|
|
196
|
+
*
|
|
197
|
+
* @param {string} concern
|
|
198
|
+
* @param {object} var_set
|
|
199
|
+
* @returns {object}
|
|
200
|
+
*/
|
|
201
|
+
get_subst_vars(concern,var_set,var_src_file) {
|
|
202
|
+
let subst_obj = {}
|
|
203
|
+
for ( let avar in var_set ) {
|
|
204
|
+
if ( (avar[0] === '{') || (avar.indexOf(".") > 0) ) {
|
|
205
|
+
let base_var_name = (avar[0] === '{') ? avar.replace('{','').replace('}','') : avar
|
|
206
|
+
//
|
|
207
|
+
let subkeys = false
|
|
208
|
+
if ( avar.indexOf(".") > 0 ) {
|
|
209
|
+
let vpars = base_var_name.split('.')
|
|
210
|
+
base_var_name = vpars.shift()
|
|
211
|
+
subkeys = vpars
|
|
212
|
+
//
|
|
213
|
+
if ( subst_obj[base_var_name] === undefined ) {
|
|
214
|
+
subst_obj[base_var_name] = {}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
//
|
|
218
|
+
let rec = subst_obj[base_var_name]
|
|
219
|
+
if ( (typeof rec === "object") && subkeys.length ) {
|
|
220
|
+
let namer = ""
|
|
221
|
+
let actor = ""
|
|
222
|
+
let file = base_var_name
|
|
223
|
+
while ( subkeys.length ) {
|
|
224
|
+
let ky = subkeys.shift()
|
|
225
|
+
let maybe_rec = rec[ky]
|
|
226
|
+
namer = actor
|
|
227
|
+
actor = file
|
|
228
|
+
file = ky
|
|
229
|
+
if ( maybe_rec === undefined ) {
|
|
230
|
+
maybe_rec = ""
|
|
231
|
+
if ( subkeys.length ) {
|
|
232
|
+
maybe_rec = {}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
rec[ky] = maybe_rec
|
|
236
|
+
rec = maybe_rec
|
|
237
|
+
}
|
|
238
|
+
//
|
|
239
|
+
if ( namer.length && actor.length && file.length ) {
|
|
240
|
+
rec = subst_obj[namer][actor]
|
|
241
|
+
//
|
|
242
|
+
rec.name = namer
|
|
243
|
+
if ( namer.indexOf(actor) > 0 ){
|
|
244
|
+
actor = ""
|
|
245
|
+
}
|
|
246
|
+
actor = parse_util.capitalize(actor)
|
|
247
|
+
rec.file = `${namer}${actor}.txt`
|
|
248
|
+
//
|
|
249
|
+
} else if ( this.namer_in_name_db(concern,base_var_name,var_src_file) ) {
|
|
250
|
+
let [found_name,ftype] = this.lookup_app_assignement(concern,base_var_name,var_src_file)
|
|
251
|
+
subst_obj[base_var_name] = {
|
|
252
|
+
"name" : found_name
|
|
253
|
+
}
|
|
254
|
+
subst_obj[base_var_name][actor] = {
|
|
255
|
+
"file" : `./${found_name}.${ftype}`
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
//
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
subst_obj[avar] = var_set[avar]
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return subst_obj
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* This method uses specific merge rules that fravor the existing data from previous website
|
|
271
|
+
* renditions.
|
|
272
|
+
*
|
|
273
|
+
* @param {object} subst_obj
|
|
274
|
+
* @param {object} existing_subst
|
|
275
|
+
*/
|
|
276
|
+
merge_existing_subst(subst_obj,existing_subst) {
|
|
277
|
+
for ( let ky in existing_subst ) {
|
|
278
|
+
if ( subst_obj[ky] === undefined ) {
|
|
279
|
+
subst_obj[ky] = existing_subst[ky]
|
|
280
|
+
} else {
|
|
281
|
+
if ( (typeof existing_subst[ky] === "object") && (typeof subst_obj[ky] === "object") ) {
|
|
282
|
+
this.merge_existing_subst(subst_obj[ky],existing_subst[ky])
|
|
283
|
+
} else if ( (typeof existing_subst[ky] === "object") && (typeof subst_obj[ky] !== "object") ) {
|
|
284
|
+
subst_obj[ky] = existing_subst[ky]
|
|
285
|
+
} else if ( (typeof existing_subst[ky] === "string") && (typeof subst_obj[ky] === "string") ) {
|
|
286
|
+
if ( existing_subst[ky].length > 0 ) {
|
|
287
|
+
subst_obj[ky] = existing_subst[ky]
|
|
288
|
+
}
|
|
289
|
+
} else if ( (typeof existing_subst[ky] === "string") && (typeof subst_obj[ky] === "object") ) {
|
|
290
|
+
subst_obj[ky].content = existing_subst[ky]
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Makes all the pre-staging subsitution maps needed in order to generate
|
|
299
|
+
* website/app files to be used in production.
|
|
300
|
+
*
|
|
301
|
+
* EXISTING FILES CAN BE USED HERE...
|
|
302
|
+
*
|
|
303
|
+
* @param {object} subst_defs
|
|
304
|
+
*/
|
|
305
|
+
async publish_subs_defs(subst_defs) {
|
|
306
|
+
//
|
|
307
|
+
let concerns_subst_map = {} // each concern will have an entry here.
|
|
308
|
+
//
|
|
309
|
+
for ( let concern in subst_defs ) {
|
|
310
|
+
// set up the map object for the concern
|
|
311
|
+
concerns_subst_map[concern] = {}
|
|
312
|
+
//
|
|
313
|
+
let var_set = subst_defs[concern].variables // get the set of variables in use
|
|
314
|
+
let subst_obj = this.get_subst_vars(concern,var_set) // makes this based on existing template and name_drop db
|
|
315
|
+
//
|
|
316
|
+
let concerns_dir = `[websites]/${concern}/${this.created_dir}`
|
|
317
|
+
concerns_dir = this.concern_to_odir[concern]
|
|
318
|
+
concerns_dir = this.paths.dirname(concerns_dir)
|
|
319
|
+
concerns_dir = this.paths.compile_one_path(concerns_dir)
|
|
320
|
+
let file_path = `${concerns_dir}/${concern}.subst`
|
|
321
|
+
//
|
|
322
|
+
let static_src = `[websites]/${concern}/static/${concern}.subst`
|
|
323
|
+
static_src = this.paths.compile_one_path(static_src)
|
|
324
|
+
let existing_subst = false
|
|
325
|
+
if ( fos.pathExists(static_src) ) {
|
|
326
|
+
existing_subst = await fos.load_json_data_at_path(static_src)
|
|
327
|
+
if ( existing_subst !== false ) {
|
|
328
|
+
this.merge_existing_subst(subst_obj,existing_subst) // does a merge from the created to existing
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
//
|
|
332
|
+
await fos.write_out_pretty_json(file_path,subst_obj,4) // an actual subst file for populating variables across the site
|
|
333
|
+
//
|
|
334
|
+
// The file containing sitewide variable mappings
|
|
335
|
+
// this is the top level entry if specific files don't have one.
|
|
336
|
+
//
|
|
337
|
+
// This is a genneral listing (db) of all variables for all sites
|
|
338
|
+
// and for each file in a site.
|
|
339
|
+
//
|
|
340
|
+
concerns_subst_map[concern][concern] = {
|
|
341
|
+
"path" : file_path,
|
|
342
|
+
"vars" : Object.keys(var_set)
|
|
343
|
+
}
|
|
344
|
+
//
|
|
345
|
+
let files_output = subst_defs[concern].files
|
|
346
|
+
for ( let file in files_output ) {
|
|
347
|
+
let file_focus = files_output[file]
|
|
348
|
+
//
|
|
349
|
+
let var_set = file_focus.variables
|
|
350
|
+
let subst_obj = this.get_subst_vars(concern,var_set,file)
|
|
351
|
+
let file_path = file_focus.output
|
|
352
|
+
file_path = file_path.replace('.html','_html.subst')
|
|
353
|
+
//
|
|
354
|
+
if ( existing_subst !== false ) {
|
|
355
|
+
this.merge_existing_subst(subst_obj,existing_subst)
|
|
356
|
+
}
|
|
357
|
+
//
|
|
358
|
+
file_path = await fos.ensure_directories(file_path,'',true)
|
|
359
|
+
//
|
|
360
|
+
await fos.write_out_pretty_json(file_path,subst_obj,4)
|
|
361
|
+
//
|
|
362
|
+
concerns_subst_map[concern][file] = {
|
|
363
|
+
"path" : file_path,
|
|
364
|
+
"vars" : Object.keys(var_set)
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// write this entire DB
|
|
370
|
+
let subst_map_file = `[websites]/${this.project_dir}/concerns_to_subst_files.json`
|
|
371
|
+
subst_map_file = this.paths.compile_one_path(subst_map_file)
|
|
372
|
+
await fos.write_out_pretty_json(subst_map_file,concerns_subst_map,4)
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* namer is a variable found in the file.
|
|
378
|
+
* namer may be in the namer db of a concern, providing
|
|
379
|
+
* a calculation or a file description that will be kept with in a subst file.
|
|
380
|
+
*
|
|
381
|
+
* called by get_subst_vars
|
|
382
|
+
*
|
|
383
|
+
* @param {string} namer
|
|
384
|
+
* @returns
|
|
385
|
+
*/
|
|
386
|
+
namer_in_name_db(concern,namer,file) {
|
|
387
|
+
if ( file ) {
|
|
388
|
+
let file_prober = file.replace(".tmplt","_calc.db")
|
|
389
|
+
for ( let ky of Object.keys(this.all_concerns_namer_db[concern]) ) {
|
|
390
|
+
if ( ky.indexOf(file_prober) > 0 ) {
|
|
391
|
+
if ( namer in this.all_concerns_namer_db[concern][ky] ) {
|
|
392
|
+
return true
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return false
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
*
|
|
403
|
+
* Looks in all the calc section DBs for a given concern.
|
|
404
|
+
* Within the map of files to sections DBs, this finds the first match for a file name
|
|
405
|
+
* that would hold the a DB key, **namer**. If the file and the object can be found
|
|
406
|
+
* by the sequence of keys, this will return the calc section name (given by an application)
|
|
407
|
+
* and a file type (given by the applications)
|
|
408
|
+
*
|
|
409
|
+
* This method is used by methods generating subtitution maps to be used during phase 3.
|
|
410
|
+
*
|
|
411
|
+
* @param {string} concern -- the name of a concern such as a url or a business name/token
|
|
412
|
+
* @param {string} namer -- a field in the a calc section db, e.g. `about_box`
|
|
413
|
+
* @returns {pair} -- returns the application selected name and file type.
|
|
414
|
+
*/
|
|
415
|
+
lookup_app_assignement(concern,namer,file) {
|
|
416
|
+
if ( file ) {
|
|
417
|
+
let file_prober = file.replace(".tmplt","_calc.db")
|
|
418
|
+
for ( let ky of Object.keys(this.all_concerns_namer_db[concern]) ) {
|
|
419
|
+
if ( ky.indexOf(file_prober) > 0 ) {
|
|
420
|
+
if ( namer in this.all_concerns_namer_db[concern][ky] ) {
|
|
421
|
+
let defs = this.all_concerns_namer_db[concern][ky][namer]
|
|
422
|
+
return [defs.name, defs.content.type]
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return["test","html"]
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
module.exports = TemplatesToPreStaging
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
|
|
2
|
+
const worker_thread_import_scheme = "importScripts('@bundle_name')"
|
|
3
|
+
const main_page_import_scheme = "<script defer src='@bundle_name'></script>"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {string} bundle -- name of the file
|
|
8
|
+
* @param {object} page_or_worker_context
|
|
9
|
+
*/
|
|
10
|
+
function bundle_inclusion_transform(bundle,page_or_worker_context) {
|
|
11
|
+
//
|
|
12
|
+
let btxt = ""
|
|
13
|
+
if ( page_or_worker_context && (page_or_worker_context._page_type === "worker") ) {
|
|
14
|
+
btxt = worker_thread_import_scheme.replace("@bundle_name",bundle)
|
|
15
|
+
} else {
|
|
16
|
+
btxt = main_page_import_scheme.replace("@bundle_name",bundle)
|
|
17
|
+
}
|
|
18
|
+
//
|
|
19
|
+
return "\n" + btxt + "\n"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
module.exports.bundle_inclusion_transform = bundle_inclusion_transform
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const css_link = "<link rel='stylesheet' href='@css_file'>"
|
|
27
|
+
|
|
28
|
+
function link_inclusion_transform(link_spec,page_or_worker_context) {
|
|
29
|
+
let type = 'css'
|
|
30
|
+
link_spec = link_spec.substring(1)
|
|
31
|
+
let link_parts = link_spec.split('>')
|
|
32
|
+
type = link_parts[0]
|
|
33
|
+
let type_file = link_parts[1]
|
|
34
|
+
if ( type_file ) {
|
|
35
|
+
type_file = type_file.replace('::','').trim()
|
|
36
|
+
if ( type === 'css' ) {
|
|
37
|
+
let ltxt = css_link.replace('@css_file',type_file)
|
|
38
|
+
return "\n" + ltxt + "\n"
|
|
39
|
+
} else {
|
|
40
|
+
return ""
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//
|
|
44
|
+
return ""
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
module.exports.link_inclusion_transform = link_inclusion_transform
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
let html_start_doc_head = `
|
|
4
|
+
<!doctype html>
|
|
5
|
+
<html>
|
|
6
|
+
<head>
|
|
7
|
+
`
|
|
8
|
+
|
|
9
|
+
let end_body_html = `
|
|
10
|
+
</body>
|
|
11
|
+
</html>
|
|
12
|
+
`
|
|
13
|
+
|
|
14
|
+
let end_head = `
|
|
15
|
+
</head>
|
|
16
|
+
`
|
|
17
|
+
|
|
18
|
+
let start_style = `
|
|
19
|
+
<style>
|
|
20
|
+
`
|
|
21
|
+
|
|
22
|
+
let end_style = `
|
|
23
|
+
</style>
|
|
24
|
+
`
|
|
25
|
+
|
|
26
|
+
let start_script = `
|
|
27
|
+
<script lang="JavaScript" >
|
|
28
|
+
`
|
|
29
|
+
|
|
30
|
+
let end_script = `
|
|
31
|
+
</script>
|
|
32
|
+
`
|
|
33
|
+
|
|
34
|
+
let start_body = `
|
|
35
|
+
<body>
|
|
36
|
+
`
|
|
37
|
+
|
|
38
|
+
let base_patterns_mod = {
|
|
39
|
+
"html:" : {
|
|
40
|
+
"start_doc_head" : html_start_doc_head,
|
|
41
|
+
'end_head': end_head,
|
|
42
|
+
'start_style': start_style,
|
|
43
|
+
'end_style': end_style,
|
|
44
|
+
'start_script': start_script,
|
|
45
|
+
'end_script': end_script,
|
|
46
|
+
'start_body': start_body,
|
|
47
|
+
'end_body_html': end_body_html
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
module.exports.base_patterns_mod = base_patterns_mod
|
package/lib/mod_utils.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
const fs = require('fs')
|
|
3
|
-
const
|
|
4
|
-
const {load_json_file,array_flatten} = require('../lib/utils')
|
|
3
|
+
const {load_json_file} = require('../lib/utils')
|
|
5
4
|
const {execSync} = require('child_process')
|
|
6
5
|
const {translate_marker} = require('../lib/utils')
|
|
7
6
|
|
package/lib/phase1.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
const
|
|
2
|
+
const fos = require('extra-file-class')()
|
|
3
|
+
|
|
3
4
|
const path = require('path')
|
|
4
|
-
const
|
|
5
|
-
const {translate_marker} = require('../lib/utils')
|
|
5
|
+
const {translate_marker,mapify,find_map,key_map_sub} = require('../lib/utils')
|
|
6
6
|
|
|
7
7
|
//$$files::header.html<<
|
|
8
8
|
const g_inserts_match = /\$\$files\:\:(\w|_|-|\+)+\/*(\w|_|-|\+)+\.(\w|_|-\+)+\<\</g
|
|
@@ -11,66 +11,6 @@ const g_names_inserts_match = /\$\$files\:\:name\:\:(\w|_|-|\+)+\/*(\w|_|-|\+)+\
|
|
|
11
11
|
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
|
|
12
12
|
//
|
|
13
13
|
|
|
14
|
-
function subst(fdata,key,value) {
|
|
15
|
-
while ( fdata.indexOf(key) >= 0 ) {
|
|
16
|
-
fdata = fdata.replace(key,value)
|
|
17
|
-
}
|
|
18
|
-
return fdata
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function mapify(a1,a2,key_edit) {
|
|
23
|
-
let the_map = {}
|
|
24
|
-
let n = a1.length
|
|
25
|
-
if ( typeof key_edit === 'function' ) {
|
|
26
|
-
for ( let i = 0; i < n; i++ ) {
|
|
27
|
-
let ky = key_edit(a1[i])
|
|
28
|
-
the_map[ky] = a2[i]
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
for ( let i = 0; i < n; i++ ) {
|
|
32
|
-
the_map[a1[i]] = a2[i]
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return the_map
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
function find_map(part_form,the_map) {
|
|
40
|
-
|
|
41
|
-
let key = part_form.substr(0,part_form.indexOf("<<")).trim()
|
|
42
|
-
if ( key.length === 0 ) {
|
|
43
|
-
//console.log(part_form)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let data = the_map[key]
|
|
47
|
-
|
|
48
|
-
return[key,data]
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
function key_map_sub(file_data,key_values,vars) {
|
|
54
|
-
let fdata = '' + file_data
|
|
55
|
-
for ( let key in key_values ) {
|
|
56
|
-
let value = key_values[key]
|
|
57
|
-
if ( value[0] === '>' ) {
|
|
58
|
-
let varname = value.substr(1)
|
|
59
|
-
let i = vars.indexOf(varname)
|
|
60
|
-
if ( i >= 0 ) {
|
|
61
|
-
value = vars.substr(i + varname.length + '::'.length)
|
|
62
|
-
if ( value.indexOf('::') > 0 ) {
|
|
63
|
-
value = value.substr(0,value.indexOf('::'))
|
|
64
|
-
}
|
|
65
|
-
value = value.trim()
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
fdata = subst(fdata,`$$${key}`,value)
|
|
69
|
-
}
|
|
70
|
-
//
|
|
71
|
-
return fdata
|
|
72
|
-
}
|
|
73
|
-
|
|
74
14
|
|
|
75
15
|
|
|
76
16
|
function windows_module(file_data) {
|
|
@@ -145,7 +85,7 @@ function sub_file_replace(file_data,defs,conf) {
|
|
|
145
85
|
for ( let file in defs ) {
|
|
146
86
|
try {
|
|
147
87
|
let the_file = alphas_file_paths(file,conf)
|
|
148
|
-
let sub_file =
|
|
88
|
+
let sub_file = fos.readFileSync(the_file).toString()
|
|
149
89
|
let marker = `$$file::${file}<<`
|
|
150
90
|
file_data = file_data.replace(marker,sub_file)
|
|
151
91
|
} catch(e) {
|
|
@@ -159,7 +99,7 @@ function sub_file_replace(file_data,defs,conf) {
|
|
|
159
99
|
function sub_file_processing(clean_key,file_def,conf) {
|
|
160
100
|
let the_file = alphas_file_paths(clean_key,conf)
|
|
161
101
|
try {
|
|
162
|
-
let file_data =
|
|
102
|
+
let file_data = fos.readFileSync(the_file).toString()
|
|
163
103
|
if ( typeof file_def === 'object' ) {
|
|
164
104
|
file_data = sub_file_replace(file_data,file_def,conf)
|
|
165
105
|
}
|
|
@@ -196,7 +136,7 @@ function named_replacer_replacement(key_string,conf,file_key) {
|
|
|
196
136
|
the_file = translate_marker(the_file,conf)
|
|
197
137
|
}
|
|
198
138
|
try {
|
|
199
|
-
let file_data =
|
|
139
|
+
let file_data = fos.readFileSync(the_file).toString()
|
|
200
140
|
//
|
|
201
141
|
if ( typeof named_file_def.key_values === 'object' ) {
|
|
202
142
|
file_data = key_map_sub(file_data,named_file_def.key_values,clean_key)
|
|
@@ -312,7 +252,7 @@ function load_scripts(conf,file_key) {
|
|
|
312
252
|
the_file = translate_marker(the_file,conf)
|
|
313
253
|
}
|
|
314
254
|
try {
|
|
315
|
-
let file_data =
|
|
255
|
+
let file_data = fos.readFileSync(the_file).toString()
|
|
316
256
|
let m_file_key = `script::${clean_key}`
|
|
317
257
|
//
|
|
318
258
|
let script_filters = script_list[clean_key]
|
|
@@ -340,7 +280,7 @@ class Phase1 {
|
|
|
340
280
|
}
|
|
341
281
|
|
|
342
282
|
ensure_directory(out_dir,target) {
|
|
343
|
-
|
|
283
|
+
fos.ensureDirSync(`${out_dir}/${target}`)
|
|
344
284
|
}
|
|
345
285
|
|
|
346
286
|
|