1 | import { exec as execAsync } from 'child_process';
|
2 |
|
3 |
|
4 |
|
5 | export function buildStatic(params: {
|
6 | exclude: string | undefined;
|
7 | include: string | undefined;
|
8 | httpPort: number;
|
9 | }): void {
|
10 | const excludeRegex = `${params.exclude ? params.exclude.split(',').join('*|') : 'NO_EXCLUDE'}*`;
|
11 | const includeRegex = `${params.include ? params.include.split(',').join('*|') : 'NO_INCLUDE'}*`;
|
12 |
|
13 | const asyncExec = execAsync(`
|
14 | echo "Copy current working directory to ZWITTERION_TEMP directory"
|
15 |
|
16 | originalDirectory=$(pwd)
|
17 |
|
18 | rm -rf dist
|
19 | cd ..
|
20 | rm -rf ZWITTERION_TEMP
|
21 | cp -r $originalDirectory ZWITTERION_TEMP
|
22 | cd ZWITTERION_TEMP
|
23 |
|
24 | echo "Download and save all .html files from Zwitterion"
|
25 |
|
26 | shopt -s globstar
|
27 | for file in **/*.html; do
|
28 | if [[ ! $file =~ ${excludeRegex} ]] || [[ $file =~ ${includeRegex} ]]
|
29 | then
|
30 | echo $file
|
31 | wget -q -x -nH "http://localhost:${params.httpPort}/$file"
|
32 | fi
|
33 | done
|
34 |
|
35 | echo "Download and save all .js files from Zwitterion"
|
36 |
|
37 | shopt -s globstar
|
38 | for file in **/*.js; do
|
39 | if [[ ! $file =~ ${excludeRegex} ]] || [[ $file =~ ${includeRegex} ]]
|
40 | then
|
41 | echo $file
|
42 | wget -q -x -nH "http://localhost:${params.httpPort}/$\{file%.*\}.js"
|
43 | fi
|
44 | done
|
45 |
|
46 | echo "Download and save all .ts files from Zwitterion"
|
47 |
|
48 | shopt -s globstar
|
49 | for file in **/*.ts; do
|
50 | if [[ ! $file =~ ${excludeRegex} ]] || [[ $file =~ ${includeRegex} ]]
|
51 | then
|
52 | echo $file
|
53 | wget -q -x -nH "http://localhost:${params.httpPort}/$\{file%.*\}.ts"
|
54 | fi
|
55 | done
|
56 |
|
57 | echo "Download and save all .as files from Zwitterion"
|
58 |
|
59 | shopt -s globstar
|
60 | for file in **/*.as; do
|
61 | if [[ ! $file =~ ${excludeRegex} ]]
|
62 | then
|
63 | wget -q -x -nH "http://localhost:${params.httpPort}/$\{file%.*\}.as"
|
64 | fi
|
65 | done
|
66 |
|
67 | echo "Download and save all .wasm files from Zwitterion"
|
68 |
|
69 | shopt -s globstar
|
70 | for file in **/*.wasm; do
|
71 | if [[ ! $file =~ ${excludeRegex} ]]
|
72 | then
|
73 | wget -q -x -nH "http://localhost:${params.httpPort}/$\{file%.*\}.wasm"
|
74 | fi
|
75 | done
|
76 |
|
77 | #echo "Download and save all .rs files from Zwitterion"
|
78 |
|
79 | #shopt -s globstar
|
80 | #for file in **/*.rs; do
|
81 | # if [[ ! $file =~ ${excludeRegex} ]]
|
82 | # then
|
83 | # wget -q -x -nH "http://localhost:${params.httpPort}/$\{file%.*\}.rs"
|
84 | # fi
|
85 | #done
|
86 |
|
87 | #echo "Download and save all .tsx files from Zwitterion"
|
88 |
|
89 | #shopt -s globstar
|
90 | #for file in **/*.tsx; do
|
91 | # if [[ ! $file =~ ${excludeRegex} ]] || [[ $file =~ ${includeRegex} ]]
|
92 | # then
|
93 | # echo $file
|
94 | # wget -q -x -nH "http://localhost:${params.httpPort}/$\{file%.*\}.tsx"
|
95 | # fi
|
96 | #done
|
97 |
|
98 | #echo "Download and save all .jsx files from Zwitterion"
|
99 |
|
100 | #shopt -s globstar
|
101 | #for file in **/*.jsx; do
|
102 | # if [[ ! $file =~ ${excludeRegex} ]] || [[ $file =~ ${includeRegex} ]]
|
103 | # then
|
104 | # echo $file
|
105 | # wget -q -x -nH "http://localhost:${params.httpPort}/$\{file%.*\}.jsx"
|
106 | # fi
|
107 | #done
|
108 |
|
109 | #echo "Download and save all .c files from Zwitterion"
|
110 |
|
111 | #shopt -s globstar
|
112 | #for file in **/*.c; do
|
113 | # if [[ ! $file =~ ${excludeRegex} ]]
|
114 | # then
|
115 | # wget -q -x -nH "http://localhost:${params.httpPort}/$\{file%.*\}.c"
|
116 | # fi
|
117 | #done
|
118 |
|
119 | #echo "Download and save all .cc files from Zwitterion"
|
120 |
|
121 | #shopt -s globstar
|
122 | #for file in **/*.cc; do
|
123 | # if [[ ! $file =~ ${excludeRegex} ]]
|
124 | # then
|
125 | # wget -q -x -nH "http://localhost:${params.httpPort}/$\{file%.*\}.cc"
|
126 | # fi
|
127 | #done
|
128 |
|
129 | #echo "Download and save all .cpp files from Zwitterion"
|
130 |
|
131 | #shopt -s globstar
|
132 | #for file in **/*.cpp; do
|
133 | # if [[ ! $file =~ ${excludeRegex} ]]
|
134 | # then
|
135 | # wget -q -x -nH "http://localhost:${params.httpPort}/$\{file%.*\}.cpp"
|
136 | # fi
|
137 | #done
|
138 |
|
139 | echo "Copy ZWITTERION_TEMP to dist directory in the project root directory"
|
140 |
|
141 | cd ..
|
142 | cp -r ZWITTERION_TEMP $originalDirectory/dist
|
143 | rm -rf ZWITTERION_TEMP
|
144 |
|
145 | echo "Static build finished"
|
146 | `, {
|
147 | shell: '/bin/bash'
|
148 | }, () => {
|
149 | process.exit();
|
150 | });
|
151 |
|
152 | if (
|
153 | asyncExec.stdout !== null
|
154 | ) {
|
155 | asyncExec.stdout.pipe(process.stdout);
|
156 | }
|
157 |
|
158 | if (
|
159 | asyncExec.stderr !== null
|
160 | ) {
|
161 | asyncExec.stderr.pipe(process.stderr);
|
162 | }
|
163 | } |
\ | No newline at end of file |