@itee/tasks 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/tasks.iml +8 -0
- package/.idea/vcs.xml +6 -0
- package/CHANGELOG.md +56 -0
- package/README.md +1 -0
- package/configs/builds/build.conf.mjs +1 -0
- package/configs/cleans/clean.conf.mjs +1 -0
- package/configs/docs/doc.conf.json +1 -0
- package/configs/lints/lint.conf.mjs +91 -0
- package/configs/refresh.conf.mjs +1 -0
- package/configs/tests/benchmarks/compute-benchmarks.conf.mjs +5 -0
- package/configs/tests/benchmarks/run-benchmarks-for-frontend.conf.mjs +37 -0
- package/configs/tests/benchmarks/run-benchmarks.conf.mjs +7 -0
- package/configs/tests/bundlings/check-bundling-from-esm-build-import.conf.mjs +45 -0
- package/configs/tests/bundlings/check-bundling-from-esm-files-direct.conf.mjs +51 -0
- package/configs/tests/bundlings/check-bundling-from-esm-files-import.conf.mjs +48 -0
- package/configs/tests/units/compute-unit-tests.conf.mjs +5 -0
- package/configs/tests/units/run-unit-tests-for-frontend.conf.mjs +14 -0
- package/configs/tests/units/run-unit-tests.conf.mjs +7 -0
- package/package.json +100 -0
- package/sources/_utils.mjs +412 -0
- package/sources/builds/build.task.mjs +52 -0
- package/sources/cleans/clean.task.mjs +32 -0
- package/sources/docs/doc.task.mjs +48 -0
- package/sources/helps/help.task.mjs +155 -0
- package/sources/index.mjs +21 -0
- package/sources/lints/lint.task.mjs +46 -0
- package/sources/refresh.mjs +100 -0
- package/sources/releases/release.task.mjs +32 -0
- package/sources/tests/benchmarks/compute-benchmarks.task.mjs +236 -0
- package/sources/tests/benchmarks/run-benchmarks-for-backend.task.mjs +43 -0
- package/sources/tests/benchmarks/run-benchmarks-for-frontend.task.mjs +48 -0
- package/sources/tests/benchmarks/run-benchmarks.task.mjs +16 -0
- package/sources/tests/bundlings/check-bundling-from-esm-build-import.task.mjs +127 -0
- package/sources/tests/bundlings/check-bundling-from-esm-files-direct.task.mjs +94 -0
- package/sources/tests/bundlings/check-bundling-from-esm-files-import.task.mjs +113 -0
- package/sources/tests/bundlings/check-bundling.task.mjs +24 -0
- package/sources/tests/run-tests.task.mjs +22 -0
- package/sources/tests/units/compute-unit-tests.task.mjs +547 -0
- package/sources/tests/units/run-unit-tests-for-backend.task.mjs +48 -0
- package/sources/tests/units/run-unit-tests-for-frontend.task.mjs +48 -0
- package/sources/tests/units/run-unit-tests.task.mjs +16 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import colors from 'ansi-colors'
|
|
2
|
+
import childProcess from 'child_process'
|
|
3
|
+
import log from 'fancy-log'
|
|
4
|
+
import { glob } from 'glob'
|
|
5
|
+
import {
|
|
6
|
+
parallel,
|
|
7
|
+
series
|
|
8
|
+
} from 'gulp'
|
|
9
|
+
import {
|
|
10
|
+
existsSync,
|
|
11
|
+
mkdirSync,
|
|
12
|
+
readFileSync,
|
|
13
|
+
writeFileSync
|
|
14
|
+
} from 'node:fs'
|
|
15
|
+
import {
|
|
16
|
+
basename,
|
|
17
|
+
dirname,
|
|
18
|
+
extname,
|
|
19
|
+
join,
|
|
20
|
+
normalize,
|
|
21
|
+
relative,
|
|
22
|
+
} from 'node:path'
|
|
23
|
+
import { fileURLToPath } from 'node:url'
|
|
24
|
+
|
|
25
|
+
const {
|
|
26
|
+
red,
|
|
27
|
+
green,
|
|
28
|
+
yellow,
|
|
29
|
+
blue,
|
|
30
|
+
magenta,
|
|
31
|
+
cyan
|
|
32
|
+
} = colors
|
|
33
|
+
|
|
34
|
+
///
|
|
35
|
+
|
|
36
|
+
function createDirectoryIfNotExist( directoryPath ) {
|
|
37
|
+
|
|
38
|
+
if ( !existsSync( directoryPath ) ) {
|
|
39
|
+
log( 'Creating', green( directoryPath ) )
|
|
40
|
+
mkdirSync( directoryPath, { recursive: true } )
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getJsonFrom( path ) {
|
|
46
|
+
|
|
47
|
+
const buffer = readFileSync( path )
|
|
48
|
+
return JSON.parse( buffer.toString() )
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getTaskConfigurationPathFor( filename ) {
|
|
53
|
+
|
|
54
|
+
// Get relative path of the task between internal or user defined
|
|
55
|
+
let relativeTaskPath = filename.includes( iteePackageSourcesDirectory )
|
|
56
|
+
? relative( iteePackageSourcesDirectory, filename )
|
|
57
|
+
: relative( packageTasksDirectory, filename )
|
|
58
|
+
|
|
59
|
+
// Generate all possible config file path depending on file extension and default or user defined
|
|
60
|
+
const terminalExtension = extname( relativeTaskPath )
|
|
61
|
+
const searchValue = relativeTaskPath.includes( '.task.' ) ? `.task${ terminalExtension }` : terminalExtension
|
|
62
|
+
const replaceValues = [
|
|
63
|
+
'.conf.json',
|
|
64
|
+
'.conf.js',
|
|
65
|
+
'.conf.mjs',
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
const packageConfigurationPaths = []
|
|
69
|
+
const defaultConfigurationPaths = []
|
|
70
|
+
|
|
71
|
+
for ( const replaceValue of replaceValues ) {
|
|
72
|
+
const configurationLocation = relativeTaskPath.replace( searchValue, replaceValue )
|
|
73
|
+
const packageConfigurationPath = join( packageTasksConfigurationsDirectory, configurationLocation )
|
|
74
|
+
const defaultConfigurationPath = join( iteePackageConfigurationsDirectory, configurationLocation )
|
|
75
|
+
|
|
76
|
+
packageConfigurationPaths.push( packageConfigurationPath )
|
|
77
|
+
defaultConfigurationPaths.push( defaultConfigurationPath )
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Take care of the configuration search order (package first then default !)
|
|
81
|
+
const configurationPaths = [ ...packageConfigurationPaths, ...defaultConfigurationPaths ]
|
|
82
|
+
let configurationPath = undefined
|
|
83
|
+
|
|
84
|
+
// Looking for existing configuration file
|
|
85
|
+
for ( const packageConfigurationPath of configurationPaths ) {
|
|
86
|
+
|
|
87
|
+
if ( existsSync( packageConfigurationPath ) ) {
|
|
88
|
+
configurationPath = packageConfigurationPath
|
|
89
|
+
break
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Else throw an error
|
|
95
|
+
if ( !configurationPath ) {
|
|
96
|
+
throw new Error( `Unable to find configuration in package configuration paths ${ configurationPaths.join( ', ' ) }.` )
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return configurationPath
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function getTaskConfigurationFor( filename ) {
|
|
104
|
+
|
|
105
|
+
const configurationFilePath = getTaskConfigurationPathFor( filename )
|
|
106
|
+
|
|
107
|
+
log( `Loading configuration from ${ cyan( configurationFilePath ) }` )
|
|
108
|
+
|
|
109
|
+
let configuration = null
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
|
|
113
|
+
if ( extname( configurationFilePath ) === '.json' ) {
|
|
114
|
+
|
|
115
|
+
configuration = getJsonFrom( configurationFilePath )
|
|
116
|
+
|
|
117
|
+
} else {
|
|
118
|
+
|
|
119
|
+
const moduleData = await import( configurationFilePath )
|
|
120
|
+
configuration = moduleData.default
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
} catch ( e ) {
|
|
125
|
+
|
|
126
|
+
log( red( e ) )
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return configuration
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function createFile( filePath, fileContent ) {
|
|
135
|
+
|
|
136
|
+
log( 'Creating', green( filePath ) )
|
|
137
|
+
writeFileSync( filePath, fileContent )
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function getFilesFrom( globPattern, filter = ( any ) => true ) {
|
|
142
|
+
|
|
143
|
+
return glob.sync( globPattern )
|
|
144
|
+
.map( filePath => normalize( filePath ) )
|
|
145
|
+
.filter( filter )
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
///
|
|
150
|
+
|
|
151
|
+
function getPackageRootDirectory() {
|
|
152
|
+
|
|
153
|
+
let __dirname
|
|
154
|
+
|
|
155
|
+
if ( import.meta.dirname ) {
|
|
156
|
+
__dirname = import.meta.dirname
|
|
157
|
+
} else if ( import.meta.filename ) {
|
|
158
|
+
__dirname = dirname( import.meta.filename )
|
|
159
|
+
} else if ( import.meta.url ) {
|
|
160
|
+
const __filename = fileURLToPath( import.meta.url )
|
|
161
|
+
__dirname = dirname( __filename )
|
|
162
|
+
} else {
|
|
163
|
+
throw new Error( 'Unable to retrieve module dirname.' )
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return join( __dirname, '..' )
|
|
167
|
+
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const iteePackageRootDirectory = getPackageRootDirectory()
|
|
171
|
+
const iteePackageJsonPath = join( iteePackageRootDirectory, 'package.json' )
|
|
172
|
+
const iteePackageConfigurationsDirectory = join( iteePackageRootDirectory, 'configs' )
|
|
173
|
+
const iteePackageNodeModulesDirectory = join( iteePackageRootDirectory, 'node_modules' )
|
|
174
|
+
const iteePackageSourcesDirectory = join( iteePackageRootDirectory, 'sources' )
|
|
175
|
+
|
|
176
|
+
const packageRootDirectory = iteePackageRootDirectory.includes( 'node_modules' ) ? join( iteePackageRootDirectory, '../../' ) : iteePackageRootDirectory
|
|
177
|
+
const packageTasksDirectory = join( packageRootDirectory, '.tasks' )
|
|
178
|
+
const packageTasksConfigurationsDirectory = join( packageTasksDirectory, 'configs' )
|
|
179
|
+
const packageNodeModulesDirectory = join( packageRootDirectory, 'node_modules' )
|
|
180
|
+
const packageBuildsDirectory = join( packageRootDirectory, 'builds' )
|
|
181
|
+
const packageSourcesDirectory = join( packageRootDirectory, 'sources' )
|
|
182
|
+
const packageSourcesBackendDirectory = join( packageSourcesDirectory, 'backend' )
|
|
183
|
+
const packageSourcesCommonDirectory = join( packageSourcesDirectory, 'common' )
|
|
184
|
+
const packageSourcesFrontendDirectory = join( packageSourcesDirectory, 'frontend' )
|
|
185
|
+
const packageTestsDirectory = join( packageRootDirectory, 'tests' )
|
|
186
|
+
const packageTestsBenchmarksDirectory = join( packageTestsDirectory, 'benchmarks' )
|
|
187
|
+
const packageTestsBundlesDirectory = join( packageTestsDirectory, 'bundles' )
|
|
188
|
+
const packageTestsUnitsDirectory = join( packageTestsDirectory, 'units' )
|
|
189
|
+
const packageDocsDirectory = join( packageRootDirectory, 'docs' )
|
|
190
|
+
const packageTutorialsDirectory = join( packageRootDirectory, 'tutorials' )
|
|
191
|
+
const packageJsonPath = join( packageRootDirectory, 'package.json' )
|
|
192
|
+
|
|
193
|
+
///
|
|
194
|
+
|
|
195
|
+
const packageJson = getJsonFrom( packageJsonPath )
|
|
196
|
+
const packageName = packageJson.name
|
|
197
|
+
const packageVersion = packageJson.version
|
|
198
|
+
const packageDescription = packageJson.description
|
|
199
|
+
|
|
200
|
+
function getPrettyPackageName( separator = ' ' ) {
|
|
201
|
+
|
|
202
|
+
let prettyPackageName = ''
|
|
203
|
+
|
|
204
|
+
const nameSplits = packageName.split( '-' )
|
|
205
|
+
for ( const nameSplit of nameSplits ) {
|
|
206
|
+
prettyPackageName += nameSplit.charAt( 0 ).toUpperCase() + nameSplit.slice( 1 ) + separator
|
|
207
|
+
}
|
|
208
|
+
prettyPackageName = prettyPackageName.slice( 0, -1 )
|
|
209
|
+
|
|
210
|
+
return prettyPackageName
|
|
211
|
+
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function getPrettyPackageVersion() {
|
|
215
|
+
|
|
216
|
+
return 'v' + packageVersion
|
|
217
|
+
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function getPrettyNodeVersion() {
|
|
221
|
+
|
|
222
|
+
let nodeVersion = 'vX.x.ₓ'
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
nodeVersion = childProcess.execFileSync( 'node', [ '--version' ] )
|
|
226
|
+
.toString()
|
|
227
|
+
.replace( /(\r\n|\n|\r)/gm, '' )
|
|
228
|
+
} catch ( e ) {
|
|
229
|
+
log( red( e ) )
|
|
230
|
+
|
|
231
|
+
if ( e.message.includes( 'ENOENT' ) ) {
|
|
232
|
+
nodeVersion += yellow( ' Not seems to be accessible from the path environment.' )
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return ' node: ' + nodeVersion
|
|
237
|
+
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function getPrettyNpmVersion() {
|
|
241
|
+
|
|
242
|
+
let npmVersion = 'X.x.ₓ'
|
|
243
|
+
|
|
244
|
+
try {
|
|
245
|
+
npmVersion = childProcess.execFileSync( 'npm', [ '--version' ] )
|
|
246
|
+
.toString()
|
|
247
|
+
.replace( /(\r\n|\n|\r)/gm, '' )
|
|
248
|
+
} catch ( e ) {
|
|
249
|
+
log( red( e ) )
|
|
250
|
+
|
|
251
|
+
if ( e.message.includes( 'ENOENT' ) ) {
|
|
252
|
+
npmVersion += yellow( ' Not seems to be accessible from the path environment.' )
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return ' npm: v' + npmVersion
|
|
257
|
+
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
///
|
|
261
|
+
|
|
262
|
+
async function getTasksFrom( taskFiles = [] ) {
|
|
263
|
+
|
|
264
|
+
const tasks = []
|
|
265
|
+
for ( const taskFile of taskFiles ) {
|
|
266
|
+
const relativeTaskFile = relative( packageRootDirectory, taskFile )
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
|
|
270
|
+
const module = await import(taskFile)
|
|
271
|
+
|
|
272
|
+
const exportStrings = []
|
|
273
|
+
for ( const moduleKey in module ) {
|
|
274
|
+
const task = module[ moduleKey ]
|
|
275
|
+
tasks.push( task )
|
|
276
|
+
|
|
277
|
+
const name = task.name ?? null
|
|
278
|
+
const displayName = task.displayName ?? null
|
|
279
|
+
const fullName = ( moduleKey !== name ) ? `${ blue( moduleKey ) }( ${ magenta( name ) } )` : `${ blue( name ) }`
|
|
280
|
+
const exportAs = ( displayName ) ? ` as ${ cyan( displayName ) }` : ''
|
|
281
|
+
const exportString = fullName + exportAs
|
|
282
|
+
exportStrings.push( exportString )
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
//log( 'Process ', green( relativeTaskFile ), `with task${ ( exportStrings.length > 1 ) ? 's' : '' }`, exportStrings.join( ', ' ) )
|
|
286
|
+
|
|
287
|
+
} catch ( error ) {
|
|
288
|
+
|
|
289
|
+
log( 'Error ', red( relativeTaskFile ), error.message )
|
|
290
|
+
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return tasks
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async function serializeTasksFrom( taskFiles = [] ) {
|
|
300
|
+
|
|
301
|
+
const tasks = await getTasksFrom( taskFiles )
|
|
302
|
+
return series( ...tasks )
|
|
303
|
+
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async function parallelizeTasksFrom( taskFiles = [] ) {
|
|
307
|
+
|
|
308
|
+
const tasks = await getTasksFrom( taskFiles )
|
|
309
|
+
return parallel( ...tasks )
|
|
310
|
+
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
///
|
|
314
|
+
|
|
315
|
+
function logLoadingTask( filename ) {
|
|
316
|
+
|
|
317
|
+
const taskPath = relative( packageRootDirectory, filename )
|
|
318
|
+
const taskName = basename( filename, '.task.mjs' )
|
|
319
|
+
|
|
320
|
+
log( `Loading ${ green( taskPath ) } with task ${ blue( taskName ) }` )
|
|
321
|
+
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
///
|
|
325
|
+
|
|
326
|
+
function IndenterFactory( indentationChar = '\t', indentationLevel = 5 ) {
|
|
327
|
+
|
|
328
|
+
const indentationLevels = {}
|
|
329
|
+
let currentProperty = 'I_'
|
|
330
|
+
for ( let currentIndentationLevel = 1 ; currentIndentationLevel <= indentationLevel ; currentIndentationLevel++ ) {
|
|
331
|
+
indentationLevels[ currentProperty ] = indentationChar.repeat( currentIndentationLevel )
|
|
332
|
+
currentProperty += '_'
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return {
|
|
336
|
+
I: new Indenter( indentationChar ),
|
|
337
|
+
...indentationLevels
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
class Indenter {
|
|
343
|
+
|
|
344
|
+
constructor( indentationChar = '\t' ) {
|
|
345
|
+
|
|
346
|
+
this.indentationChar = indentationChar
|
|
347
|
+
this.currentIndentationLevel = 0
|
|
348
|
+
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
_( indentationLevel = null ) {
|
|
352
|
+
return this.indentationChar.repeat( indentationLevel ?? this.currentIndentationLevel )
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
deeper( level = 1 ) {
|
|
356
|
+
this.currentIndentationLevel += level
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
shallower( level = 1 ) {
|
|
360
|
+
this.currentIndentationLevel -= level
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
///
|
|
366
|
+
|
|
367
|
+
export {
|
|
368
|
+
createDirectoryIfNotExist,
|
|
369
|
+
getJsonFrom,
|
|
370
|
+
getTaskConfigurationPathFor,
|
|
371
|
+
getTaskConfigurationFor,
|
|
372
|
+
createFile,
|
|
373
|
+
getFilesFrom,
|
|
374
|
+
|
|
375
|
+
iteePackageRootDirectory,
|
|
376
|
+
iteePackageJsonPath,
|
|
377
|
+
iteePackageConfigurationsDirectory,
|
|
378
|
+
iteePackageNodeModulesDirectory,
|
|
379
|
+
iteePackageSourcesDirectory,
|
|
380
|
+
|
|
381
|
+
packageRootDirectory,
|
|
382
|
+
packageTasksDirectory,
|
|
383
|
+
packageTasksConfigurationsDirectory,
|
|
384
|
+
packageNodeModulesDirectory,
|
|
385
|
+
packageBuildsDirectory,
|
|
386
|
+
packageSourcesDirectory,
|
|
387
|
+
packageSourcesBackendDirectory,
|
|
388
|
+
packageSourcesCommonDirectory,
|
|
389
|
+
packageSourcesFrontendDirectory,
|
|
390
|
+
packageTestsDirectory,
|
|
391
|
+
packageTestsBenchmarksDirectory,
|
|
392
|
+
packageTestsBundlesDirectory,
|
|
393
|
+
packageTestsUnitsDirectory,
|
|
394
|
+
packageDocsDirectory,
|
|
395
|
+
packageTutorialsDirectory,
|
|
396
|
+
packageJsonPath,
|
|
397
|
+
packageJson,
|
|
398
|
+
packageName,
|
|
399
|
+
packageVersion,
|
|
400
|
+
packageDescription,
|
|
401
|
+
getPrettyPackageName,
|
|
402
|
+
getPrettyPackageVersion,
|
|
403
|
+
getPrettyNodeVersion,
|
|
404
|
+
getPrettyNpmVersion,
|
|
405
|
+
|
|
406
|
+
getTasksFrom,
|
|
407
|
+
serializeTasksFrom,
|
|
408
|
+
parallelizeTasksFrom,
|
|
409
|
+
logLoadingTask,
|
|
410
|
+
|
|
411
|
+
IndenterFactory as Indenter
|
|
412
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import colors from 'ansi-colors'
|
|
2
|
+
import log from 'fancy-log'
|
|
3
|
+
import { basename } from 'node:path'
|
|
4
|
+
import { rollup } from 'rollup'
|
|
5
|
+
import {
|
|
6
|
+
getTaskConfigurationFor,
|
|
7
|
+
logLoadingTask
|
|
8
|
+
} from '../_utils.mjs'
|
|
9
|
+
|
|
10
|
+
logLoadingTask( import.meta.filename )
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
red,
|
|
14
|
+
green,
|
|
15
|
+
yellow,
|
|
16
|
+
} = colors
|
|
17
|
+
|
|
18
|
+
const buildTask = async ( done ) => {
|
|
19
|
+
|
|
20
|
+
const configuration = await getTaskConfigurationFor( import.meta.filename )
|
|
21
|
+
|
|
22
|
+
for ( let config of configuration ) {
|
|
23
|
+
|
|
24
|
+
if ( config === undefined || config === null || config.length === 0 ) {
|
|
25
|
+
log( yellow( 'Empty configuration object... Skip it!' ) )
|
|
26
|
+
continue
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
log( 'Building', green( config.output.file ) )
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
|
|
33
|
+
const bundle = await rollup( config )
|
|
34
|
+
await bundle.write( config.output )
|
|
35
|
+
|
|
36
|
+
} catch ( error ) {
|
|
37
|
+
|
|
38
|
+
done( red( error.message ) )
|
|
39
|
+
return
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
done()
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
buildTask.displayName = basename( import.meta.filename, '.task.mjs' )
|
|
49
|
+
buildTask.description = 'Todo...'
|
|
50
|
+
buildTask.flags = null
|
|
51
|
+
|
|
52
|
+
export { buildTask }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import colors from 'ansi-colors'
|
|
2
|
+
import { deleteAsync } from 'del'
|
|
3
|
+
import log from 'fancy-log'
|
|
4
|
+
import { basename } from 'node:path'
|
|
5
|
+
import {
|
|
6
|
+
getTaskConfigurationFor,
|
|
7
|
+
logLoadingTask
|
|
8
|
+
} from '../_utils.mjs'
|
|
9
|
+
|
|
10
|
+
logLoadingTask( import.meta.filename )
|
|
11
|
+
|
|
12
|
+
const { red } = colors
|
|
13
|
+
const configuration = await getTaskConfigurationFor( import.meta.filename )
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @method npm run clean
|
|
17
|
+
* @global
|
|
18
|
+
* @description Will delete builds and temporary folders
|
|
19
|
+
*/
|
|
20
|
+
const cleanTask = () => deleteAsync( configuration, {
|
|
21
|
+
onProgress: progress => {
|
|
22
|
+
const path = progress.path || 'Nothing to clean...'
|
|
23
|
+
const percent = Math.round( progress.percent * 100 )
|
|
24
|
+
const spacer = percent === 100 ? '' : ' '
|
|
25
|
+
log( `Deleting [${ progress.deletedCount }/${ progress.totalCount }]<${ percent }%>${ spacer }:`, red( path ) )
|
|
26
|
+
}
|
|
27
|
+
} )
|
|
28
|
+
cleanTask.displayName = basename( import.meta.filename, '.task.mjs' )
|
|
29
|
+
cleanTask.description = 'Will delete builds and temporary folders'
|
|
30
|
+
cleanTask.flags = null
|
|
31
|
+
|
|
32
|
+
export { cleanTask }
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import colors from 'ansi-colors'
|
|
2
|
+
import log from 'fancy-log'
|
|
3
|
+
import child_process from 'node:child_process'
|
|
4
|
+
import { basename } from 'node:path'
|
|
5
|
+
import { promisify } from 'node:util'
|
|
6
|
+
import {
|
|
7
|
+
getTaskConfigurationPathFor,
|
|
8
|
+
logLoadingTask
|
|
9
|
+
} from '../_utils.mjs'
|
|
10
|
+
|
|
11
|
+
logLoadingTask( import.meta.filename )
|
|
12
|
+
|
|
13
|
+
const execFile = promisify( child_process.execFile )
|
|
14
|
+
const { red } = colors
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @method npm run doc
|
|
18
|
+
* @global
|
|
19
|
+
* @description Will generate this documentation
|
|
20
|
+
*/
|
|
21
|
+
const docTask = async ( done ) => {
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
|
|
25
|
+
const configurationPath = getTaskConfigurationPathFor( import.meta.filename )
|
|
26
|
+
|
|
27
|
+
const { stdout } = await execFile(
|
|
28
|
+
'./node_modules/.bin/jsdoc',
|
|
29
|
+
[
|
|
30
|
+
'--configure', configurationPath,
|
|
31
|
+
'--destination', './docs'
|
|
32
|
+
]
|
|
33
|
+
)
|
|
34
|
+
log( stdout )
|
|
35
|
+
done()
|
|
36
|
+
|
|
37
|
+
} catch ( error ) {
|
|
38
|
+
|
|
39
|
+
done( red( error.message ) )
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
docTask.displayName = basename( import.meta.filename, '.task.mjs' )
|
|
45
|
+
docTask.description = 'Will generate this documentation.'
|
|
46
|
+
docTask.flags = null
|
|
47
|
+
|
|
48
|
+
export { docTask }
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import colors from 'ansi-colors'
|
|
2
|
+
import log from 'fancy-log'
|
|
3
|
+
import { basename } from 'node:path'
|
|
4
|
+
import {
|
|
5
|
+
getPrettyNodeVersion,
|
|
6
|
+
getPrettyNpmVersion,
|
|
7
|
+
getPrettyPackageName,
|
|
8
|
+
getPrettyPackageVersion,
|
|
9
|
+
Indenter,
|
|
10
|
+
logLoadingTask
|
|
11
|
+
} from '../_utils.mjs'
|
|
12
|
+
|
|
13
|
+
logLoadingTask( import.meta.filename )
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
red,
|
|
17
|
+
green,
|
|
18
|
+
blue,
|
|
19
|
+
cyan,
|
|
20
|
+
yellow,
|
|
21
|
+
magenta,
|
|
22
|
+
unstyle
|
|
23
|
+
} = colors
|
|
24
|
+
|
|
25
|
+
function alignTextCenter( text, width ) {
|
|
26
|
+
|
|
27
|
+
const unstyledText = unstyle( text.repeat( 1 ) )
|
|
28
|
+
const marginLength = ( width - unstyledText.length ) / 2
|
|
29
|
+
|
|
30
|
+
let leftMargin, rightMargin
|
|
31
|
+
if ( Number.isInteger( marginLength ) ) {
|
|
32
|
+
leftMargin = marginLength
|
|
33
|
+
rightMargin = marginLength
|
|
34
|
+
} else {
|
|
35
|
+
const flooredMargin = Math.floor( marginLength )
|
|
36
|
+
leftMargin = flooredMargin
|
|
37
|
+
rightMargin = flooredMargin + 1
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return ' '.repeat( leftMargin ) + text + ' '.repeat( rightMargin )
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function alignTextLeft( text, width ) {
|
|
45
|
+
|
|
46
|
+
const unstyledText = unstyle( text.repeat( 1 ) )
|
|
47
|
+
let repeatTime = width - unstyledText.length
|
|
48
|
+
repeatTime = ( repeatTime > 0 ) ? repeatTime : 0
|
|
49
|
+
|
|
50
|
+
return text + ' '.repeat( repeatTime )
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function alignTextRight( text, width ) {
|
|
55
|
+
|
|
56
|
+
const unstyledText = unstyle( text.repeat( 1 ) )
|
|
57
|
+
let repeatTime = width - unstyledText.length
|
|
58
|
+
repeatTime = ( repeatTime > 0 ) ? repeatTime : 0
|
|
59
|
+
|
|
60
|
+
return ' '.repeat( repeatTime ) + text
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @method npm run help ( default )
|
|
66
|
+
* @global
|
|
67
|
+
* @description Will display the help in console
|
|
68
|
+
*/
|
|
69
|
+
const helpTask = ( done ) => {
|
|
70
|
+
|
|
71
|
+
const bannerWidth = 70
|
|
72
|
+
const prettyPackageName = getPrettyPackageName()
|
|
73
|
+
const prettyPackageVersion = getPrettyPackageVersion()
|
|
74
|
+
const prettyNodeVersion = getPrettyNodeVersion()
|
|
75
|
+
const prettyNpmVersion = getPrettyNpmVersion()
|
|
76
|
+
|
|
77
|
+
const tableCharset = {
|
|
78
|
+
topLeftCorner: '┏',
|
|
79
|
+
topRightCorner: '┓',
|
|
80
|
+
bottomRightCorner: '┛',
|
|
81
|
+
bottomLeftCorner: '┗',
|
|
82
|
+
horizontalBorder: '━',
|
|
83
|
+
horizontalSeparator: '─',
|
|
84
|
+
leftJoinSeparator: '┠',
|
|
85
|
+
rightJoinSeparator: '┨',
|
|
86
|
+
verticalBorder: '┃',
|
|
87
|
+
verticalSeparator: '',
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const mainBorder = tableCharset.horizontalBorder.repeat( bannerWidth )
|
|
91
|
+
const thinBorder = tableCharset.horizontalSeparator.repeat( bannerWidth )
|
|
92
|
+
const tableTop = `${ tableCharset.topLeftCorner }${ mainBorder }${ tableCharset.topRightCorner }`
|
|
93
|
+
const tableSeparator = `${ tableCharset.leftJoinSeparator }${ thinBorder }${ tableCharset.rightJoinSeparator }`
|
|
94
|
+
const tableBottom = `${ tableCharset.bottomLeftCorner }${ mainBorder }${ tableCharset.bottomRightCorner }`
|
|
95
|
+
const tableLine = ( innerText ) => `${ tableCharset.verticalBorder }${ innerText }${ tableCharset.verticalBorder }`
|
|
96
|
+
|
|
97
|
+
const {
|
|
98
|
+
I_,
|
|
99
|
+
I__,
|
|
100
|
+
I___,
|
|
101
|
+
I____,
|
|
102
|
+
} = new Indenter( '\t', 4 )
|
|
103
|
+
|
|
104
|
+
const npmRun = blue( 'npm run' )
|
|
105
|
+
|
|
106
|
+
log( '' )
|
|
107
|
+
log( tableTop )
|
|
108
|
+
log( tableLine( alignTextCenter( 'HELP', bannerWidth ) ) )
|
|
109
|
+
log( tableLine( alignTextCenter( prettyPackageName, bannerWidth ) ) )
|
|
110
|
+
log( tableLine( alignTextCenter( prettyPackageVersion, bannerWidth ) ) )
|
|
111
|
+
log( tableSeparator )
|
|
112
|
+
log( tableLine( alignTextLeft( prettyNodeVersion, bannerWidth ) ) )
|
|
113
|
+
log( tableLine( alignTextLeft( prettyNpmVersion, bannerWidth ) ) )
|
|
114
|
+
log( tableBottom )
|
|
115
|
+
log( I_, 'Available commands are:' )
|
|
116
|
+
log( I__, npmRun, cyan( 'help' ), '- Display this help.' )
|
|
117
|
+
log( I__, npmRun, cyan( 'patch' ), '- Will apply some patch/replacements in dependencies.', red( '(Apply only once after run "npm install")' ) )
|
|
118
|
+
log( I__, npmRun, cyan( 'clean' ), '- Will delete builds and temporary folders.' )
|
|
119
|
+
log( I__, npmRun, cyan( 'lint' ), '- Will run the eslint in pedantic mode with auto fix when possible.' )
|
|
120
|
+
log( I__, npmRun, cyan( 'doc' ), '- Will run jsdoc, and create documentation under `documentation` folder, using the docdash theme' )
|
|
121
|
+
log( I__, npmRun, cyan( 'test' ), '- Will run the test framworks (unit and bench), and create reports under `documentation/report` folder, using the mochawesome theme' )
|
|
122
|
+
log( I__, npmRun, cyan( 'unit' ), '- Will run the karma server for unit tests.' )
|
|
123
|
+
log( I__, npmRun, cyan( 'bench' ), '- Will run the karma server for benchmarks.' )
|
|
124
|
+
log( I__, npmRun, cyan( 'build' ), yellow( '--' ), green( '<options>' ), '- Will build the application for development and/or production environments.' )
|
|
125
|
+
log( I___, yellow( 'Note: The two dash are only required if you provide options !' ) )
|
|
126
|
+
log( I___, 'The available', green( '<options>' ), 'are:' )
|
|
127
|
+
log( I____, green( '-i' ), 'or', green( '--input' ), '- The main file path to build', cyan( '[Default: "sources/main.js"]' ), '.' )
|
|
128
|
+
log( I____, green( '-o' ), 'or', green( '--output' ), '- The folder where output the build', cyan( '[Default: "builds"]' ), '.' )
|
|
129
|
+
log(
|
|
130
|
+
I____,
|
|
131
|
+
green( '-f:' ),
|
|
132
|
+
magenta( '<format>' ),
|
|
133
|
+
'or',
|
|
134
|
+
green( '--format:' ),
|
|
135
|
+
magenta( '<format>' ),
|
|
136
|
+
' - to specify the output build type. Where format could be any of:', magenta( 'cjs, esm, iife, umd' ), '.'
|
|
137
|
+
)
|
|
138
|
+
log( I____, green( '-e:' ), magenta( '<env>' ), 'or', green( '--env:' ), magenta( '<env>' ), ' - to specify the build environment. Where env could be any of:', magenta(
|
|
139
|
+
'dev' ), magenta( 'prod' ), cyan( '[Default: "dev"]' ), '.' )
|
|
140
|
+
log( I____, green( '-s' ), 'or', green( '--sourcemap' ), ' - to build with related source map', cyan( '[Default: true]' ), '.' )
|
|
141
|
+
log( I____, green( '-t' ), 'or', green( '--treeshake' ), ' - allow to perform treeshaking when building', cyan( '[Default: true]' ), '.' )
|
|
142
|
+
log( I__, npmRun, cyan( 'release' ), '- Will run all the lint, test stuff, and if succeed will build the application.' )
|
|
143
|
+
log( '' )
|
|
144
|
+
log( I_, 'In case you have', blue( 'gulp' ), 'installed globally, you could use also:' )
|
|
145
|
+
log( I__, blue( 'gulp' ), cyan( 'command' ), '- It will perform the command like using "npm run" but with less characters to type... Because you\'re a developer, right ?' )
|
|
146
|
+
log( '' )
|
|
147
|
+
|
|
148
|
+
done()
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
helpTask.displayName = basename( import.meta.filename, '.task.mjs' )
|
|
152
|
+
helpTask.description = 'Display the package help'
|
|
153
|
+
helpTask.flags = null
|
|
154
|
+
|
|
155
|
+
export { helpTask }
|