11import { existsSync } from "fs" ;
2-
2+ import { LesyCoreClass } from "@lesy/core" ;
33class LesyCompiler {
44 opts : any = {
55 isTypescriptApp : false ,
@@ -18,24 +18,24 @@ class LesyCompiler {
1818 private tsConfigPath = null ;
1919
2020 exec ( opts = { } ) {
21- this . opts = { ...this . opts , ...opts } ;
22- const {
23- isTypescriptApp,
24- root,
25- srcFilePath,
26- tsFlag,
27- loadDefaultPlugins,
28- customTsConfig,
29- ...src
30- } = this . opts ;
31- const hasSrcData = Object . keys ( src ) . length > 0 ;
32- const hasBuildDir = existsSync ( `${ root } /dist` ) ;
33- const shouldRunTSCode = process . argv . includes ( tsFlag ) ;
21+ Object . assign ( this . opts , opts ) ;
22+ const src = {
23+ commands : this . opts . commands || [ ] ,
24+ middlewares : this . opts . middlewares || [ ] ,
25+ features : this . opts . features || [ ] ,
26+ plugins : this . opts . plugins || [ ] ,
27+ config : this . opts . config || { } ,
28+ validators : this . opts . validators || [ ] ,
29+ } ;
30+ const hasSrcData = this . opts . commands ;
3431 let mainFilePath : string ;
3532 process . env . LESY_LANG = "js" ;
36- if ( ! isTypescriptApp ) {
37- mainFilePath = ! hasSrcData && require . resolve ( root ) ;
33+ if ( ! this . opts . isTypescriptApp ) {
34+ mainFilePath = ! hasSrcData && require . resolve ( this . opts . root ) ;
3835 } else {
36+ const { root, tsFlag, srcFilePath, customTsConfig } = this . opts ;
37+ const hasBuildDir = existsSync ( `${ root } /dist` ) ;
38+ const shouldRunTSCode = process . argv . includes ( tsFlag ) ;
3939 if ( ( hasBuildDir && shouldRunTSCode ) || ! hasBuildDir ) {
4040 // run src
4141 process . env . LESY_LANG = "ts" ;
@@ -48,7 +48,6 @@ class LesyCompiler {
4848 mainFilePath = ! hasSrcData && require . resolve ( root ) ;
4949 }
5050 }
51-
5251 return this . runApp ( hasSrcData ? src : require ( mainFilePath ) ) ;
5352 }
5453
@@ -71,33 +70,30 @@ class LesyCompiler {
7170 }
7271
7372 private runApp ( appData ) {
74- const { LesyCore, LesyCoreClass } = require ( "@lesy/core" ) ;
75- const { root } = this . opts ;
76- Object . assign ( appData , this . includeEssentials ( appData ) ) ;
77-
73+ this . includeEssentials ( appData ) ;
74+ appData . root = this . opts . root ;
7875 const lesy = new LesyCoreClass ( )
79- . bootstrap ( { ... appData , root } )
76+ . bootstrap ( appData )
8077 . catch ( ( e : any ) => console . log ( "LESY ERROR:" , e ) ) ;
81-
8278 return {
8379 parse : ( argv : string [ ] ) =>
84- lesy . then ( ( l ) => {
80+ lesy . then ( ( l : any ) => {
8581 if ( global [ "lesyWorkspace" ] ) return l ;
8682 return l . run ( argv || process . argv . slice ( 2 ) ) ;
8783 } ) ,
8884 } ;
8985 }
9086
9187 private includeEssentials ( appData ) {
92- let { plugins = [ ] , config = { } } = appData ;
9388 if ( this . opts . loadDefaultPlugins ) {
94- plugins = [
89+ appData . plugins = [
9590 ...this . defaultPlugins . map ( ( p : string ) => require . resolve ( p ) ) ,
96- ...plugins ,
91+ ...appData . plugins ,
9792 ] ;
9893 }
99- config = { ...this . defaultConfig , ...config } ;
100- return { ...appData , plugins, config } ;
94+ const config = this . defaultConfig ;
95+ for ( const prop in appData . config ) config [ prop ] = appData . config [ prop ] ;
96+ appData . config = config ;
10197 }
10298}
10399
0 commit comments