1
1
#! /usr/bin/env node
2
-
3
- import type { Configs } from '../@types/poku.js' ;
4
2
import { escapeRegExp } from '../modules/helpers/list-files.js' ;
5
3
import { getArg , getPaths , hasArg , argToArray } from '../parsers/get-arg.js' ;
6
4
import { states } from '../configs/files.js' ;
@@ -10,26 +8,25 @@ import { envFile } from '../modules/helpers/env.js';
10
8
import { poku } from '../modules/essentials/poku.js' ;
11
9
import { log , hr } from '../services/write.js' ;
12
10
import { getConfigs } from '../parsers/options.js' ;
11
+ import { GLOBAL , VERSION } from '../configs/poku.js' ;
13
12
14
13
( async ( ) => {
15
14
if ( hasArg ( 'version' ) || hasArg ( 'v' , '-' ) ) {
16
- const { VERSION } = require ( '../configs/poku.js' ) ;
17
-
18
15
log ( VERSION ) ;
19
16
return ;
20
17
}
21
18
22
19
if ( hasArg ( 'help' ) || hasArg ( 'h' , '-' ) ) {
23
- const { help } = require ( './help.js' ) ;
24
-
25
- help ( ) ;
26
-
20
+ require ( './help.js' ) . help ( ) ;
27
21
return ;
28
22
}
29
23
30
24
const enforce = hasArg ( 'enforce' ) || hasArg ( 'x' , '-' ) ;
31
25
const configFile = getArg ( 'config' ) || getArg ( 'c' , '-' ) ;
32
- const defaultConfigs = await getConfigs ( configFile ) ;
26
+
27
+ GLOBAL . defaultConfigs = await getConfigs ( configFile ) ;
28
+ const { defaultConfigs } = GLOBAL ;
29
+
33
30
const dirs : string [ ] =
34
31
getPaths ( '-' ) ??
35
32
( defaultConfigs ?. include
@@ -98,13 +95,36 @@ import { getConfigs } from '../parsers/options.js';
98
95
return ;
99
96
}
100
97
101
- if ( enforce ) {
102
- const { checkFlags } = require ( './enforce.js' ) ;
98
+ GLOBAL . configFile = configFile ;
99
+ GLOBAL . options = {
100
+ filter :
101
+ typeof filter === 'string' ? new RegExp ( escapeRegExp ( filter ) ) : filter ,
102
+ exclude :
103
+ typeof exclude === 'string' ? new RegExp ( escapeRegExp ( exclude ) ) : exclude ,
104
+ concurrency,
105
+ sequential,
106
+ quiet,
107
+ debug,
108
+ failFast,
109
+ deno : {
110
+ allow : denoAllow ,
111
+ deny : denoDeny ,
112
+ cjs : denoCJS ,
113
+ } ,
114
+ noExit : watchMode ,
115
+ beforeEach :
116
+ 'beforeEach' in defaultConfigs ? defaultConfigs . beforeEach : undefined ,
117
+ afterEach :
118
+ 'afterEach' in defaultConfigs ? defaultConfigs . afterEach : undefined ,
119
+ } ;
120
+
121
+ const tasks : Promise < unknown > [] = [];
103
122
104
- checkFlags ( ) ;
123
+ if (hasEnvFile || defaultConfigs?.envFile) {
124
+ GLOBAL . envFile = getArg ( 'envFile' ) ?? defaultConfigs ?. envFile ?? '.env' ;
105
125
}
106
126
107
- const tasks : Promise < unknown > [] = [] ;
127
+ if (enforce) require('../services/enforce.js').enforce() ;
108
128
109
129
/* c8 ignore start */ // Process-based
110
130
if (killPort || defaultConfigs?.kill?.port) {
@@ -135,33 +155,7 @@ import { getConfigs } from '../parsers/options.js';
135
155
}
136
156
/* c8 ignore stop */
137
157
138
- if (hasEnvFile || defaultConfigs?.envFile) {
139
- const envFilePath = getArg ( 'envFile' ) ?? defaultConfigs ?. envFile ;
140
-
141
- tasks . push ( envFile ( envFilePath ) ) ;
142
- }
143
-
144
- const options: Configs = {
145
- filter :
146
- typeof filter === 'string' ? new RegExp ( escapeRegExp ( filter ) ) : filter ,
147
- exclude :
148
- typeof exclude === 'string' ? new RegExp ( escapeRegExp ( exclude ) ) : exclude ,
149
- concurrency ,
150
- sequential ,
151
- quiet ,
152
- debug ,
153
- failFast ,
154
- deno : {
155
- allow : denoAllow ,
156
- deny : denoDeny ,
157
- cjs : denoCJS ,
158
- } ,
159
- noExit : watchMode ,
160
- beforeEach :
161
- 'beforeEach' in defaultConfigs ? defaultConfigs . beforeEach : undefined ,
162
- afterEach :
163
- 'afterEach' in defaultConfigs ? defaultConfigs . afterEach : undefined ,
164
- } ;
158
+ GLOBAL.envFile && tasks . push ( envFile ( GLOBAL . envFile ) ) ;
165
159
166
160
if ( debug || defaultConfigs ?. debug ) {
167
161
hr ( ) ;
@@ -170,15 +164,11 @@ import { getConfigs } from '../parsers/options.js';
170
164
console . table ( dirs ) ;
171
165
log ( '\n' ) ;
172
166
log ( `${ format ( '…' ) . info ( ) . italic ( ) } ${ format ( 'Options' ) . bold ( ) } ` ) ;
173
- console . dir ( options , { depth : null , colors : true } ) ;
167
+ console . dir ( GLOBAL . options , { depth : null , colors : true } ) ;
174
168
}
175
169
176
170
await Promise.all(tasks);
177
- await poku(dirs, options);
178
-
179
- if (watchMode) {
180
- const { startWatch } = require ( './watch.js' ) ;
171
+ await poku(dirs, GLOBAL.options);
181
172
182
- await startWatch ( dirs , options ) ;
183
- }
173
+ if (watchMode) await require('./watch.js').startWatch(dirs, GLOBAL.options);
184
174
} ) ( ) ;
0 commit comments