|
1 | | -import colors from 'ansi-colors' |
2 | | -import log from 'fancy-log' |
3 | | -import { writeFileSync } from 'fs' |
4 | | -import { glob } from 'glob' |
| 1 | +import colors from 'ansi-colors' |
| 2 | +import log from 'fancy-log' |
| 3 | +import { writeFileSync } from 'fs' |
5 | 4 | import { |
| 5 | + basename, |
6 | 6 | join, |
7 | | - normalize, |
8 | 7 | relative |
9 | | -} from 'path' |
10 | | -import { packageRootDirectory } from './_utils.mjs' |
| 8 | +} from 'path' |
| 9 | +import { |
| 10 | + getFilesFrom, |
| 11 | + packageRootDirectory |
| 12 | +} from './_utils.mjs' |
| 13 | +import { tasksToIgnore } from './configs/refresh.conf.mjs' |
11 | 14 |
|
12 | 15 | const { |
13 | | - blue, |
14 | 16 | green, |
15 | | - magenta, |
16 | | - cyan |
| 17 | + yellow, |
17 | 18 | } = colors |
18 | 19 |
|
| 20 | +// Get and filter tasks to expose |
| 21 | +const taskFiles = getFilesFrom( |
| 22 | + join( packageRootDirectory, '.tasks/{.*.task.mjs,*.task.mjs,.**/*.task.mjs,.**/**/*.task.mjs}' ), |
| 23 | + filePath => { |
| 24 | + const relativeFilepath = relative( packageRootDirectory, filePath ) |
| 25 | + const filename = basename( filePath ) |
| 26 | + const included = !tasksToIgnore.includes( filename ) |
| 27 | + |
| 28 | + included |
| 29 | + ? log( 'Include', green( relativeFilepath ) ) |
| 30 | + : log( 'Exclude', yellow( relativeFilepath ) ) |
| 31 | + |
| 32 | + return included |
| 33 | + } |
| 34 | +) |
| 35 | + |
| 36 | +// Prepare gulpfile content with header |
19 | 37 | let gulpfileContent = '' + |
20 | 38 | '/**\n' + |
21 | 39 | ' * This file is auto-generated by internal gulp command.\n' + |
22 | 40 | ' * If you want to customize the available gulp tasks, create your own in .tasks folder\n' + |
23 | 41 | ' * and run "gulp refresh"\n' + |
24 | 42 | ' */\n\n' |
25 | 43 |
|
26 | | -const taskFiles = glob.sync( join( packageRootDirectory, '.tasks/{.*.task.mjs,*.task.mjs,.**/*.task.mjs,.**/**/*.task.mjs}' ) ) |
27 | | - .map( filePath => normalize( filePath ) ) |
28 | | - |
| 44 | +// Generate tasks exports and append to gulpfile content |
29 | 45 | 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 | 46 | const relativeTaskFile = relative( packageRootDirectory, taskFile ) |
44 | | - log( 'Found', green( relativeTaskFile ), 'with', exportStrings.join( ', ' ) ) |
45 | 47 | gulpfileContent += `export * from './${ relativeTaskFile }'\n` |
46 | 48 | } |
47 | 49 |
|
| 50 | +// Create gulpfile file |
48 | 51 | const gulpfilePath = join( packageRootDirectory, 'gulpfile.mjs' ) |
49 | | -log( 'Refreshing', green( gulpfilePath ) ) |
| 52 | +log( 'Refresh', green( gulpfilePath ) ) |
50 | 53 | writeFileSync( gulpfilePath, gulpfileContent ) |
0 commit comments