@@ -11,35 +11,22 @@ const {
1111 mkdirSync,
1212 realpathSync,
1313} = require ( "node:fs" ) ;
14- const nodesSourceDir = cwd ( ) + "/src/nodes " ;
15- const nodesTargetDir = cwd ( ) + "/dist/nodes " ;
14+ const sourcePath = cwd ( ) + "/src" ;
15+ const targetPath = cwd ( ) + "/dist" ;
1616const buildTsConfig = JSON . parse ( readFileSync ( "build.tsconfig.json" ) . toString ( ) ) ;
1717
18- function makeDir ( dir ) {
19- if ( ! existsSync ( dir ) ) {
20- console . log ( dir ) ;
21- const parentDir = realpathSync ( `${ dir } ../` ) ;
22- console . log ( parentDir ) ;
23- if ( ! existsSync ( parentDir ) ) {
24- makeDir ( parentDir ) ;
25- }
26-
27- mkdirSync ( dir ) ;
28- }
29- }
30-
3118/**
3219 * @param node String
33- * @param sourcePath String
34- * @param targetPath String
20+ * @param source String
21+ * @param target String
3522 */
36- function buildForm ( node , sourcePath , targetPath ) {
23+ function buildNodeForm ( node , source , target ) {
3724 /**
3825 * @type {string[] }
3926 */
4027 const html = [ ] ;
41- const form = readFileSync ( `${ sourcePath } /form.html` ) . toString ( ) ;
42- const docs = existsSync ( `${ sourcePath } /docs.html` ) ? readFileSync ( `${ sourcePath } /docs.html` ) . toString ( ) : undefined ;
28+ const form = readFileSync ( `${ source } /form.html` ) . toString ( ) ;
29+ const docs = existsSync ( `${ source } /docs.html` ) ? readFileSync ( `${ source } /docs.html` ) . toString ( ) : undefined ;
4330
4431 const formLines = form . split ( "\n" ) ;
4532 html . push ( `<script type="text/html" data-template-name="${ node } ">` ) ;
@@ -61,7 +48,7 @@ function buildForm(node, sourcePath, targetPath) {
6148 html . push ( "</script>" ) ;
6249 }
6350
64- const initTS = readFileSync ( `${ sourcePath } /init.ts` ) . toString ( ) ;
51+ const initTS = readFileSync ( `${ source } /init.ts` ) . toString ( ) ;
6552 let initJS = ts
6653 . transpileModule ( initTS , buildTsConfig )
6754 . outputText . replace ( / e x p o r t \{ (?: [ ^ \} ] + ) ? \} ; / gim, "" )
@@ -78,32 +65,32 @@ function buildForm(node, sourcePath, targetPath) {
7865
7966 html . push ( "" ) ;
8067
81- mkdirSync ( `${ targetPath } /` , {
68+ mkdirSync ( `${ target } /` , {
8269 recursive : true ,
8370 } ) ;
8471
85- writeFileSync ( `${ targetPath } /${ node } .html` , html . join ( "\n" ) ) ;
72+ writeFileSync ( `${ target } /${ node } .html` , html . join ( "\n" ) ) ;
8673}
8774
8875/**
8976 * @param node String
90- * @param sourcePath String
91- * @param targetPath String
77+ * @param source String
78+ * @param target String
9279 */
93- function copyLocales ( node , sourcePath , targetPath ) {
94- if ( ! existsSync ( `${ sourcePath } /locales` ) ) {
80+ function copyNodeLocales ( node , source , target ) {
81+ if ( ! existsSync ( `${ source } /locales` ) ) {
9582 return ;
9683 }
9784
98- readdirSync ( `${ sourcePath } /locales` , {
85+ readdirSync ( `${ source } /locales` , {
9986 recursive : false ,
10087 } )
10188 . filter ( ( language ) => {
10289 return language . match ( / ^ [ a - z ] { 2 , 2 } (?: - [ A - Z ] { 2 , 2 } ) ? \. j s o n $ / ) ;
10390 } )
10491 . forEach ( ( language ) => {
10592 const languageCode = language . match ( / ^ ( [ a - z ] { 2 , 2 } (?: - [ A - Z ] { 2 , 2 } ) ? ) \. j s o n $ / i) [ 1 ] ;
106- const content = readFileSync ( `${ sourcePath } /locales/${ language } ` ) . toString ( ) ;
93+ const content = readFileSync ( `${ source } /locales/${ language } ` ) . toString ( ) ;
10794
10895 /**
10996 * @type {string[] }
@@ -120,27 +107,75 @@ function copyLocales(node, sourcePath, targetPath) {
120107 } ) ;
121108 json . push ( "}" ) ;
122109
123- mkdirSync ( `${ targetPath } /locales/${ languageCode } ` , {
110+ mkdirSync ( `${ target } /locales/${ languageCode } ` , {
124111 recursive : true ,
125112 } ) ;
126113
127- writeFileSync ( `${ targetPath } /locales/${ languageCode } /${ node } .json` , json . join ( "\n" ) ) ;
114+ writeFileSync ( `${ target } /locales/${ languageCode } /${ node } .json` , json . join ( "\n" ) ) ;
128115 } ) ;
129116}
130117
131- readdirSync ( nodesSourceDir , {
132- recursive : false ,
133- } )
134- . filter ( ( node ) => {
135- const path = `${ nodesSourceDir } /${ node } ` ;
118+ function buildNodes ( ) {
119+ readdirSync ( `${ sourcePath } /nodes` , {
120+ recursive : false ,
121+ } )
122+ . filter ( ( node ) => {
123+ const path = `${ sourcePath } /nodes/${ node } ` ;
124+
125+ return existsSync ( `${ path } /form.html` ) && existsSync ( `${ path } /${ node } .ts` ) ;
126+ } )
127+ . forEach ( ( node ) => {
128+ console . info ( `Building node ${ node } ` ) ;
136129
137- return existsSync ( `${ path } /form.html` ) && existsSync ( `${ path } /${ node } .ts` ) ;
130+ const source = `${ sourcePath } /nodes/${ node } ` ;
131+ const target = `${ targetPath } /nodes/${ node } ` ;
132+
133+ buildNodeForm ( node , source , target ) ;
134+
135+ copyNodeLocales ( node , source , target ) ;
136+ } ) ;
137+ }
138+
139+ function buildPlugins ( ) {
140+ readdirSync ( `${ sourcePath } /plugins` , {
141+ recursive : false ,
138142 } )
139- . forEach ( ( node ) => {
140- const sourcePath = `${ nodesSourceDir } /${ node } ` ;
141- const targetPath = `${ nodesTargetDir } /${ node } ` ;
143+ . filter ( ( plugin ) => {
144+ const path = `${ sourcePath } /plugins/${ plugin } ` ;
142145
143- buildForm ( node , sourcePath , targetPath ) ;
146+ return existsSync ( `${ path } /${ plugin } .ts` ) ;
147+ } )
148+ . forEach ( ( plugin ) => {
149+ console . info ( `Building plugin ${ plugin } ` ) ;
144150
145- copyLocales ( node , sourcePath , targetPath ) ;
146- } ) ;
151+ // does nothing yet
152+ } ) ;
153+ }
154+
155+ function buildThemes ( ) {
156+ readdirSync ( `${ sourcePath } /themes` , {
157+ recursive : false ,
158+ } )
159+ . filter ( ( theme ) => {
160+ const path = `${ sourcePath } /themes/${ theme } ` ;
161+
162+ return existsSync ( `${ path } /${ theme } .ts` ) ;
163+ } )
164+ . forEach ( ( theme ) => {
165+ console . info ( `Building theme ${ theme } ` ) ;
166+
167+ // does nothing yet
168+ } ) ;
169+ }
170+
171+ if ( existsSync ( `${ sourcePath } /plugins` ) ) {
172+ buildPlugins ( ) ;
173+ }
174+
175+ if ( existsSync ( `${ sourcePath } /nodes` ) ) {
176+ buildNodes ( ) ;
177+ }
178+
179+ if ( existsSync ( `${ sourcePath } /themes` ) ) {
180+ buildThemes ( ) ;
181+ }
0 commit comments