Skip to content

Commit bbe5a04

Browse files
committed
🐛 (gulpfile-refresh) use external script that do not require gulp to be loaded for refreshing it
1 parent f370e1e commit bbe5a04

File tree

2 files changed

+50
-65
lines changed

2 files changed

+50
-65
lines changed

.tasks/_refresh-gulpfile.task.mjs

Lines changed: 0 additions & 65 deletions
This file was deleted.

.tasks/_refresh.mjs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import colors from 'ansi-colors'
2+
import log from 'fancy-log'
3+
import { writeFileSync } from 'fs'
4+
import { glob } from 'glob'
5+
import {
6+
join,
7+
normalize,
8+
relative
9+
} from 'path'
10+
import { packageRootDirectory } from './_utils.mjs'
11+
12+
const {
13+
blue,
14+
green,
15+
magenta,
16+
cyan
17+
} = colors
18+
19+
let gulpfileContent = '' +
20+
'/**\n' +
21+
' * This file is auto-generated by internal gulp command.\n' +
22+
' * If you want to customize the available gulp tasks, create your own in .tasks folder\n' +
23+
' * and run "gulp refresh"\n' +
24+
' */\n\n'
25+
26+
const taskFiles = glob.sync( join( packageRootDirectory, '.tasks/{.*.task.mjs,*.task.mjs,.**/*.task.mjs,.**/**/*.task.mjs}' ) )
27+
.map( filePath => normalize( filePath ) )
28+
29+
for ( const taskFile of taskFiles ) {
30+
const module = await import(taskFile)
31+
32+
const exportStrings = []
33+
for ( const moduleKey in module ) {
34+
const task = module[ moduleKey ]
35+
const name = task.name ?? null
36+
const displayName = task.displayName ?? null
37+
const fullName = ( moduleKey !== name ) ? `${ blue( moduleKey ) }( ${ magenta( name ) } )` : `${ blue( name ) }`
38+
const exportAs = ( displayName ) ? ` as ${ cyan( displayName ) }` : ''
39+
const exportString = fullName + exportAs
40+
exportStrings.push( exportString )
41+
}
42+
43+
const relativeTaskFile = relative( packageRootDirectory, taskFile )
44+
log( 'Found', green( relativeTaskFile ), 'with', exportStrings.join( ', ' ) )
45+
gulpfileContent += `export * from './${ relativeTaskFile }'\n`
46+
}
47+
48+
const gulpfilePath = join( packageRootDirectory, 'gulpfile.mjs' )
49+
log( 'Refreshing', green( gulpfilePath ) )
50+
writeFileSync( gulpfilePath, gulpfileContent )

0 commit comments

Comments
 (0)