@itee/tasks 1.3.0 → 1.3.2
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/CHANGELOG.md +14 -0
- package/docs/-_utils.mjs.html +68 -18
- package/docs/cleans_clean.task.mjs.html +10 -11
- package/docs/global.html +17 -173
- package/docs/helps_help.task.mjs.html +23 -59
- package/docs/index.html +4 -4
- package/docs/lints_lint.task.mjs.html +15 -12
- package/docs/patches_patch.task.mjs.html +14 -12
- package/docs/quicksearch.html +1 -1
- package/docs/releases_release.task.mjs.html +5 -5
- package/docs/tests_benchmarks_compute-benchmarks.task.mjs.html +35 -38
- package/docs/tests_benchmarks_run-benchmarks-for-backend.task.mjs.html +20 -18
- package/docs/tests_benchmarks_run-benchmarks-for-frontend.task.mjs.html +21 -23
- package/docs/tests_bundlings_check-bundling-from-esm-files-direct.task.mjs.html +22 -34
- package/docs/tests_bundlings_check-bundling.task.mjs.html +5 -5
- package/docs/tests_run-tests.task.mjs.html +5 -5
- package/docs/tests_units_compute-unit-tests.task.mjs.html +40 -42
- package/docs/tests_units_run-unit-tests-for-backend.task.mjs.html +21 -19
- package/docs/tests_units_run-unit-tests-for-frontend.task.mjs.html +21 -23
- package/package.json +4 -4
- package/{sources → scripts}/refresh.mjs +10 -12
- package/sources/builds/build.conf.mjs +3 -0
- package/sources/builds/build.task.mjs +11 -13
- package/{configs → sources}/cleans/clean.conf.mjs +1 -1
- package/sources/cleans/clean.task.mjs +6 -7
- package/{configs → sources}/docs/doc.conf.mjs +8 -7
- package/sources/docs/doc.task.mjs +7 -8
- package/sources/helps/help.task.mjs +18 -54
- package/{configs → sources}/lints/lint.conf.mjs +50 -18
- package/sources/lints/lint.task.mjs +11 -8
- package/sources/patches/patch.task.mjs +9 -7
- package/sources/releases/release.task.mjs +1 -1
- package/sources/tasks.js +26 -0
- package/sources/tests/benchmarks/compute-benchmarks.conf.mjs +5 -0
- package/sources/tests/benchmarks/compute-benchmarks.task.mjs +31 -34
- package/sources/tests/benchmarks/run-benchmarks-for-backend.task.mjs +16 -14
- package/{configs → sources}/tests/benchmarks/run-benchmarks-for-frontend.conf.mjs +6 -6
- package/sources/tests/benchmarks/run-benchmarks-for-frontend.task.mjs +17 -19
- package/{configs → sources}/tests/benchmarks/run-benchmarks.conf.mjs +2 -2
- package/sources/tests/benchmarks/run-benchmarks.task.mjs +3 -3
- package/{configs → sources}/tests/bundlings/check-bundling-from-esm-build-import.conf.mjs +12 -10
- package/sources/tests/bundlings/check-bundling-from-esm-build-import.task.mjs +17 -17
- package/{configs → sources}/tests/bundlings/check-bundling-from-esm-files-direct.conf.mjs +20 -14
- package/sources/tests/bundlings/check-bundling-from-esm-files-direct.task.mjs +17 -29
- package/{configs → sources}/tests/bundlings/check-bundling-from-esm-files-import.conf.mjs +15 -13
- package/sources/tests/bundlings/check-bundling-from-esm-files-import.task.mjs +17 -29
- package/sources/tests/bundlings/check-bundling.task.mjs +1 -1
- package/sources/tests/run-tests.task.mjs +1 -1
- package/sources/tests/units/compute-unit-tests.conf.mjs +5 -0
- package/sources/tests/units/compute-unit-tests.task.mjs +36 -38
- package/sources/tests/units/run-unit-tests-for-backend.task.mjs +17 -15
- package/{configs → sources}/tests/units/run-unit-tests-for-frontend.conf.mjs +1 -1
- package/sources/tests/units/run-unit-tests-for-frontend.task.mjs +17 -19
- package/{configs → sources}/tests/units/run-unit-tests.conf.mjs +2 -2
- package/sources/tests/units/run-unit-tests.task.mjs +3 -3
- package/sources/utils/builds.mjs +238 -0
- package/sources/utils/colors.mjs +19 -0
- package/sources/utils/files.mjs +70 -0
- package/sources/utils/loggings.mjs +33 -0
- package/sources/utils/packages.mjs +172 -0
- package/sources/utils/tasks.mjs +170 -0
- package/sources/utils/texts.mjs +98 -0
- package/configs/builds/build.conf.mjs +0 -3
- package/configs/tests/benchmarks/compute-benchmarks.conf.mjs +0 -5
- package/configs/tests/units/compute-unit-tests.conf.mjs +0 -5
- package/sources/_utils.mjs +0 -642
- package/sources/index.mjs +0 -21
- /package/{configs → scripts}/refresh.conf.mjs +0 -0
|
@@ -1,36 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import childProcess
|
|
3
|
-
import log from 'fancy-log'
|
|
4
|
-
import { glob } from 'glob'
|
|
5
|
-
import { isNotEmptyArray } from 'itee-validators'
|
|
1
|
+
import { isNotEmptyArray } from 'itee-validators'
|
|
2
|
+
import childProcess from 'node:child_process'
|
|
6
3
|
import {
|
|
7
4
|
basename,
|
|
8
5
|
dirname,
|
|
9
6
|
extname,
|
|
10
7
|
join,
|
|
11
|
-
normalize,
|
|
12
8
|
relative
|
|
13
|
-
}
|
|
9
|
+
} from 'node:path'
|
|
10
|
+
import {
|
|
11
|
+
red,
|
|
12
|
+
yellow
|
|
13
|
+
} from '../../utils/colors.mjs'
|
|
14
14
|
import {
|
|
15
15
|
createDirectoryIfNotExist,
|
|
16
16
|
createFile,
|
|
17
|
+
getJavascriptSourceFiles
|
|
18
|
+
} from '../../utils/files.mjs'
|
|
19
|
+
import {
|
|
20
|
+
log,
|
|
21
|
+
logLoadingTask
|
|
22
|
+
} from '../../utils/loggings.mjs'
|
|
23
|
+
import {
|
|
17
24
|
getPrettyPackageName,
|
|
18
|
-
|
|
19
|
-
Indenter,
|
|
20
|
-
logLoadingTask,
|
|
21
|
-
packageName,
|
|
25
|
+
getUnscopedPackageName,
|
|
22
26
|
packageNodeModulesDirectory,
|
|
23
27
|
packageSourcesDirectory,
|
|
24
28
|
packageTestsUnitsDirectory
|
|
25
|
-
}
|
|
29
|
+
} from '../../utils/packages.mjs'
|
|
30
|
+
import { getTaskConfigurationFor } from '../../utils/tasks.mjs'
|
|
31
|
+
import {
|
|
32
|
+
Indenter,
|
|
33
|
+
toCamelCase
|
|
34
|
+
} from '../../utils/texts.mjs'
|
|
26
35
|
|
|
27
36
|
logLoadingTask( import.meta.filename )
|
|
28
37
|
|
|
29
|
-
const {
|
|
30
|
-
red,
|
|
31
|
-
yellow,
|
|
32
|
-
} = colors
|
|
33
|
-
|
|
34
38
|
/**
|
|
35
39
|
* @description Will generate unit test files from source code using type inference from comments
|
|
36
40
|
*/
|
|
@@ -38,20 +42,8 @@ const computeUnitTestsTask = async ( done ) => {
|
|
|
38
42
|
|
|
39
43
|
createDirectoryIfNotExist( packageTestsUnitsDirectory )
|
|
40
44
|
|
|
41
|
-
// Get task configuration
|
|
42
45
|
const filePathsToIgnore = await getTaskConfigurationFor( import.meta.filename )
|
|
43
|
-
|
|
44
|
-
// Get source files to process
|
|
45
|
-
const pattern = join( packageSourcesDirectory, '**' )
|
|
46
|
-
const sourceFiles = glob.sync( pattern )
|
|
47
|
-
.map( filePath => normalize( filePath ) )
|
|
48
|
-
.filter( filePath => {
|
|
49
|
-
const fileName = basename( filePath )
|
|
50
|
-
const isJsFile = fileName.endsWith( '.js' )
|
|
51
|
-
const isNotPrivateFile = !fileName.startsWith( '_' )
|
|
52
|
-
const isNotIgnoredFile = !filePathsToIgnore.includes( fileName )
|
|
53
|
-
return isJsFile && isNotPrivateFile && isNotIgnoredFile
|
|
54
|
-
} )
|
|
46
|
+
const sourceFiles = getJavascriptSourceFiles( filePathsToIgnore )
|
|
55
47
|
|
|
56
48
|
const unitsImportMap = []
|
|
57
49
|
for ( let sourceFile of sourceFiles ) {
|
|
@@ -59,20 +51,26 @@ const computeUnitTestsTask = async ( done ) => {
|
|
|
59
51
|
const specificFilePath = sourceFile.replace( packageSourcesDirectory, '' )
|
|
60
52
|
const specificDir = dirname( specificFilePath )
|
|
61
53
|
|
|
62
|
-
const fileName
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
54
|
+
const fileName = basename( sourceFile, extname( sourceFile ) )
|
|
55
|
+
const camelCaseFileName = toCamelCase( fileName )
|
|
56
|
+
const unitFileName = `${ camelCaseFileName }.unit.mjs`
|
|
57
|
+
const unitDirPath = join( packageTestsUnitsDirectory, specificDir )
|
|
58
|
+
const unitFilePath = join( unitDirPath, unitFileName )
|
|
66
59
|
|
|
67
|
-
const nsName = `${
|
|
68
|
-
const unitName = `${
|
|
60
|
+
const nsName = `${ camelCaseFileName }Namespace`
|
|
61
|
+
const unitName = `${ camelCaseFileName }Units`
|
|
69
62
|
const importDirPath = relative( unitDirPath, packageSourcesDirectory )
|
|
70
63
|
const importFilePath = join( importDirPath, specificFilePath ).replace( /\\/g, '/' )
|
|
71
64
|
|
|
72
65
|
try {
|
|
73
66
|
|
|
74
67
|
const jsdocPath = join( packageNodeModulesDirectory, '/jsdoc/jsdoc.js' )
|
|
75
|
-
const jsdocOutput = childProcess.execFileSync( 'node', [ jsdocPath, '
|
|
68
|
+
const jsdocOutput = childProcess.execFileSync( 'node', [ jsdocPath, '--explain', sourceFile ] ).toString()
|
|
69
|
+
|
|
70
|
+
if ( jsdocOutput.includes( 'There are no input files to process' ) ) {
|
|
71
|
+
log( 'Error ', red( `${ sourceFile }, no input files to process` ) )
|
|
72
|
+
continue
|
|
73
|
+
}
|
|
76
74
|
|
|
77
75
|
const classNames = []
|
|
78
76
|
const usedLongnames = []
|
|
@@ -534,7 +532,7 @@ const computeUnitTestsTask = async ( done ) => {
|
|
|
534
532
|
|
|
535
533
|
}
|
|
536
534
|
|
|
537
|
-
const unitsFilePath = join( packageTestsUnitsDirectory, `${
|
|
535
|
+
const unitsFilePath = join( packageTestsUnitsDirectory, `${ getUnscopedPackageName() }.units.mjs` )
|
|
538
536
|
createFile( unitsFilePath, unitsTemplate )
|
|
539
537
|
|
|
540
538
|
done()
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import log from 'fancy-log'
|
|
4
|
-
import { existsSync } from 'fs'
|
|
5
|
-
import { basename } from 'node:path'
|
|
6
|
-
import { join } from 'path'
|
|
1
|
+
import { spawn } from 'node:child_process'
|
|
2
|
+
import { existsSync } from 'node:fs'
|
|
7
3
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
basename,
|
|
5
|
+
join
|
|
6
|
+
} from 'node:path'
|
|
7
|
+
import {
|
|
8
|
+
red,
|
|
9
|
+
yellow
|
|
10
|
+
} from '../../utils/colors.mjs'
|
|
11
|
+
import {
|
|
12
|
+
log,
|
|
13
|
+
logLoadingTask
|
|
14
|
+
} from '../../utils/loggings.mjs'
|
|
15
|
+
import {
|
|
16
|
+
getUnscopedPackageName,
|
|
10
17
|
packageNodeModulesDirectory,
|
|
11
18
|
packageTestsUnitsDirectory
|
|
12
|
-
} from '../../
|
|
19
|
+
} from '../../utils/packages.mjs'
|
|
13
20
|
|
|
14
21
|
logLoadingTask( import.meta.filename )
|
|
15
22
|
|
|
16
|
-
const {
|
|
17
|
-
red,
|
|
18
|
-
yellow,
|
|
19
|
-
} = colors
|
|
20
|
-
|
|
21
23
|
/**
|
|
22
24
|
* @description Will run unit tests with node
|
|
23
25
|
*/
|
|
24
26
|
const runUnitTestsForBackendTask = ( done ) => {
|
|
25
27
|
|
|
26
|
-
const testsPath = join( packageTestsUnitsDirectory, `/${
|
|
28
|
+
const testsPath = join( packageTestsUnitsDirectory, `/${ getUnscopedPackageName() }.units.mjs` )
|
|
27
29
|
if ( !existsSync( testsPath ) ) {
|
|
28
30
|
log( yellow( `${ testsPath } does not exist, skip backend unit tests...` ) )
|
|
29
31
|
done()
|
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
import { startTestRunner }
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
logLoadingTask
|
|
7
|
-
} from '../../_utils.mjs'
|
|
1
|
+
import { startTestRunner } from '@web/test-runner'
|
|
2
|
+
import { basename } from 'node:path'
|
|
3
|
+
import { red } from '../../utils/colors.mjs'
|
|
4
|
+
import { logLoadingTask } from '../../utils/loggings.mjs'
|
|
5
|
+
import { getTaskConfigurationFor } from '../../utils/tasks.mjs'
|
|
8
6
|
|
|
9
7
|
logLoadingTask( import.meta.filename )
|
|
10
8
|
|
|
11
|
-
const { red } = colors
|
|
12
|
-
|
|
13
9
|
/**
|
|
14
10
|
* @description Will run unit tests with web-test-runner
|
|
15
11
|
*/
|
|
16
|
-
const runUnitTestsForFrontendTask = () => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
const runUnitTestsForFrontendTask = async () => {
|
|
13
|
+
|
|
14
|
+
const configuration = await getTaskConfigurationFor( import.meta.filename )
|
|
15
|
+
const testRunner = await startTestRunner( {
|
|
16
|
+
config: configuration,
|
|
17
|
+
readCliArgs: false,
|
|
18
|
+
readFileConfig: false,
|
|
19
|
+
autoExitProcess: false,
|
|
20
|
+
} )
|
|
21
|
+
|
|
22
|
+
return new Promise( ( resolve, reject ) => {
|
|
26
23
|
|
|
27
24
|
if ( !testRunner ) {
|
|
28
25
|
reject( red( 'Internal test runner error.' ) )
|
|
@@ -40,6 +37,7 @@ const runUnitTestsForFrontendTask = () => {
|
|
|
40
37
|
} )
|
|
41
38
|
|
|
42
39
|
} )
|
|
40
|
+
|
|
43
41
|
}
|
|
44
42
|
runUnitTestsForFrontendTask.displayName = basename( import.meta.filename, '.task.mjs' )
|
|
45
43
|
runUnitTestsForFrontendTask.description = 'Will run unit tests with web-test-runner'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { join } from 'path'
|
|
2
|
-
import { iteePackageSourcesDirectory } from '
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
import { iteePackageSourcesDirectory } from '../../utils/packages.mjs'
|
|
3
3
|
|
|
4
4
|
export default [
|
|
5
5
|
join( iteePackageSourcesDirectory, 'tests/units/run-unit-tests-for-backend.task.mjs' ),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { basename }
|
|
1
|
+
import { basename } from 'node:path'
|
|
2
|
+
import { logLoadingTask, } from '../../utils/loggings.mjs'
|
|
2
3
|
import {
|
|
3
4
|
getTaskConfigurationFor,
|
|
4
|
-
logLoadingTask,
|
|
5
5
|
serializeTasksFrom
|
|
6
|
-
}
|
|
6
|
+
} from '../../utils/tasks.mjs'
|
|
7
7
|
|
|
8
8
|
logLoadingTask( import.meta.filename )
|
|
9
9
|
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import commonjs from '@rollup/plugin-commonjs'
|
|
2
|
+
import nodeResolve from '@rollup/plugin-node-resolve'
|
|
3
|
+
import terser from '@rollup/plugin-terser'
|
|
4
|
+
import figlet from 'figlet'
|
|
5
|
+
import {
|
|
6
|
+
basename,
|
|
7
|
+
join
|
|
8
|
+
} from 'node:path'
|
|
9
|
+
import replace from 'rollup-plugin-re'
|
|
10
|
+
import { red } from './colors.mjs'
|
|
11
|
+
import { log } from './loggings.mjs'
|
|
12
|
+
import {
|
|
13
|
+
getPrettyPackageName,
|
|
14
|
+
getPrettyPackageVersion,
|
|
15
|
+
getUnscopedPackageName,
|
|
16
|
+
packageAuthor,
|
|
17
|
+
packageBuildsDirectory,
|
|
18
|
+
packageDescription,
|
|
19
|
+
packageLicense,
|
|
20
|
+
packageSourcesDirectory
|
|
21
|
+
} from './packages.mjs'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function getPrettyFormatForBanner( format ) {
|
|
25
|
+
|
|
26
|
+
let prettyFormat = ''
|
|
27
|
+
|
|
28
|
+
switch ( format ) {
|
|
29
|
+
|
|
30
|
+
case 'cjs':
|
|
31
|
+
prettyFormat = 'CommonJs'
|
|
32
|
+
break
|
|
33
|
+
|
|
34
|
+
case 'esm':
|
|
35
|
+
prettyFormat = 'EsModule'
|
|
36
|
+
break
|
|
37
|
+
|
|
38
|
+
case 'iife':
|
|
39
|
+
prettyFormat = 'Standalone'
|
|
40
|
+
break
|
|
41
|
+
|
|
42
|
+
case 'umd':
|
|
43
|
+
prettyFormat = 'Universal'
|
|
44
|
+
break
|
|
45
|
+
|
|
46
|
+
default:
|
|
47
|
+
throw new RangeError( `Invalid switch parameter: ${ format }` )
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return prettyFormat
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function convertBannerIntoComment( banner ) {
|
|
56
|
+
|
|
57
|
+
let bannerCommented = '/**\n'
|
|
58
|
+
bannerCommented += ' * '
|
|
59
|
+
bannerCommented += banner.replaceAll( '\n', '\n * ' )
|
|
60
|
+
bannerCommented += '\n'
|
|
61
|
+
bannerCommented += ` * @desc ${ packageDescription }\n`
|
|
62
|
+
bannerCommented += ` * @author [${ packageAuthor.name }]{@link ${ packageAuthor.url }}\n`
|
|
63
|
+
bannerCommented += ` * @license [${ packageLicense }]{@link https://opensource.org/licenses}\n`
|
|
64
|
+
bannerCommented += ' * \n'
|
|
65
|
+
bannerCommented += ' */'
|
|
66
|
+
|
|
67
|
+
return bannerCommented
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function computeBannerFor( format ) {
|
|
72
|
+
|
|
73
|
+
const packageName = getPrettyPackageName( '.' )
|
|
74
|
+
const packageVersion = getPrettyPackageVersion()
|
|
75
|
+
const prettyFormat = getPrettyFormatForBanner( format )
|
|
76
|
+
|
|
77
|
+
const figText = figlet.textSync(
|
|
78
|
+
`${ packageName } ${ packageVersion } - ${ prettyFormat }`,
|
|
79
|
+
{
|
|
80
|
+
font: 'Tmplr',
|
|
81
|
+
horizontalLayout: 'default',
|
|
82
|
+
verticalLayout: 'default',
|
|
83
|
+
whitespaceBreak: true,
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
return convertBannerIntoComment( figText )
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function computeIntroFor( requestPackages = [] ) {
|
|
92
|
+
|
|
93
|
+
let intro = ''
|
|
94
|
+
|
|
95
|
+
for ( const requestPackage of requestPackages ) {
|
|
96
|
+
intro += `if( ${ requestPackage } === undefined ) { throw new Error('${ getPrettyPackageName() } need ${ requestPackage } to be defined first. Please check your scripts loading order.') }` + '\n'
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return intro
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function getOutputFileExtensionBasedOnFileFormat( format ) {
|
|
104
|
+
|
|
105
|
+
let extension
|
|
106
|
+
|
|
107
|
+
if ( format === 'cjs' ) {
|
|
108
|
+
extension = 'cjs'
|
|
109
|
+
} else if ( format === 'esm' ) {
|
|
110
|
+
extension = 'mjs'
|
|
111
|
+
} else {
|
|
112
|
+
extension = 'js'
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return extension
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Will create an appropriate configuration object for rollup, related to the given arguments.
|
|
121
|
+
*
|
|
122
|
+
* @generator
|
|
123
|
+
* @param options
|
|
124
|
+
* @return {Array.<json>} An array of rollup configuration
|
|
125
|
+
*/
|
|
126
|
+
function createRollupConfigs( options = {} ) {
|
|
127
|
+
|
|
128
|
+
const _options = {
|
|
129
|
+
input: join( packageSourcesDirectory, `${ getUnscopedPackageName() }.js` ),
|
|
130
|
+
output: packageBuildsDirectory,
|
|
131
|
+
formats: [ 'esm', 'cjs', 'iife' ],
|
|
132
|
+
envs: [ 'dev', 'prod' ],
|
|
133
|
+
treeshake: true,
|
|
134
|
+
...options
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const {
|
|
138
|
+
input,
|
|
139
|
+
output,
|
|
140
|
+
formats,
|
|
141
|
+
envs,
|
|
142
|
+
treeshake
|
|
143
|
+
} = _options
|
|
144
|
+
const name = getPrettyPackageName( '.' )
|
|
145
|
+
const fileName = basename( input, '.js' )
|
|
146
|
+
|
|
147
|
+
const configs = []
|
|
148
|
+
|
|
149
|
+
for ( let formatIndex = 0, numberOfFormats = formats.length ; formatIndex < numberOfFormats ; ++formatIndex ) {
|
|
150
|
+
|
|
151
|
+
for ( let envIndex = 0, numberOfEnvs = envs.length ; envIndex < numberOfEnvs ; envIndex++ ) {
|
|
152
|
+
|
|
153
|
+
const env = envs[ envIndex ]
|
|
154
|
+
const isProd = ( env.includes( 'prod' ) )
|
|
155
|
+
const format = formats[ formatIndex ]
|
|
156
|
+
const extension = getOutputFileExtensionBasedOnFileFormat( format )
|
|
157
|
+
const outputPath = ( isProd )
|
|
158
|
+
? join( output, `${ fileName }.min.${ extension }` )
|
|
159
|
+
: join( output, `${ fileName }.${ extension }` )
|
|
160
|
+
|
|
161
|
+
configs.push( {
|
|
162
|
+
input: input,
|
|
163
|
+
external: ( format === 'cjs' ) ? [
|
|
164
|
+
'fs'
|
|
165
|
+
] : [],
|
|
166
|
+
plugins: [
|
|
167
|
+
replace( {
|
|
168
|
+
defines: {
|
|
169
|
+
IS_REMOVE_ON_BUILD: false,
|
|
170
|
+
IS_BACKEND_SPECIFIC: ( format === 'cjs' )
|
|
171
|
+
}
|
|
172
|
+
} ),
|
|
173
|
+
commonjs( {
|
|
174
|
+
include: 'node_modules/**'
|
|
175
|
+
} ),
|
|
176
|
+
nodeResolve( {
|
|
177
|
+
preferBuiltins: true
|
|
178
|
+
} ),
|
|
179
|
+
isProd && terser()
|
|
180
|
+
],
|
|
181
|
+
onwarn: ( {
|
|
182
|
+
loc,
|
|
183
|
+
frame,
|
|
184
|
+
message
|
|
185
|
+
} ) => {
|
|
186
|
+
|
|
187
|
+
// Ignore some errors
|
|
188
|
+
if ( message.includes( 'Circular dependency' ) ) { return }
|
|
189
|
+
if ( message.includes( 'plugin uglify is deprecated' ) ) { return }
|
|
190
|
+
|
|
191
|
+
let errorMessage = ( loc )
|
|
192
|
+
? `/!\\ ${ loc.file } (${ loc.line }:${ loc.column }) ${ frame } ${ message }\n`
|
|
193
|
+
: `/!\\ ${ message }\n`
|
|
194
|
+
|
|
195
|
+
log( red( errorMessage ) )
|
|
196
|
+
|
|
197
|
+
},
|
|
198
|
+
treeshake: treeshake,
|
|
199
|
+
output: {
|
|
200
|
+
// core options
|
|
201
|
+
file: outputPath,
|
|
202
|
+
format: format,
|
|
203
|
+
name: name,
|
|
204
|
+
globals: {},
|
|
205
|
+
|
|
206
|
+
// advanced options
|
|
207
|
+
paths: {},
|
|
208
|
+
banner: ( isProd ) ? '' : computeBannerFor( format ),
|
|
209
|
+
footer: '',
|
|
210
|
+
intro: ( !isProd && format === 'iife' ) ? computeIntroFor() : '',
|
|
211
|
+
outro: '',
|
|
212
|
+
sourcemap: !isProd,
|
|
213
|
+
interop: 'auto',
|
|
214
|
+
|
|
215
|
+
// danger zone
|
|
216
|
+
exports: 'auto',
|
|
217
|
+
amd: {},
|
|
218
|
+
indent: '\t',
|
|
219
|
+
strict: true
|
|
220
|
+
}
|
|
221
|
+
} )
|
|
222
|
+
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return configs
|
|
228
|
+
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
export {
|
|
233
|
+
getPrettyFormatForBanner,
|
|
234
|
+
convertBannerIntoComment,
|
|
235
|
+
computeBannerFor,
|
|
236
|
+
computeIntroFor,
|
|
237
|
+
createRollupConfigs,
|
|
238
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import colors from 'ansi-colors'
|
|
2
|
+
|
|
3
|
+
const red = ( value ) => colors.red( value )
|
|
4
|
+
const green = ( value ) => colors.green( value )
|
|
5
|
+
const blue = ( value ) => colors.blue( value )
|
|
6
|
+
const cyan = ( value ) => colors.cyan( value )
|
|
7
|
+
const yellow = ( value ) => colors.yellow( value )
|
|
8
|
+
const magenta = ( value ) => colors.magenta( value )
|
|
9
|
+
const unstyle = ( value ) => colors.unstyle( value )
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
red,
|
|
13
|
+
green,
|
|
14
|
+
blue,
|
|
15
|
+
cyan,
|
|
16
|
+
yellow,
|
|
17
|
+
magenta,
|
|
18
|
+
unstyle
|
|
19
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { glob } from 'glob'
|
|
2
|
+
import {
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
writeFileSync
|
|
7
|
+
} from 'node:fs'
|
|
8
|
+
import {
|
|
9
|
+
basename,
|
|
10
|
+
extname,
|
|
11
|
+
join,
|
|
12
|
+
normalize
|
|
13
|
+
} from 'node:path'
|
|
14
|
+
import { green } from './colors.mjs'
|
|
15
|
+
import { log } from './loggings.mjs'
|
|
16
|
+
import { packageSourcesDirectory } from './packages.mjs'
|
|
17
|
+
|
|
18
|
+
function createDirectoryIfNotExist( directoryPath ) {
|
|
19
|
+
|
|
20
|
+
if ( existsSync( directoryPath ) ) { return }
|
|
21
|
+
|
|
22
|
+
log( 'Creating', green( directoryPath ) )
|
|
23
|
+
mkdirSync( directoryPath, { recursive: true } )
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getJsonFrom( path ) {
|
|
28
|
+
|
|
29
|
+
const buffer = readFileSync( path )
|
|
30
|
+
const fileContent = buffer.toString()
|
|
31
|
+
return JSON.parse( fileContent )
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function createFile( filePath, fileContent ) {
|
|
36
|
+
|
|
37
|
+
log( 'Creating', green( filePath ) )
|
|
38
|
+
writeFileSync( filePath, fileContent )
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getFilesFrom( globPattern, filter = ( /*any*/ ) => true ) {
|
|
43
|
+
|
|
44
|
+
return glob.sync( globPattern )
|
|
45
|
+
.map( filePath => normalize( filePath ) )
|
|
46
|
+
.filter( filter )
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getJavascriptSourceFiles( filePathsToIgnore = [] ) {
|
|
51
|
+
|
|
52
|
+
return glob.sync( join( packageSourcesDirectory, '**' ) )
|
|
53
|
+
.map( filePath => normalize( filePath ) )
|
|
54
|
+
.filter( filePath => {
|
|
55
|
+
const fileName = basename( filePath )
|
|
56
|
+
const isJsFile = [ '.js', '.mjs', '.cjs' ].includes( extname( fileName ) )
|
|
57
|
+
const isNotPrivateFile = !fileName.startsWith( '_' )
|
|
58
|
+
const isNotIgnoredFile = !filePathsToIgnore.includes( fileName )
|
|
59
|
+
return isJsFile && isNotPrivateFile && isNotIgnoredFile
|
|
60
|
+
} )
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export {
|
|
65
|
+
createDirectoryIfNotExist,
|
|
66
|
+
getJsonFrom,
|
|
67
|
+
createFile,
|
|
68
|
+
getFilesFrom,
|
|
69
|
+
getJavascriptSourceFiles
|
|
70
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import log from 'fancy-log'
|
|
2
|
+
import {
|
|
3
|
+
basename,
|
|
4
|
+
relative
|
|
5
|
+
} from 'node:path'
|
|
6
|
+
import {
|
|
7
|
+
blue,
|
|
8
|
+
green
|
|
9
|
+
} from './colors.mjs'
|
|
10
|
+
import { packageRootDirectory } from './packages.mjs'
|
|
11
|
+
|
|
12
|
+
/* global process */
|
|
13
|
+
const isDebugging = ( process && process.env && process.env.RUNNER_DEBUG && process.env.RUNNER_DEBUG === '1' )
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
function logLoadingTask( filename ) {
|
|
17
|
+
|
|
18
|
+
if ( !isDebugging ) {
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const taskPath = relative( packageRootDirectory, filename )
|
|
23
|
+
const taskName = basename( filename, '.task.mjs' )
|
|
24
|
+
|
|
25
|
+
log( `Loading ${ green( taskPath ) } with task ${ blue( taskName ) }` )
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
log,
|
|
32
|
+
logLoadingTask
|
|
33
|
+
}
|