From 01e977f922ea29cd2994f96c18e4b3f033b1802d Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Mon, 27 Dec 2021 16:55:28 +0100 Subject: facilitate egistering dynamic content scripts with mappings data --- compute_scripts.awk | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'compute_scripts.awk') diff --git a/compute_scripts.awk b/compute_scripts.awk index 9edc56d..b778934 100755 --- a/compute_scripts.awk +++ b/compute_scripts.awk @@ -108,7 +108,8 @@ BEGIN { function process_file(path, read_path, mode, line, result, line_part, directive, directive_args, - if_nesting, if_nesting_true, if_branch_processed) { + if_nesting, if_nesting_true, if_branch_processed, + additional_line_nr) { if (path in modes && modes[path] != mode) { printf "ERROR: File %s used multiple times in different contexts\n", path > "/dev/stderr" @@ -151,8 +152,13 @@ function process_file(path, read_path, mode, printf "ERROR: Could not read %s\n", read_path > "/dev/stderr" return 1 } - if (result == 0) - break + if (result == 0) { + if (path != js_to_amalgamate || \ + additional_line_nr == additional_lines_count) + break + + line = amalgamation_additional_lines[++additional_line_nr] + } if (line !~ /^#/) { if (if_nesting_true == if_nesting) @@ -169,9 +175,15 @@ function process_file(path, read_path, mode, return 1 } if (result == 0) { - printf "ERROR: Unexpected EOF in %s\n", - read_path > "/dev/stderr" - return 1 + if (path == js_to_amalgamate && \ + additional_line_nr < additional_lines_count) { + line_part = \ + amalgamation_additional_lines[++additional_line_nr] + } else { + printf "ERROR: Unexpected EOF in %s\n", + read_path > "/dev/stderr" + return 1 + } } line = line " " line_part @@ -569,7 +581,7 @@ function print_amalgamation(js_deps, js_deps_count, } function print_usage() { - printf "USAGE: %s compute_scripts.awk -- [-D PREPROCESSOR_DEFINITION]... [-M manifest/to/process/manifest.json]... [-H html/to/process.html]... [-J js/to/process.js]... [--help|-h] [--output-dir=./build] [--write-js-deps] [--write-html-deps] [--output=files-to-copy|--output=amalgamate-js:js/to/process.js]\n", + printf "USAGE: %s compute_scripts.awk -- [-D PREPROCESSOR_DEFINITION]... [-M manifest/to/process/manifest.json]... [-H html/to/process.html]... [-J js/to/process.js]... [--help|-h] [--output-dir=./build] [--write-js-deps] [--write-html-deps] [--output=files-to-copy|--output=amalgamate-js:js/to/process.js[:additional-code]]\n", ARGV[0] > "/dev/stderr" } @@ -580,13 +592,16 @@ BEGIN { option_arg_patterns["J"] = path_re } -function main(i, path, letter, dir, max_line_nr, js_deps, js_deps_count) { +function main(i, path, letter, dir, max_line_nr, js_deps, js_deps_count, + amalgamation_additional_code) { output_dir = "./build" write_js_deps = false write_html_deps = false output = "" js_to_amalgamate = "" + delete amalgamation_additional_lines[0] + additional_lines_count = 0 delete main_js_lines[0] delete manifests_to_process[0] @@ -629,13 +644,21 @@ function main(i, path, letter, dir, max_line_nr, js_deps, js_deps_count) { output = "files-to-copy" } else if (ARGV[i] ~ /^--output=amalgamate-js:/) { output = "amalgamate-js" - js_to_amalgamate = ARGV[i] - sub(/^--output=amalgamate-js:/, "", js_to_amalgamate) + amalgamation_additional_code = ARGV[i] + sub(/^--output=amalgamate-js:/, "", amalgamation_additional_code) + js_to_amalgamate = amalgamation_additional_code + sub(/:.*$/, "", js_to_amalgamate) if (js_to_amalgamate !~ path_re) { printf "ERROR: amalgamate-js path does not match '%s': %s\n", path_re, js_to_amalgamate > "/dev/stderr" return 1 } + sub(/^[^:]+:?/, "", amalgamation_additional_code) + if (amalgamation_additional_code) { + additional_lines_count = split(amalgamation_additional_code, + amalgamation_additional_lines, + "\n") + } } else { printf "ERROR: Unknown option '%s'\n", ARGV[i] > "/dev/stderr" print_usage() -- cgit v1.2.3