roll-right 0.0.1 → 0.1.2
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 +55 -10
- package/bin/breakup.js +56 -0
- package/bin/index.js +107 -4
- package/index.js +1 -1
- package/lib/mod_utils.js +79 -0
- package/lib/phase1.js +445 -0
- package/lib/phase2.js +77 -0
- package/lib/rr_utils.js +128 -8
- package/lib/to_export.js +39 -0
- package/lib/utils.js +97 -0
- package/package.json +11 -2
- package/tools/affiliates.js +132 -0
- package/tools/allgen.sh +20 -0
- package/tools/charwindow.js +17 -0
- package/tools/filter_requires.js +60 -0
- package/tools/genpage.js +141 -0
- package/tools/npm_much.sh +57 -0
- package/tools/prep_body_insert_only.js +28 -0
- package/tools/releasepages.js +814 -0
- package/tools/rungen.sh +6 -0
- package/tools/rungen_dashboard.sh +5 -0
- package/tools/rungen_header_shell.sh +5 -0
- package/tools/rungen_paramed_shell.sh +12 -0
- package/tools/rungen_profile.sh +5 -0
- package/tools/web_files.js +149 -0
- package/transform.js +490 -0
- package/roll_right.js +0 -96
package/tools/rungen.sh
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
dir=$1
|
|
2
|
+
template_source=$2
|
|
3
|
+
file=$3
|
|
4
|
+
odir=$4
|
|
5
|
+
ofile=$5
|
|
6
|
+
echo $dir
|
|
7
|
+
pushd ./tools
|
|
8
|
+
node prep_body_insert_only.js ../sites/${dir}/static/template/${template_source} ../sites/${dir}/static/${file} ../sites/${dir}/tmp_output.html
|
|
9
|
+
#
|
|
10
|
+
node genpage.js ../sites/${dir}/static/${dir}.subst ../sites/${dir}/tmp_output.html ../sites/${dir}/${odir}/${ofile}
|
|
11
|
+
rm ../sites/${dir}/tmp_output.html
|
|
12
|
+
popd
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const minify = require('html-minifier').minify;
|
|
3
|
+
const tar = require('tar')
|
|
4
|
+
const {exec} = require('child_process')
|
|
5
|
+
const path_util = require('path')
|
|
6
|
+
const util = require('util');
|
|
7
|
+
const asyc_exec = util.promisify(exec);
|
|
8
|
+
|
|
9
|
+
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
|
|
10
|
+
var g_html_web_directories = []
|
|
11
|
+
var g_releaseObject = {}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const g_src_dir = '../release' // 'release' //
|
|
15
|
+
var g_config_file = '../release/release.json' // 'release.json' //
|
|
16
|
+
try {
|
|
17
|
+
var releaseObj_str = fs.readFileSync(g_config_file,'ascii').toString()
|
|
18
|
+
try {
|
|
19
|
+
g_releaseObject = JSON.parse(releaseObj_str)
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.error(`failed to parse the file '${g_config_file}'`)
|
|
22
|
+
console.error(e)
|
|
23
|
+
process.exit(0)
|
|
24
|
+
}
|
|
25
|
+
} catch (e) {
|
|
26
|
+
console.error(`failed to find the file '${g_config_file}'`)
|
|
27
|
+
process.exit(0)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
|
|
31
|
+
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// ensureExists
|
|
36
|
+
// does what it says.
|
|
37
|
+
function ensureExists(path, mask) {
|
|
38
|
+
if (typeof mask == 'undefined') { // allow the `mask` parameter to be optional
|
|
39
|
+
cb = mask;
|
|
40
|
+
mask = 0777;
|
|
41
|
+
}
|
|
42
|
+
var p = new Promise((resolve,reject) => {
|
|
43
|
+
fs.mkdir(path, mask, function(err) {
|
|
44
|
+
if (err) {
|
|
45
|
+
if (err.code == 'EEXIST') resolve(null); // ignore the error if the folder already exists
|
|
46
|
+
else reject(err); // something else went wrong
|
|
47
|
+
} else resolve(null); // successfully created folder
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
})
|
|
51
|
+
return p
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function ensurePathExists(path,mask) {
|
|
55
|
+
let where_all = path.split('/')
|
|
56
|
+
where_all.shift()
|
|
57
|
+
where = ''
|
|
58
|
+
where_all.forEach(async level => {
|
|
59
|
+
where += '/' + level
|
|
60
|
+
try {
|
|
61
|
+
await ensureExists(where,mask)
|
|
62
|
+
} catch (e) {
|
|
63
|
+
if (e.code != 'EEXIST') {
|
|
64
|
+
console.log(e)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
return(where)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
function get_directory_from_list(dir_list,base_dname) {
|
|
73
|
+
let dir = dir_list.find(adir => {
|
|
74
|
+
console.log(adir,base_dname)
|
|
75
|
+
return(adir.indexOf(base_dname) >= 0 )
|
|
76
|
+
})
|
|
77
|
+
return(dir)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function locate_html_directory(conf) {
|
|
81
|
+
|
|
82
|
+
let nginx_loc = conf.conf_location
|
|
83
|
+
let cmd = `grep -rE 'root\\s+/' ${nginx_loc}/*.conf`
|
|
84
|
+
console.log(cmd)
|
|
85
|
+
try {
|
|
86
|
+
const { stdout, stderr } = await asyc_exec(cmd)
|
|
87
|
+
|
|
88
|
+
let lines = stdout.split('\n')
|
|
89
|
+
let good_line = lines.filter(line => {
|
|
90
|
+
if ( line.length == 0 ) return(false)
|
|
91
|
+
if ( line.indexOf(':') >= 0 ) {
|
|
92
|
+
line = line.split(':')[1]
|
|
93
|
+
}
|
|
94
|
+
let l = line.trim()
|
|
95
|
+
return(l[0] !== '#')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
g_html_web_directories = good_line.map(line => {
|
|
99
|
+
if ( line.indexOf(':') >= 0 ) {
|
|
100
|
+
line = line.split(':')[1]
|
|
101
|
+
}
|
|
102
|
+
line = line.replace('root','')
|
|
103
|
+
line = line.trim()
|
|
104
|
+
line = line.replace(';','')
|
|
105
|
+
return(line)
|
|
106
|
+
})
|
|
107
|
+
} catch (e) {
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
console.log(g_html_web_directories)
|
|
112
|
+
|
|
113
|
+
// /etc/nginx/sites-enabled/default: root /var/www/html;
|
|
114
|
+
// /etc/nginx/sites-enabled/popsongnow.conf: root /var/www/html/popsongnow;
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
function move_html(doms) {
|
|
120
|
+
for ( let dom in doms ) {
|
|
121
|
+
//
|
|
122
|
+
let dom_dots = dom.split('.')
|
|
123
|
+
let base_dname = dom_dots[1]
|
|
124
|
+
//console.log(base_dname, g_html_web_directories)
|
|
125
|
+
let dir = get_directory_from_list(g_html_web_directories,base_dname)
|
|
126
|
+
//console.log(dir)
|
|
127
|
+
if ( dir !== undefined ) {
|
|
128
|
+
//
|
|
129
|
+
ensurePathExists(dir)
|
|
130
|
+
//
|
|
131
|
+
let domObj = doms[dom]
|
|
132
|
+
let files = domObj.html.files
|
|
133
|
+
files.forEach(file => {
|
|
134
|
+
let fpath = `${g_src_dir}/${dom}/${file}.html`
|
|
135
|
+
let target = `${dir}/${file}.html`
|
|
136
|
+
fs.copyFileSync(fpath,target)
|
|
137
|
+
})
|
|
138
|
+
//
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function process_web_files() {
|
|
144
|
+
//g_html_web_directories = [ '/usr/local/var/www/html/popsongnow', '/usr/local/var/www/html/copious' ] // /var/www/html/popsongnow
|
|
145
|
+
await locate_html_directory(g_releaseObject.nginx)
|
|
146
|
+
move_html(g_releaseObject.domains)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
process_web_files()
|
package/transform.js
ADDED
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path')
|
|
3
|
+
|
|
4
|
+
//function stay_healthy_function() {}
|
|
5
|
+
// https://www.youtube.com/watch?v=s86-Z-CbaHA
|
|
6
|
+
|
|
7
|
+
// FROM STACK EXCHANGE
|
|
8
|
+
Object.defineProperty(global, '__stack', {
|
|
9
|
+
get: function() {
|
|
10
|
+
var orig = Error.prepareStackTrace;
|
|
11
|
+
Error.prepareStackTrace = function(_, stack) {
|
|
12
|
+
return stack;
|
|
13
|
+
};
|
|
14
|
+
var err = new Error;
|
|
15
|
+
Error.captureStackTrace(err, arguments.callee);
|
|
16
|
+
var stack = err.stack;
|
|
17
|
+
Error.prepareStackTrace = orig;
|
|
18
|
+
return stack;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
Object.defineProperty(global, '__line', {
|
|
23
|
+
get: function() {
|
|
24
|
+
return __stack[1].getLineNumber();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
Object.defineProperty(global, '__function', {
|
|
29
|
+
get: function() {
|
|
30
|
+
return __stack[1].getFunctionName();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
function foo() {
|
|
36
|
+
console.log(__line);
|
|
37
|
+
console.log(__function);
|
|
38
|
+
}
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
function die(msg) {
|
|
43
|
+
console.log(msg)
|
|
44
|
+
console.log("terminating")
|
|
45
|
+
try {
|
|
46
|
+
stay_healthy_function()
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error(e)
|
|
49
|
+
process.exit(0)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//$?SUBST??:post_fetch.js?$ // examples
|
|
54
|
+
//
|
|
55
|
+
const g_subst_tag = '//$?SUBST??:'
|
|
56
|
+
const g_export_tag = '//$$EXPORTABLE::'
|
|
57
|
+
|
|
58
|
+
//
|
|
59
|
+
let import_dir = "./client" // default to html generation
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
function subst_str(istr,symbol,value) {
|
|
63
|
+
let in_parts = istr.split(symbol)
|
|
64
|
+
if ( in_parts.length === 1 ) {
|
|
65
|
+
return istr
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let out_parts = []
|
|
69
|
+
out_parts.push(in_parts.shift())
|
|
70
|
+
while ( in_parts.length ) {
|
|
71
|
+
let opart = value + in_parts.shift()
|
|
72
|
+
out_parts.push(opart)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let output = out_parts.join('')
|
|
76
|
+
return output
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
function extact_expr(symbol_ky,boundries) {
|
|
81
|
+
let c1 = boundries[0]
|
|
82
|
+
let c2 = boundries[1]
|
|
83
|
+
let p1 = symbol_ky.indexOf(c1)
|
|
84
|
+
if ( p1 > 0 ) {
|
|
85
|
+
let p2 = symbol_ky.lastIndexOf(c2)
|
|
86
|
+
let expr_str = symbol_ky.substr((p1+1),(p2 - p1 - 1))
|
|
87
|
+
return expr_str
|
|
88
|
+
}
|
|
89
|
+
return('')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function subst_mode_files(template_str,filler) {
|
|
93
|
+
if ( !template_str || (typeof template_str !== 'string') || (template_str.length < 3) ) {
|
|
94
|
+
die(`in: ${__function} :${__line}:: input is not long enough to operate`)
|
|
95
|
+
}
|
|
96
|
+
let parts = template_str.split(g_subst_tag)
|
|
97
|
+
if ( parts.length === 0 ) {
|
|
98
|
+
die(`in: ${__function} :${__line}:: failure in split function`)
|
|
99
|
+
}
|
|
100
|
+
if ( parts.length === 1 ) {
|
|
101
|
+
return template_str // no subsitutions
|
|
102
|
+
}
|
|
103
|
+
//
|
|
104
|
+
let new_parts = []
|
|
105
|
+
new_parts.push(parts.shift())
|
|
106
|
+
let char_count = new_parts[0].length
|
|
107
|
+
|
|
108
|
+
while ( parts.length ) {
|
|
109
|
+
let part = parts.shift()
|
|
110
|
+
char_count += part.length
|
|
111
|
+
let stopper = part.indexOf('?$')
|
|
112
|
+
if ( stopper < 3 ) { // a.b at least... has to be a file name with an extension
|
|
113
|
+
die(`in: ${__function} :${__line}:: char ${char_count} substitution not defined`)
|
|
114
|
+
}
|
|
115
|
+
//
|
|
116
|
+
let fname = part.substr(0,stopper)
|
|
117
|
+
let rest = part.substr(stopper + 2)
|
|
118
|
+
|
|
119
|
+
let subst = filler[fname]
|
|
120
|
+
new_parts.push('\n' + subst + '\n' + rest)
|
|
121
|
+
//
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let output = new_parts.join('')
|
|
125
|
+
return(output)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
function prep_for_export_import(target_file_contents) {
|
|
131
|
+
if ( !target_file_contents || (typeof target_file_contents !== 'string') || (target_file_contents.length < (g_export_tag.length + 60)) ) {
|
|
132
|
+
die(`in: ${__function} :${__line}:: input is not long enough to operate`)
|
|
133
|
+
}
|
|
134
|
+
// gather all the export names or expressions
|
|
135
|
+
let parts = template_str.split(g_export_tag)
|
|
136
|
+
if ( parts.length === 0 ) {
|
|
137
|
+
die(`in: ${__function} :${__line}:: failure in split function`)
|
|
138
|
+
}
|
|
139
|
+
if ( parts.length === 1 ) {
|
|
140
|
+
return template_str // no subsitutions
|
|
141
|
+
}
|
|
142
|
+
//
|
|
143
|
+
let new_parts = []
|
|
144
|
+
let all_exports = []
|
|
145
|
+
new_parts.push(parts.shift())
|
|
146
|
+
while ( parts.length ) {
|
|
147
|
+
let part = parts.shift()
|
|
148
|
+
// go to next comment and take in the comment
|
|
149
|
+
part = part.trim()
|
|
150
|
+
let cloc = part.indexOf('/*')
|
|
151
|
+
if ( cloc >= 0 ) {
|
|
152
|
+
part = part.trim().substr(cloc+2)
|
|
153
|
+
cloc = part.indexOf('*/')
|
|
154
|
+
let exports = part.substr(0,cloc)
|
|
155
|
+
part = part.substr(cloc+2)
|
|
156
|
+
part += '/n'
|
|
157
|
+
new_parts.push(part)
|
|
158
|
+
exports = exports.split('\n')
|
|
159
|
+
all_exports = all_exports.concat(exports.map(ln => { return(ln.trim())} ))
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//
|
|
163
|
+
let output = new_parts.join('\n')
|
|
164
|
+
let unique_exports = {}
|
|
165
|
+
all_exports.forEach(exprt => {
|
|
166
|
+
unique_exports[exprt] = 1
|
|
167
|
+
})
|
|
168
|
+
//
|
|
169
|
+
let explist = Object.keys(unique_exports)
|
|
170
|
+
if ( explist.length === 0 ) {
|
|
171
|
+
return(output)
|
|
172
|
+
}
|
|
173
|
+
//
|
|
174
|
+
let explist_str = explist.join(', ')
|
|
175
|
+
let exporter = `export { ${explist_str} };`
|
|
176
|
+
output += `
|
|
177
|
+
${exporter}
|
|
178
|
+
`
|
|
179
|
+
//
|
|
180
|
+
return(output)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
function extract_fields_forms(tmplt) {
|
|
185
|
+
return tmplt.match(/{{\w*}}/g)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
function key_complexity(k1,k2) {
|
|
190
|
+
let cplx_cnt_1 = 0
|
|
191
|
+
let cplx_cnt_2 = 0
|
|
192
|
+
for ( let i = 0; i < k1.length; i++ ) {
|
|
193
|
+
let c = k1[i]
|
|
194
|
+
if ( '{[$'.includes(c) ) cplx_cnt_1++
|
|
195
|
+
if ( '{['.includes(c) ) cplx_cnt_1++
|
|
196
|
+
}
|
|
197
|
+
for ( let i = 0; i < k2.length; i++ ) {
|
|
198
|
+
let c = k2[i]
|
|
199
|
+
if ( '{[$'.includes(c) ) cplx_cnt_2++
|
|
200
|
+
if ( '{['.includes(c) ) cplx_cnt_2++
|
|
201
|
+
}
|
|
202
|
+
return(cplx_cnt_2 - cplx_cnt_1)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
/// TAKE THE NAME OF THE CONFIG FILE FROM COMMAND LINE node transform myfile.json (or other ext)
|
|
210
|
+
|
|
211
|
+
let input_file = process.argv[2]
|
|
212
|
+
|
|
213
|
+
console.log(input_file)
|
|
214
|
+
|
|
215
|
+
let data = fs.readFileSync(input_file).toString()
|
|
216
|
+
data = JSON.parse(data)
|
|
217
|
+
//
|
|
218
|
+
console.dir(data)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
/*
|
|
222
|
+
|
|
223
|
+
{
|
|
224
|
+
"businesses" : [
|
|
225
|
+
"copious.world",
|
|
226
|
+
"popsong.now"
|
|
227
|
+
],
|
|
228
|
+
"in_dir" : "string",
|
|
229
|
+
"out_dir" : "string/${business_key}",
|
|
230
|
+
"file1-eg" : {
|
|
231
|
+
"out_dir" : "special-case/${business_key}",
|
|
232
|
+
"special_items" : true,
|
|
233
|
+
"array" : "JSON FILE THAT IS ARRAY/${business_key}"
|
|
234
|
+
"input" : "a file name in in-dir :: a template file"
|
|
235
|
+
},
|
|
236
|
+
"file2-eg" : {
|
|
237
|
+
"out_dir" : "special-case/${business_key}",
|
|
238
|
+
"special_items" : true,
|
|
239
|
+
"array" : "JSON FILE THAT IS ARRAY/${business_key}"
|
|
240
|
+
"input" : [
|
|
241
|
+
"a file name in in-dir :: a template file",
|
|
242
|
+
"a file name in in-dir :: a template file"
|
|
243
|
+
]
|
|
244
|
+
},
|
|
245
|
+
"file3" : : {
|
|
246
|
+
"out_dir" : false,
|
|
247
|
+
"special_items" : false,
|
|
248
|
+
"input" : "a file name in in-dir :: a template file",
|
|
249
|
+
"import" : {
|
|
250
|
+
"inmport-file-name" : {
|
|
251
|
+
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
"import_app" : {
|
|
255
|
+
|
|
256
|
+
},
|
|
257
|
+
"subst_l1" : {
|
|
258
|
+
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
"file3" : {}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
*/
|
|
265
|
+
|
|
266
|
+
let businesses = data.businesses
|
|
267
|
+
let input_dir = data.in_dir
|
|
268
|
+
let out_dir = data.out_dir
|
|
269
|
+
|
|
270
|
+
delete data.businesses
|
|
271
|
+
delete data.in_dir
|
|
272
|
+
delete data.out_dir
|
|
273
|
+
|
|
274
|
+
for ( let business of businesses ) {
|
|
275
|
+
//
|
|
276
|
+
console.log(business)
|
|
277
|
+
for ( let filename in data ) {
|
|
278
|
+
let descr = data[filename]
|
|
279
|
+
let odir = out_dir.replace("${business_key}",business)
|
|
280
|
+
if ( descr.out_dir !== undefined ) {
|
|
281
|
+
odir = descr.out_dir.replace("${business_key}",business)
|
|
282
|
+
}
|
|
283
|
+
if ( (descr.special_items !== undefined) && descr.special_items ) {
|
|
284
|
+
console.log(filename)
|
|
285
|
+
console.log(odir)
|
|
286
|
+
//
|
|
287
|
+
let item_input = descr.array.replace("${business_key}",business)
|
|
288
|
+
|
|
289
|
+
try { // read in the files that will have parts inserted
|
|
290
|
+
let ifile = item_input
|
|
291
|
+
let item_list = fs.readFileSync(ifile).toString()
|
|
292
|
+
item_list = JSON.parse(item_list)
|
|
293
|
+
// fail if not array
|
|
294
|
+
//
|
|
295
|
+
if ( typeof descr.input === "string" ) {
|
|
296
|
+
let out_parts = []
|
|
297
|
+
let tmplt_file = input_dir + descr.input
|
|
298
|
+
let tmplt = fs.readFileSync(tmplt_file).toString() // THE TEMPLATE FILE
|
|
299
|
+
// build an array of targets
|
|
300
|
+
let field_fs = extract_fields_forms(tmplt)
|
|
301
|
+
let fields = field_fs.map( fld => { return(fld.replace("{{",'').replace("}}",''))} )
|
|
302
|
+
|
|
303
|
+
for ( let item of item_list ) {
|
|
304
|
+
let o_item = ''
|
|
305
|
+
//
|
|
306
|
+
o_item += tmplt // a string copy (reusing the template)
|
|
307
|
+
for (let i = 0; i < field_fs.length; i++ ) {
|
|
308
|
+
let fld = fields[i]
|
|
309
|
+
let repl_fld = field_fs[i]
|
|
310
|
+
let value = decodeURIComponent(item[fld])
|
|
311
|
+
value = value === undefined ? "" : value
|
|
312
|
+
o_item = o_item.replace(repl_fld,value)
|
|
313
|
+
}
|
|
314
|
+
//
|
|
315
|
+
out_parts.push(encodeURIComponent(o_item))
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
let output = out_parts.join('')
|
|
319
|
+
let outfile = odir + filename
|
|
320
|
+
console.log(outfile)
|
|
321
|
+
fs.writeFileSync(outfile,output)
|
|
322
|
+
|
|
323
|
+
} else {
|
|
324
|
+
if ( Array.isArray(descr.input) ) {
|
|
325
|
+
descr.input.forEach(file => {
|
|
326
|
+
out_parts = []
|
|
327
|
+
let tmplt_file = input_dir + file
|
|
328
|
+
//
|
|
329
|
+
let tmplt = fs.readFileSync(tmplt_file).toString()
|
|
330
|
+
let field_fs = extract_fields_forms(tmplt)
|
|
331
|
+
let fields = field_fs.map( fld => { return(fld.replace("{{",'').replace("}}",''))} )
|
|
332
|
+
//
|
|
333
|
+
let output_descr = descr.output[file]
|
|
334
|
+
if ( output_descr === undefined ) return
|
|
335
|
+
//
|
|
336
|
+
for ( let item of item_list ) {
|
|
337
|
+
let o_item = ''
|
|
338
|
+
if ( output_descr.reject !== undefined ) {
|
|
339
|
+
let check_r = item[output_descr.reject]
|
|
340
|
+
if ( (check_r !== undefined) && check_r ) {
|
|
341
|
+
continue
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
// "reject" : "no_subst"
|
|
345
|
+
if ( item.no_subst ) {
|
|
346
|
+
let nosubst_desc = descr.no_subst
|
|
347
|
+
let wrap = input_dir + nosubst_desc.wrapper
|
|
348
|
+
let tmplt_w = fs.readFileSync(wrap).toString()
|
|
349
|
+
let field_fs_w = extract_fields_forms(tmplt_w)
|
|
350
|
+
let fields_w = field_fs_w.map( fld => { return(fld.replace("{{",'').replace("}}",''))} )
|
|
351
|
+
o_item += tmplt_w
|
|
352
|
+
for (let i = 0; i < field_fs_w.length; i++ ) {
|
|
353
|
+
let fld = fields_w[i]
|
|
354
|
+
let repl_fld = field_fs_w[i]
|
|
355
|
+
let value = decodeURIComponent(item[fld])
|
|
356
|
+
value = value === undefined ? "" : value
|
|
357
|
+
o_item = o_item.replace(repl_fld,value)
|
|
358
|
+
}
|
|
359
|
+
} else {
|
|
360
|
+
o_item = '' + tmplt
|
|
361
|
+
for (let i = 0; i < field_fs.length; i++ ) {
|
|
362
|
+
let fld = fields[i]
|
|
363
|
+
let repl_fld = field_fs[i]
|
|
364
|
+
let value = decodeURIComponent(item[fld])
|
|
365
|
+
value = value === undefined ? "" : value
|
|
366
|
+
o_item = o_item.replace(repl_fld,value)
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if ( output_descr.encoded ) { // list of output parts
|
|
370
|
+
out_parts.push(encodeURIComponent(o_item))
|
|
371
|
+
} else {
|
|
372
|
+
out_parts.push(o_item)
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
//
|
|
376
|
+
let output = out_parts.join('')
|
|
377
|
+
let outfile = odir + output_descr.file
|
|
378
|
+
console.log(outfile)
|
|
379
|
+
fs.writeFileSync(outfile,output)
|
|
380
|
+
//
|
|
381
|
+
})
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
} catch(e) {
|
|
386
|
+
console.log(e)
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
} else {
|
|
390
|
+
//console.dir(descr)
|
|
391
|
+
//
|
|
392
|
+
let template_file = (input_dir + descr.input)
|
|
393
|
+
let template_str = fs.readFileSync(template_file).toString()
|
|
394
|
+
//
|
|
395
|
+
// descr.input ... input the files...
|
|
396
|
+
let file_map = descr.import
|
|
397
|
+
let filler_data = {}
|
|
398
|
+
for ( let fname in file_map ) {
|
|
399
|
+
// '*' for all otherwise filters....
|
|
400
|
+
let filter_list = file_map[fname]
|
|
401
|
+
if ( filter_list === '*' ) { // put entire in_str in place of the subst tag
|
|
402
|
+
let indir = ( fname[0] === '.' ) ? '' : input_dir
|
|
403
|
+
let str_from_file = fs.readFileSync(indir + fname).toString()
|
|
404
|
+
let key_fname = path.basename(fname)
|
|
405
|
+
filler_data[key_fname] = str_from_file
|
|
406
|
+
} else {
|
|
407
|
+
// not implemented
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
//
|
|
411
|
+
let template_str_2 = subst_mode_files(template_str,filler_data)
|
|
412
|
+
|
|
413
|
+
if ( descr.import_app !== undefined ) {
|
|
414
|
+
for ( let import_ky in descr.import_app ) {
|
|
415
|
+
let fname = descr.import_app[import_ky]
|
|
416
|
+
let import_str = fs.readFileSync(input_dir + fname).toString()
|
|
417
|
+
template_str_2 = template_str_2.replace(import_ky,import_str)
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
let output = template_str_2
|
|
422
|
+
//
|
|
423
|
+
if ( descr.subst_l1 !== undefined ) {
|
|
424
|
+
//
|
|
425
|
+
let template_str_3 = template_str_2
|
|
426
|
+
//
|
|
427
|
+
let encoded_fields = descr.decode
|
|
428
|
+
let symbolic_keys = Object.keys(descr.subst_l1)
|
|
429
|
+
symbolic_keys.sort(key_complexity)
|
|
430
|
+
for ( let symbol_ky of symbolic_keys ) {
|
|
431
|
+
//
|
|
432
|
+
let value = descr.subst_l1[symbol_ky]
|
|
433
|
+
//
|
|
434
|
+
if ( symbol_ky.includes('{') ) {
|
|
435
|
+
let smap = value
|
|
436
|
+
if ( symbol_ky.includes('{}') ) {
|
|
437
|
+
for ( let symb_ky in smap ) {
|
|
438
|
+
let value = smap[symb_ky]
|
|
439
|
+
let nxt_symbol = symbol_ky.replace('{}',`[${value}]`)
|
|
440
|
+
template_str_3 = subst_str(template_str_3,nxt_symbol,value)
|
|
441
|
+
}
|
|
442
|
+
} else {
|
|
443
|
+
let sym_formula = extact_expr(symbol_ky,'{}')
|
|
444
|
+
let value = descr.subst_l1[sym_formula]
|
|
445
|
+
if ( value !== undefined ) {
|
|
446
|
+
//
|
|
447
|
+
if ( sym_formula.includes('[]') ) {
|
|
448
|
+
let value_ky_list = descr.subst_l1[sym_formula]
|
|
449
|
+
let n = value_ky_list.length
|
|
450
|
+
for ( let i = 0; i < n; i++ ) {
|
|
451
|
+
let v_ky = value_ky_list[i]
|
|
452
|
+
let value = smap[v_ky]
|
|
453
|
+
let sym_formula_i = sym_formula.replace('[]',`[${i}]`)
|
|
454
|
+
let sym_map_key = symbol_ky.replace(sym_formula,sym_formula_i)
|
|
455
|
+
template_str_3 = subst_str(template_str_3,sym_map_key,value)
|
|
456
|
+
}
|
|
457
|
+
} else {
|
|
458
|
+
let value = smap[value]
|
|
459
|
+
let nxt_symbol = symbol_ky.replace('{}',`[${value}]`)
|
|
460
|
+
template_str_3 = subst_str(template_str_3,nxt_symbol,value)
|
|
461
|
+
}
|
|
462
|
+
//
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
} else if ( symbol_ky.includes('[') ) {
|
|
466
|
+
let vlist = value
|
|
467
|
+
let n = vlist.length
|
|
468
|
+
for ( let i = 0; i < n; i++ ) {
|
|
469
|
+
let nxt_symbol = symbol_ky.replace('[]',`[${i}]`)
|
|
470
|
+
let value = vlist[i]
|
|
471
|
+
template_str_3 = subst_str(template_str_3,nxt_symbol,value)
|
|
472
|
+
}
|
|
473
|
+
} else {
|
|
474
|
+
if ( encoded_fields.indexOf(symbol_ky) >= 0 ) {
|
|
475
|
+
value = decodeURIComponent(value)
|
|
476
|
+
}
|
|
477
|
+
template_str_3 = subst_str(template_str_3,symbol_ky,value)
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
output = template_str_3
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
let outfile = odir + filename
|
|
484
|
+
console.log(outfile)
|
|
485
|
+
fs.writeFileSync(outfile,output)
|
|
486
|
+
//
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
//
|
|
490
|
+
}
|