roll-right 0.1.3 → 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/breakup.js +0 -1
- 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 +16 -70
- 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
package/lib/phase2.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
const {spawn} = require('child_process')
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
const {gsubst} = require('../lib/utils')
|
|
5
|
+
|
|
6
|
+
const {PathManager} = require('extra-file-class')
|
|
7
|
+
const fos = require('extra-file-class')()
|
|
4
8
|
|
|
5
9
|
|
|
6
10
|
// node genpage.js ${top_level}/${dir}/static/${dir}.subst ../templates/index.html ${top_level}/${dir}/index.html
|
|
@@ -10,32 +14,30 @@ class Phase2 {
|
|
|
10
14
|
constructor(target,target_conf) {
|
|
11
15
|
this.tconf = target_conf
|
|
12
16
|
this._target = target
|
|
17
|
+
this.pm = new PathManager(conf)
|
|
13
18
|
}
|
|
14
19
|
|
|
15
|
-
ensure_directory(out_dir,target) {
|
|
16
|
-
fs.ensureDirSync(`${out_dir}/${target}`)
|
|
17
|
-
}
|
|
18
20
|
|
|
19
21
|
config(tconf,target) {
|
|
20
22
|
let static_artifacts = tconf.static_artifacts
|
|
21
23
|
let where_is_subst_file = `${static_artifacts}/${target}.subst`
|
|
22
24
|
where_is_subst_file = gsubst(where_is_subst_file,'$$target',target)
|
|
23
|
-
where_is_subst_file = translate_marker(where_is_subst_file,tconf)
|
|
25
|
+
where_is_subst_file = this.pm.translate_marker(where_is_subst_file,tconf)
|
|
24
26
|
//
|
|
25
27
|
let where_is_template_file = tconf.template
|
|
26
28
|
where_is_template_file = gsubst(where_is_template_file,'$$target',target)
|
|
27
|
-
where_is_template_file = translate_marker(where_is_template_file,tconf)
|
|
29
|
+
where_is_template_file = this.pm.translate_marker(where_is_template_file,tconf)
|
|
28
30
|
//
|
|
29
31
|
let derived_output_file_name = tconf.template.substr(tconf.template.lastIndexOf('/'))
|
|
30
32
|
//
|
|
31
33
|
let where_does_output_go = tconf.out_dir
|
|
32
34
|
where_does_output_go = gsubst(where_does_output_go,'$$target',target)
|
|
33
|
-
where_does_output_go = translate_marker(where_does_output_go,tconf)
|
|
35
|
+
where_does_output_go = this.pm.translate_marker(where_does_output_go,tconf)
|
|
34
36
|
where_does_output_go += derived_output_file_name
|
|
35
37
|
//
|
|
36
38
|
let where_are_scripts = tconf.scripts_dir
|
|
37
39
|
where_are_scripts = gsubst(where_are_scripts,'$$target',target)
|
|
38
|
-
where_are_scripts = translate_marker(where_are_scripts,tconf) + '/tools'
|
|
40
|
+
where_are_scripts = this.pm.translate_marker(where_are_scripts,tconf) + '/tools'
|
|
39
41
|
|
|
40
42
|
console.log("----------------")
|
|
41
43
|
console.log("subst: " + where_is_subst_file)
|
|
@@ -63,8 +65,8 @@ class Phase2 {
|
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
run() {
|
|
66
|
-
let out_dir = translate_marker(this.tconf.out_dir,this.tconf)
|
|
67
|
-
|
|
68
|
+
let out_dir = this.pm.translate_marker(this.tconf.out_dir,this.tconf)
|
|
69
|
+
fos.ensure_directory(out_dir,this._target)
|
|
68
70
|
this.config(this.tconf,this._target,this.tconf.template)
|
|
69
71
|
}
|
|
70
72
|
|
package/lib/rr_utils.js
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
const fs = require('fs')
|
|
3
3
|
const path = require('path')
|
|
4
|
-
const
|
|
4
|
+
const fos = require('extra-file-class')()
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
try {
|
|
10
|
-
let stat = fs.lstatSync(path);
|
|
11
|
-
return stat.isDirectory();
|
|
12
|
-
} catch (e) {
|
|
13
|
-
// lstatSync throws an error if path doesn't exist
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
7
|
+
const {array_flatten} = require('../lib/utils')
|
|
8
|
+
|
|
17
9
|
|
|
18
10
|
function load_package_json(pars) {
|
|
19
11
|
let file_path = `${pars}/package.json`
|
|
@@ -36,7 +28,7 @@ const _browser_code_access = (pars,subdirs,topdir) => {
|
|
|
36
28
|
let file_content = dirlist.map(file_name => {
|
|
37
29
|
let file_path = client_code_path + '/' + file_name
|
|
38
30
|
let content = ""
|
|
39
|
-
if ( !(
|
|
31
|
+
if ( !(fsoc.is_dirSync(file_path)) ) {
|
|
40
32
|
if ( path.extname(file_path) in g_permit_paths ) {
|
|
41
33
|
content = fs.readFileSync(file_path).toString()
|
|
42
34
|
return { file_path, content }
|
|
@@ -83,7 +75,7 @@ function check_sub_deps(dep,dependencies) {
|
|
|
83
75
|
|
|
84
76
|
|
|
85
77
|
// // transfer_node_module_browser_version
|
|
86
|
-
module.exports.transfer_node_module_browser_version = (source_spec) => {
|
|
78
|
+
module.exports.transfer_node_module_browser_version = async (source_spec) => {
|
|
87
79
|
let check_file = source_spec.file
|
|
88
80
|
let out_dir = source_spec.out_dir
|
|
89
81
|
let missing_dependencies = []
|
|
@@ -91,7 +83,7 @@ module.exports.transfer_node_module_browser_version = (source_spec) => {
|
|
|
91
83
|
// need to do this... node does not look at the current working directory
|
|
92
84
|
module.paths.unshift(`${process.cwd()}/node_modules`)
|
|
93
85
|
//
|
|
94
|
-
let package_file =
|
|
86
|
+
let package_file = fos.load_json_data_at_path(check_file)
|
|
95
87
|
for ( let dep of source_spec.dependencies ) {
|
|
96
88
|
if ( ((typeof dep === 'string') && package_file.dependencies[dep]) || (dep = check_sub_deps(dep,package_file.dependencies)) ) {
|
|
97
89
|
console.log(dep + " :: " + package_file.dependencies[dep])
|
|
@@ -107,7 +99,7 @@ module.exports.transfer_node_module_browser_version = (source_spec) => {
|
|
|
107
99
|
for ( let codes of code_list ) {
|
|
108
100
|
let { file_path, content } = codes
|
|
109
101
|
if ( file_path.indexOf("package.json") >= 0 ) {
|
|
110
|
-
let mod_pack =
|
|
102
|
+
let mod_pack = await fos.load_json_data_at_path(file_path)
|
|
111
103
|
let deps = mod_pack.dependencies
|
|
112
104
|
package_file.dependencies = Object.assign({},package_file.dependencies,deps)
|
|
113
105
|
} else {
|
package/lib/sys_utils.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
const {spawn} = require('child_process')
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SysUtils {
|
|
7
|
+
|
|
8
|
+
constructor(conf) {
|
|
9
|
+
let where_are_scripts = conf.tools_directory
|
|
10
|
+
this.generator_program = `${where_are_scripts}/genpage.js`
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
spawn_generator(where_is_subst_file, where_is_template_file, where_does_output_go,where_is_static_dir) {
|
|
15
|
+
//
|
|
16
|
+
let spawner = spawn("node",[this.generator_program, where_is_subst_file, where_is_template_file, where_does_output_go, where_is_static_dir])
|
|
17
|
+
|
|
18
|
+
spawner.stdout.on('data', (data) => {
|
|
19
|
+
console.log(`stdout: ${data}`);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
spawner.stderr.on('data', (data) => {
|
|
23
|
+
console.error(`stderr: ${data}`);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
spawner.on('close', (code) => {
|
|
27
|
+
console.log(`child process exited with code ${code}`);
|
|
28
|
+
});
|
|
29
|
+
//
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
module.exports = SysUtils
|
package/lib/utils.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
|
-
const untildify = require('untildify')
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
/**
|
|
4
|
+
* subst
|
|
5
|
+
*
|
|
6
|
+
* Calls String.replace sequentially until no instances of the pattern are left.
|
|
7
|
+
* Puts the value in place of the pattern.
|
|
8
|
+
*
|
|
9
|
+
* Returns the string
|
|
10
|
+
*
|
|
11
|
+
* @param {string} str
|
|
12
|
+
* @param {string} pattern
|
|
13
|
+
* @param {string} value
|
|
14
|
+
* @returns string
|
|
15
|
+
*/
|
|
16
|
+
function subst(str,pattern,value) {
|
|
18
17
|
let i = str.indexOf(pattern)
|
|
19
18
|
let j = 0
|
|
20
19
|
while ( i >= 0 ) {
|
|
@@ -26,7 +25,17 @@ module.exports.gsubst = (str,pattern,value) => {
|
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* recursive_flat
|
|
31
|
+
*
|
|
32
|
+
* Takes in an array whose elements are either atoms or arrays.
|
|
33
|
+
* The structure is assumed to be recursive and have some max depth
|
|
34
|
+
* not checked by this method.
|
|
35
|
+
*
|
|
36
|
+
* @param {Array} ary
|
|
37
|
+
* @returns Array
|
|
38
|
+
*/
|
|
30
39
|
function recursive_flat(ary) {
|
|
31
40
|
if ( Array.isArray(ary) ) {
|
|
32
41
|
let outary = []
|
|
@@ -44,7 +53,16 @@ function recursive_flat(ary) {
|
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
|
|
47
|
-
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* array_flatten
|
|
59
|
+
*
|
|
60
|
+
* A top level call for `recursive_flat`
|
|
61
|
+
*
|
|
62
|
+
* @param {Array} items_array
|
|
63
|
+
* @returns Array
|
|
64
|
+
*/
|
|
65
|
+
function array_flatten(items_array) {
|
|
48
66
|
let final_array = []
|
|
49
67
|
for ( let item of items_array ) {
|
|
50
68
|
if ( !Array.isArray(item) ) {
|
|
@@ -57,41 +75,331 @@ module.exports.array_flatten = (items_array) => {
|
|
|
57
75
|
return final_array
|
|
58
76
|
}
|
|
59
77
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* mapify
|
|
81
|
+
*
|
|
82
|
+
* Given two arrays creates an object whose keys are the to be found in the first array and the values in the second.
|
|
83
|
+
*
|
|
84
|
+
* The method uses all the keys and as many values found at the front of the array.
|
|
85
|
+
* It is possible that the value array will be longer than the keys. If the value array is short,
|
|
86
|
+
* then key will map to 'undefined'.
|
|
87
|
+
*
|
|
88
|
+
*
|
|
89
|
+
*
|
|
90
|
+
* @param {Array} a1
|
|
91
|
+
* @param {Array} a2
|
|
92
|
+
* @param {Function} key_edit
|
|
93
|
+
*
|
|
94
|
+
* @returns Object
|
|
95
|
+
*/
|
|
96
|
+
function mapify(a1,a2,key_edit) {
|
|
97
|
+
let the_map = {}
|
|
98
|
+
let n = a1.length
|
|
99
|
+
if ( typeof key_edit === 'function' ) {
|
|
100
|
+
for ( let i = 0; i < n; i++ ) {
|
|
101
|
+
let ky = key_edit(a1[i])
|
|
102
|
+
the_map[ky] = a2[i]
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
for ( let i = 0; i < n; i++ ) {
|
|
106
|
+
the_map[a1[i]] = a2[i]
|
|
107
|
+
}
|
|
64
108
|
}
|
|
65
|
-
return
|
|
109
|
+
return the_map
|
|
66
110
|
}
|
|
67
111
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* find_map
|
|
115
|
+
*
|
|
116
|
+
* This is for an application that takes in a string that is expected to have
|
|
117
|
+
* a delimeter marking the end of the prefix (or first part) of the string.
|
|
118
|
+
*
|
|
119
|
+
* It pulls of the prefix and uses it as a key into the map to get stored data.
|
|
120
|
+
*
|
|
121
|
+
* This returns key and data as a pair.
|
|
122
|
+
*
|
|
123
|
+
* default "<<"
|
|
124
|
+
*
|
|
125
|
+
* @param {string} part_form
|
|
126
|
+
* @param {object} the_map
|
|
127
|
+
* @param {string}
|
|
128
|
+
* @returns pair<key,data> -- this is an array with a key in position 0, and data in position 1
|
|
129
|
+
*/
|
|
130
|
+
function find_map(part_form,the_map,section_key) {
|
|
131
|
+
|
|
132
|
+
if ( section_key === undefined ) {
|
|
133
|
+
section_key = "<<"
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let key = part_form.substring(0,part_form.indexOf(section_key)).trim()
|
|
137
|
+
if ( key.length === 0 ) {
|
|
138
|
+
//console.log(part_form)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
let data = the_map[key]
|
|
142
|
+
|
|
143
|
+
return[key,data]
|
|
72
144
|
}
|
|
73
145
|
|
|
74
146
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
147
|
+
/**
|
|
148
|
+
* key_map_sub
|
|
149
|
+
*
|
|
150
|
+
* Takes in a string `source_str`, which may be formatted with substitution forms.
|
|
151
|
+
* The form '$${key}' is similar to the JavaScript substitution directive '${subsitution expre}'.
|
|
152
|
+
* There is one extra '$' up front. The object contains key-value pairs.
|
|
153
|
+
*
|
|
154
|
+
* In some cases, a value from the object may be a stored variable.
|
|
155
|
+
* In this application, the value as variable is indicated by a character prefix. (default '>')
|
|
156
|
+
* The vars parameter includes variable-value pairs allowing for substitutions specifically for a string
|
|
157
|
+
* outside the use of the key-value object. This provides override for globally set values.
|
|
158
|
+
*
|
|
159
|
+
*
|
|
160
|
+
* @param {string} source_str
|
|
161
|
+
* @param {object} key_values
|
|
162
|
+
* @param {string} vars - a string of variable,value pairs delimited by the var_delimiter
|
|
163
|
+
* @param {string} value_var_prefix (optional)
|
|
164
|
+
* @param {string} var_delimiter
|
|
165
|
+
* @returns string
|
|
166
|
+
*/
|
|
167
|
+
function key_map_sub(source_str,key_values,vars,value_var_prefix,var_delimiter) {
|
|
168
|
+
if ( value_var_prefix === undefined ) {
|
|
169
|
+
value_var_prefix = '>'
|
|
170
|
+
}
|
|
171
|
+
if ( var_delimiter === undefined ) {
|
|
172
|
+
var_delimiter = "::"
|
|
173
|
+
}
|
|
174
|
+
let fdata = '' + source_str
|
|
175
|
+
for ( let key in key_values ) {
|
|
176
|
+
let value = key_values[key]
|
|
177
|
+
if ( value[0] === value_var_prefix ) {
|
|
178
|
+
let varname = value.substr(1)
|
|
179
|
+
let i = vars.indexOf(varname)
|
|
180
|
+
if ( i >= 0 ) {
|
|
181
|
+
value = vars.substring(i + varname.length + var_delimiter.length) // take in the full variable and including the delimiter, value follows
|
|
182
|
+
if ( value.indexOf(var_delimiter) > 0 ) { // just clear of the delimiter
|
|
183
|
+
value = value.substr(0,value.indexOf(var_delimiter))
|
|
89
184
|
}
|
|
185
|
+
value = value.trim()
|
|
90
186
|
}
|
|
91
187
|
}
|
|
188
|
+
fdata = subst(fdata,`$$${key}`,value)
|
|
92
189
|
}
|
|
93
|
-
|
|
190
|
+
//
|
|
191
|
+
return fdata
|
|
94
192
|
}
|
|
95
193
|
|
|
96
194
|
|
|
97
|
-
|
|
195
|
+
class ParseUtils {
|
|
196
|
+
|
|
197
|
+
constructor() {}
|
|
198
|
+
|
|
199
|
+
clear_block_comments(str) {
|
|
200
|
+
let output = ""
|
|
201
|
+
let n = str.length - 1
|
|
202
|
+
let prev_c = str[0]
|
|
203
|
+
let i = 1
|
|
204
|
+
for ( ; i < n; i++ ) {
|
|
205
|
+
let c = str[i]
|
|
206
|
+
if ( "/*" === (`${prev_c}${c}`) ) {
|
|
207
|
+
while ( i < n ) {
|
|
208
|
+
c = str[i++]
|
|
209
|
+
if ( (c === '*') && (str[i++] === '/') ) {
|
|
210
|
+
prev_c = str[i]
|
|
211
|
+
break
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
output += prev_c
|
|
216
|
+
prev_c = c
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
n = str.length
|
|
220
|
+
if ( i < n ) {
|
|
221
|
+
output += str.substring(i-1)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return output
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
clear_comments(str) {
|
|
228
|
+
if ( str.indexOf("verbatim::") === 0 ) {
|
|
229
|
+
let check_end = str.lastIndexOf('}')
|
|
230
|
+
//
|
|
231
|
+
if ( check_end > 0 ) {
|
|
232
|
+
let front = str.substring(0,check_end+1)
|
|
233
|
+
return front
|
|
234
|
+
}
|
|
235
|
+
} else {
|
|
236
|
+
if ( str.indexOf("//") >= 0 ) {
|
|
237
|
+
let lines = str.split('\n')
|
|
238
|
+
let n = lines.length
|
|
239
|
+
for ( let i = 0; i < n; i++ ) {
|
|
240
|
+
let line = lines[i]
|
|
241
|
+
line = line.trim()
|
|
242
|
+
if ( line.length && (line.indexOf('//') === 0) ) {
|
|
243
|
+
lines[i] = ""
|
|
244
|
+
} else if ( line.length && (line.indexOf('//') > 0) ) {
|
|
245
|
+
line = line.substring(0,(line.indexOf('//'))).trim()
|
|
246
|
+
lines[i] = line
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
lines = lines.filter((line) => {
|
|
250
|
+
return line.length > 0
|
|
251
|
+
})
|
|
252
|
+
return lines.join("\n")
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return str.trim()
|
|
256
|
+
}
|
|
257
|
+
remove_spaces(str) {
|
|
258
|
+
let strs = str.split(' ')
|
|
259
|
+
strs = strs.filter((sub) => {
|
|
260
|
+
return sub.length > 0
|
|
261
|
+
})
|
|
262
|
+
return strs.join('')
|
|
263
|
+
}
|
|
264
|
+
remove_white(str) {
|
|
265
|
+
str = str.replace(/\s+/g,'')
|
|
266
|
+
return str
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
flatten(data_parts) {
|
|
270
|
+
let flattened = []
|
|
271
|
+
for ( let part of data_parts ) {
|
|
272
|
+
if ( typeof part === "string" ) {
|
|
273
|
+
flattened.push(part)
|
|
274
|
+
} else {
|
|
275
|
+
let parted = this.flatten(part)
|
|
276
|
+
for ( let p of parted ) {
|
|
277
|
+
flattened.push(p)
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return flattened
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
capitalize(str) {
|
|
286
|
+
let rest = str.substring(1)
|
|
287
|
+
str = str.substring(0,1).toUpperCase() + rest
|
|
288
|
+
return str
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
subst(str,ky,val) {
|
|
293
|
+
while ( str.indexOf(ky) >= 0 ) {
|
|
294
|
+
str = str.replace(ky,val)
|
|
295
|
+
}
|
|
296
|
+
return str
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
extract_var(str) {
|
|
301
|
+
let var_up = str.substring(str.indexOf('@{') + 2)
|
|
302
|
+
let vname = var_up.substring(0,var_up.indexOf('}'))
|
|
303
|
+
return vname
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
has_parameter_block(data) {
|
|
307
|
+
return data.indexOf("@params<{") >= 0
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
remove_parameter_block(data) {
|
|
311
|
+
data = data.trim()
|
|
312
|
+
let front_split = data.split("@params<{")
|
|
313
|
+
let front = front_split[0]
|
|
314
|
+
let rest = front_split[1]
|
|
315
|
+
|
|
316
|
+
let end_block = rest.indexOf("}>")
|
|
317
|
+
rest = rest.substring(end_block+2).trim()
|
|
318
|
+
data = front + rest
|
|
319
|
+
return data.trim()
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Revers a map... take into consideration that the original mapping might not be one to one
|
|
325
|
+
* @param {object} skeletons
|
|
326
|
+
* @returns {object}
|
|
327
|
+
*/
|
|
328
|
+
reverse_map(skeletons) {
|
|
329
|
+
let robj = {}
|
|
330
|
+
for ( let [ky,val] of Object.entries(skeletons) ) {
|
|
331
|
+
let obj = robj[val] // robj maps from value to object (a map)
|
|
332
|
+
if ( !obj ) { // create object (new value as key)
|
|
333
|
+
obj = {}
|
|
334
|
+
robj[val] = obj
|
|
335
|
+
}
|
|
336
|
+
obj[ky] = "" // collect keys that mapped to value (may be one or more)
|
|
337
|
+
}
|
|
338
|
+
return robj
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
copy_keys(dst,src,type) {
|
|
342
|
+
if ( type === "array" ) {
|
|
343
|
+
for ( let ky in src ) {
|
|
344
|
+
dst[ky] = []
|
|
345
|
+
}
|
|
346
|
+
} else if ( type === "object" ) {
|
|
347
|
+
for ( let ky in src ) {
|
|
348
|
+
dst[ky] = {}
|
|
349
|
+
}
|
|
350
|
+
} else {
|
|
351
|
+
for ( let ky in src ) {
|
|
352
|
+
dst[ky] = ""
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
*
|
|
360
|
+
* @param {object} obj
|
|
361
|
+
* @param {Function} fn
|
|
362
|
+
*/
|
|
363
|
+
key_sort(obj,fn) {
|
|
364
|
+
let sobj = {}
|
|
365
|
+
let keys = Object.keys(obj)
|
|
366
|
+
if ( typeof fn === "function" ) {
|
|
367
|
+
keys.sort((el1,el2) => {
|
|
368
|
+
let ky1 = fn(el1)
|
|
369
|
+
let ky2 = fn(el2)
|
|
370
|
+
if ( ky1 < ky2 ) {
|
|
371
|
+
return -1
|
|
372
|
+
} else if ( ky1 < ky2 ) {
|
|
373
|
+
return 1
|
|
374
|
+
} else {
|
|
375
|
+
return 0
|
|
376
|
+
}
|
|
377
|
+
})
|
|
378
|
+
} else {
|
|
379
|
+
keys.sort()
|
|
380
|
+
}
|
|
381
|
+
for ( let ky of keys ) {
|
|
382
|
+
sobj[ky] = obj[ky]
|
|
383
|
+
}
|
|
384
|
+
return sobj
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
next_char(achar) {
|
|
390
|
+
let b = achar.charCodeAt(0)
|
|
391
|
+
b++
|
|
392
|
+
let c = String.fromCharCode(b)
|
|
393
|
+
return c
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
module.exports = ParseUtils
|
|
399
|
+
|
|
400
|
+
module.exports.gsubst = subst
|
|
401
|
+
module.exports.array_flatten = array_flatten
|
|
402
|
+
module.exports.recursive_flat = recursive_flat
|
|
403
|
+
module.exports.find_map = find_map
|
|
404
|
+
module.exports.mapify = mapify
|
|
405
|
+
module.exports.key_map_sub = key_map_sub
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "roll-right",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A utilty for generating template files, e.g. HTML templates, in one phase, and then generating final output files, e.g. HTML, in another phase.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
7
7
|
"example": "examples"
|
|
@@ -11,14 +11,16 @@
|
|
|
11
11
|
"roll-right-breakup": "./bin/breakup.js"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"test": "node tests/index.js"
|
|
14
|
+
"test": "node tests/index.js",
|
|
15
|
+
"prepare" : "node bin/index.js --phase prepare --sources ../websites/template-configs/ --generator generate.json --structure parsed.json",
|
|
16
|
+
"templates" : "node bin/index.js --phase template --sources ../websites/template-configs/ --generator generate.json --structure parsed.json",
|
|
17
|
+
"page" : "node bin/index.js --phase page --sources ../websites/template-configs/ --values assignments.json"
|
|
15
18
|
},
|
|
16
19
|
"dependencies": {
|
|
17
20
|
"byte-base64": "^1.1.0",
|
|
18
|
-
"extra-file-class": "^0.
|
|
19
|
-
"fs-extra": "^10.0.1",
|
|
21
|
+
"extra-file-class": "^1.0.1",
|
|
20
22
|
"handlebars": "^4.7.7",
|
|
21
|
-
"minimist": "^1.2.
|
|
23
|
+
"minimist": "^1.2.8",
|
|
22
24
|
"untildify": "^4.0.0"
|
|
23
25
|
},
|
|
24
26
|
"repository": {
|
|
@@ -28,7 +30,8 @@
|
|
|
28
30
|
"keywords": [
|
|
29
31
|
"browserify",
|
|
30
32
|
"rollup",
|
|
31
|
-
"publisher"
|
|
33
|
+
"publisher",
|
|
34
|
+
"HTML-generation"
|
|
32
35
|
],
|
|
33
36
|
"author": "R. Leddy",
|
|
34
37
|
"license": "GPL-3.0-or-later",
|
package/test/index.js
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
|
-
const papa = require('../index.js')
|
|
1
|
+
// const papa = require('../index.js')
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
papa.browser_code()
|
|
5
|
+
// papa.browser_code()
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
let ParseUtils = require('../lib/utils')
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
let putils = new ParseUtils()
|
|
12
|
+
|
|
13
|
+
putils.clear_block_comments("")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
let commented =
|
|
17
|
+
`----/* ****
|
|
18
|
+
|
|
19
|
+
This is a test and it shoul be something you can't see.
|
|
20
|
+
|
|
21
|
+
*
|
|
22
|
+
|
|
23
|
+
*/
|
|
24
|
+
I like living in my house.
|
|
25
|
+
-------------------------
|
|
26
|
+
/* ****
|
|
27
|
+
This is a test and it shoul be something you can't see.
|
|
28
|
+
*
|
|
29
|
+
*/1234`
|
|
30
|
+
|
|
31
|
+
let oput = putils.clear_block_comments(commented)
|
|
32
|
+
|
|
33
|
+
console.log(oput)
|