11/**
22 * Written by Denis Power.
33 *
4- * globalconfig.json options.
4+ * builderconfig options.
55 *
66 * {
7- * files: [],
7+ * files: string [],
88 * dir: "./core",
9- * types: "./types"
9+ * types: {
10+ * dir: "./types",
11+ * files: string[]
12+ * }
1013 * }
1114 *
1215 *
1316 *
1417 */
1518
16- const { writeFileSync, readFileSync, readdirSync } = require ( "fs" ) ;
17- const { format } = require ( "prettier" ) ;
18- const config = getConfig ( ) ;
19+ console . log ( "Building..." )
20+
21+ import builderconfig from "./builderconfig.js" ;
22+ import { writeFileSync , readFileSync , readdirSync } from "node:fs" ;
23+ import { format } from "prettier" ;
24+
25+ const {
26+ version,
27+ year,
28+ files,
29+ dir,
30+ types : { dir : typeDir , version : typeVersion } ,
31+ } = builderconfig ;
32+
1933const Package = JSON . parse ( readFileSync ( "./package.json" ) ) ;
2034const packageLock = JSON . parse ( readFileSync ( "./package-lock.json" ) ) ;
21- const buildVersion = process . argv [ 2 ] ;
22- const buildYear = process . argv [ 3 ] ;
23- const buildType = process . argv [ 4 ] ;
24- const typeVersion = process . argv [ 5 ] ;
25- const isGlobalBuild = buildType . toUpperCase ( ) == "GLOBAL" ;
26- const isModuleBuild = buildType . toUpperCase ( ) == "MODULE" ;
27- const isTsDeclaration = buildType . toUpperCase ( ) == "TYPES" ;
2835
2936class Inter {
3037 #source;
@@ -120,38 +127,21 @@ function isBlankSpace(code) {
120127 return / \s / . test ( code ) ;
121128}
122129
123- function getConfig ( ) {
124- const resultObject = {
125- hasFile : false ,
126- file : void 0 ,
127- } ;
128-
129- try {
130- resultObject . file = JSON . parse ( readFileSync ( "./builderconfig.json" ) ) ;
131- resultObject . hasFile = true ;
132- } catch ( e ) {
133- /*No globalconfig.json*/
134- }
135-
136- return resultObject ;
137- }
138-
139- if ( ! config . hasFile ) throw new Error ( "No `globalconfig.json` file found" ) ;
130+ if ( ! files ) throw new Error ( "No `builderconfing.js` file found" ) ;
140131
141132function buildTsDeclaration ( ) {
142- const { types } = config . file ;
143- const files = readdirSync ( types ) ;
144133 let body = "" ;
134+ const typeFiles = readdirSync ( typeDir ) ;
145135
146- for ( const file of files ) {
147- const fileString = readFileSync ( `${ types } /${ file } ` ) ;
136+ for ( const file of typeFiles ) {
137+ const fileString = readFileSync ( `${ typeDir } /${ file } ` ) ;
148138 body += fileString ;
149139 }
150140
151141 body = `
152142 /***
153143 * MIT LICENSED BY - Denis Power(Inter creator)
154- * Typescript declaration file for Inter version ${ buildVersion }
144+ * Typescript declaration file for Inter version ${ version }
155145 * Version - ${ typeVersion }
156146 * Repo - https://github.com/interjs/inter/types
157147 * GENERATED BY INTER BUILDER
@@ -164,8 +154,9 @@ function buildTsDeclaration() {
164154 writeFileSync ( "inter.m.d.ts" , body ) ;
165155}
166156
167- function build ( ) {
168- const { files, dir } = config . file ;
157+ function build ( buildType ) {
158+ const isModuleBuild = buildType == "module" ;
159+ const isGlobalBuild = buildType == "global" ;
169160
170161 let body = "" ;
171162
@@ -208,10 +199,10 @@ function build() {
208199
209200/**
210201 * Interjs
211- * Version - ${ buildVersion }
202+ * Version - ${ version }
212203 * MIT LICENSED BY - Denis Power
213204 * Repo - https://github.com/interjs/inter
214- * 2021 - ${ buildYear }
205+ * 2021 - ${ year }
215206 * GENERATED BY INTER BUILDER
216207 *
217208 */
@@ -226,7 +217,7 @@ function build() {
226217 window.template = template;
227218 window.toAttrs = toAttrs;
228219 window.Backend = Backend;
229- console.log("The global version ${ buildVersion } of Inter was loaded successfully.")
220+ console.log("The global version ${ version } of Inter was loaded successfully.")
230221
231222 })();
232223
@@ -236,28 +227,31 @@ function build() {
236227
237228/**
238229 * Interjs
239- * Version - ${ buildVersion }
230+ * Version - ${ version }
240231 * MIT LICENSED BY - Denis Power
241232 * Repo - https://github.com/interjs/inter
242- * 2021 - ${ buildYear }
233+ * 2021 - ${ year }
243234 * GENERATED BY INTER BUILDER
244235 * Module version
245236 */
246237
247- export const interVersion = "${ buildVersion } ";
238+ export const interVersion = "${ version } ";
248239${ builtCode }
249240 ` ;
250241 }
251242
252243 if ( isGlobalBuild ) writeFileSync ( "inter.js" , format ( body ) ) ;
253244 else if ( isModuleBuild ) writeFileSync ( "inter.m.js" , format ( body ) ) ;
254245
255- Package . version = buildVersion ;
256- packageLock . version = buildVersion ;
246+ Package . version = version ;
247+ packageLock . version = version ;
257248
258249 writeFileSync ( "package.json" , JSON . stringify ( Package ) ) ;
259250 writeFileSync ( "package-lock.json" , JSON . stringify ( packageLock ) ) ;
260251}
261252
262- if ( isTsDeclaration ) buildTsDeclaration ( ) ;
263- else build ( ) ;
253+ buildTsDeclaration ( ) ;
254+ build ( "global" ) ;
255+ build ( "module" ) ;
256+
257+ console . log ( "Inter Built Successfully" )
0 commit comments