itee-tasks 1.0.3

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.
Files changed (48) hide show
  1. package/.czrc +6 -0
  2. package/.github/workflows/node.js.yml +56 -0
  3. package/.releaserc.mjs +94 -0
  4. package/CHANGELOG.md +25 -0
  5. package/README.md +1 -0
  6. package/configs/builds/build.conf.mjs +1 -0
  7. package/configs/cleans/clean.conf.mjs +1 -0
  8. package/configs/docs/doc.conf.json +1 -0
  9. package/configs/lints/lint.conf.mjs +91 -0
  10. package/configs/refresh.conf.mjs +1 -0
  11. package/configs/tests/benchmarks/compute-benchmarks.conf.mjs +25 -0
  12. package/configs/tests/benchmarks/run-benchmarks-for-frontend.conf.mjs +41 -0
  13. package/configs/tests/benchmarks/run-benchmarks.conf.mjs +7 -0
  14. package/configs/tests/bundlings/check-bundling-from-esm-build-import.conf.mjs +45 -0
  15. package/configs/tests/bundlings/check-bundling-from-esm-files-direct.conf.mjs +45 -0
  16. package/configs/tests/bundlings/check-bundling-from-esm-files-import.conf.mjs +42 -0
  17. package/configs/tests/bundlings/check-bundling.conf.mjs +25 -0
  18. package/configs/tests/units/compute-unit-tests.conf.mjs +25 -0
  19. package/configs/tests/units/run-unit-tests-for-frontend.conf.mjs +15 -0
  20. package/configs/tests/units/run-unit-tests.conf.mjs +7 -0
  21. package/gulpfile.mjs +28 -0
  22. package/package.json +91 -0
  23. package/sources/_utils.mjs +389 -0
  24. package/sources/builds/build.task.mjs +55 -0
  25. package/sources/cleans/clean.task.mjs +36 -0
  26. package/sources/docs/doc.task.mjs +49 -0
  27. package/sources/helps/help.task.mjs +154 -0
  28. package/sources/index.mjs +21 -0
  29. package/sources/lints/lint.task.mjs +47 -0
  30. package/sources/refresh.mjs +100 -0
  31. package/sources/releases/release.task.mjs +31 -0
  32. package/sources/tests/benchmarks/compute-benchmarks.task.mjs +224 -0
  33. package/sources/tests/benchmarks/run-benchmarks-for-backend.task.mjs +42 -0
  34. package/sources/tests/benchmarks/run-benchmarks-for-frontend.task.mjs +52 -0
  35. package/sources/tests/benchmarks/run-benchmarks.task.mjs +21 -0
  36. package/sources/tests/bundlings/check-bundling-from-esm-build-import.task.mjs +131 -0
  37. package/sources/tests/bundlings/check-bundling-from-esm-files-direct.task.mjs +88 -0
  38. package/sources/tests/bundlings/check-bundling-from-esm-files-import.task.mjs +106 -0
  39. package/sources/tests/bundlings/check-bundling.task.mjs +23 -0
  40. package/sources/tests/run-tests.task.mjs +21 -0
  41. package/sources/tests/units/compute-unit-tests.task.mjs +535 -0
  42. package/sources/tests/units/run-unit-tests-for-backend.task.mjs +47 -0
  43. package/sources/tests/units/run-unit-tests-for-frontend.task.mjs +52 -0
  44. package/sources/tests/units/run-unit-tests.task.mjs +21 -0
  45. package/tests/benchmarks/default/default.bench.js +1 -0
  46. package/tests/benchmarks/itee-tasks.benchmarks.js +8 -0
  47. package/tests/units/default/default.unit.mjs +1 -0
  48. package/tests/units/itee-tasks.units.mjs +1 -0
@@ -0,0 +1,21 @@
1
+ import { join } from 'path'
2
+ import {
3
+ getConfigurationFrom,
4
+ getConfigurationPathFor,
5
+ logLoadingTask,
6
+ serializeTasksFrom
7
+ } from '../../_utils.mjs'
8
+
9
+
10
+ const configurationLocation = join( 'tests', 'benchmarks', 'run-benchmarks.conf.mjs' )
11
+ const configurationPath = getConfigurationPathFor( configurationLocation )
12
+ const configuration = await getConfigurationFrom( configurationPath )
13
+
14
+ const runBenchmarksTestsTask = await serializeTasksFrom( configuration )
15
+ runBenchmarksTestsTask.displayName = 'run-benchmarks'
16
+ runBenchmarksTestsTask.description = 'Will run benchmarks in back and front environments.'
17
+ runBenchmarksTestsTask.flags = null
18
+
19
+ logLoadingTask( import.meta.filename, runBenchmarksTestsTask, configurationPath )
20
+
21
+ export { runBenchmarksTestsTask }
@@ -0,0 +1,131 @@
1
+ import colors from 'ansi-colors'
2
+ import log from 'fancy-log'
3
+ import {
4
+ existsSync,
5
+ mkdirSync,
6
+ readFileSync,
7
+ rmSync,
8
+ writeFileSync
9
+ } from 'fs'
10
+ import {
11
+ basename,
12
+ join,
13
+ relative
14
+ } from 'path'
15
+ import { rollup } from 'rollup'
16
+ import {
17
+ getConfigurationFrom,
18
+ getConfigurationPathFor,
19
+ logLoadingTask,
20
+ packageBuildsDirectory,
21
+ packageName,
22
+ packageTestsBundlesDirectory
23
+ } from '../../_utils.mjs'
24
+
25
+ const {
26
+ red,
27
+ green,
28
+ magenta,
29
+ } = colors
30
+
31
+ const configurationLocation = join( 'tests', 'bundlings', 'check-bundling-from-esm-build-import.conf.mjs' )
32
+ const configurationPath = getConfigurationPathFor( configurationLocation )
33
+
34
+ const checkBundlingFromEsmBuildImportTask = async ( done ) => {
35
+
36
+ const configuration = await getConfigurationFrom( configurationPath )
37
+
38
+ const buildFilePath = join( packageBuildsDirectory, `${ packageName }.esm.js` )
39
+ if ( !existsSync( buildFilePath ) ) {
40
+ done( red( buildFilePath + ' does not exist' ) )
41
+ }
42
+
43
+ const outputDir = join( packageTestsBundlesDirectory, 'from_build_import' )
44
+ const temporaryDir = join( packageTestsBundlesDirectory, 'from_build_import', '.tmp' )
45
+ const importDir = relative( temporaryDir, packageBuildsDirectory )
46
+ const importFilePath = join( importDir, `${ packageName }.esm.js` )
47
+
48
+ if ( existsSync( outputDir ) ) {
49
+ log( 'Clean up', magenta( outputDir ) )
50
+ rmSync( outputDir, { recursive: true } )
51
+ }
52
+
53
+ try {
54
+
55
+ // Get build exports list
56
+ const data = readFileSync( buildFilePath, 'utf8' )
57
+ const regex = /export\s{\s(.*)\s}/
58
+ const found = data.match( regex )
59
+ if ( found === null ) {
60
+ log( red( `Unable to find exports in ${ buildFilePath }` ) )
61
+ return
62
+ }
63
+
64
+ const exports = found[ 1 ].split( ',' )
65
+ .map( item => item.trim() )
66
+
67
+ // Create temporary imports files for each build export
68
+ // And then bundle it
69
+ let temporaryFilePaths = []
70
+ for ( let namedExport of exports ) {
71
+ if ( namedExport.includes( ' as ' ) ) {
72
+ namedExport = namedExport.split( ' as ' )[ 1 ]
73
+ }
74
+
75
+ const temporaryFileName = `${ namedExport }.import.js`
76
+ const temporaryFilePath = join( temporaryDir, temporaryFileName )
77
+ const temporaryFileData = `import { ${ namedExport } } from '${ importFilePath.replace( /\\/g, '/' ) }'`
78
+
79
+ mkdirSync( temporaryDir, { recursive: true } )
80
+ writeFileSync( temporaryFilePath, temporaryFileData )
81
+
82
+ temporaryFilePaths.push( temporaryFilePath )
83
+ }
84
+
85
+ // Bundle each temporary files and check side effects
86
+ let fileName, bundleFileName, bundleFilePath
87
+ for ( const temporaryFilePath of temporaryFilePaths ) {
88
+
89
+ fileName = basename( temporaryFilePath )
90
+ bundleFileName = fileName.replace( '.tmp.', '.bundle.' )
91
+ bundleFilePath = join( outputDir, bundleFileName )
92
+
93
+ try {
94
+
95
+ configuration.input = temporaryFilePath
96
+ configuration.output.file = bundleFilePath
97
+
98
+ const bundle = await rollup( configuration )
99
+ const { output } = await bundle.generate( configuration.output )
100
+
101
+ let code = output[ 0 ].code
102
+ if ( code.length > 1 ) {
103
+ log( red( `[${ bundleFileName }] contain side-effects !` ) )
104
+ await bundle.write( configuration.output )
105
+ } else {
106
+ log( green( `[${ bundleFileName }] is side-effect free.` ) )
107
+ }
108
+
109
+ } catch ( error ) {
110
+
111
+ log( red( error.message ) )
112
+
113
+ }
114
+ }
115
+
116
+ } catch ( error ) {
117
+ log( red( error.message ) )
118
+ } finally {
119
+
120
+ done()
121
+
122
+ }
123
+
124
+ }
125
+ checkBundlingFromEsmBuildImportTask.displayName = 'check-bundling-from-esm-build-import'
126
+ checkBundlingFromEsmBuildImportTask.description = 'Verify that the project esm build is correctly importable in third party esm files'
127
+ checkBundlingFromEsmBuildImportTask.flags = null
128
+
129
+ logLoadingTask( import.meta.filename, checkBundlingFromEsmBuildImportTask, configurationPath )
130
+
131
+ export { checkBundlingFromEsmBuildImportTask }
@@ -0,0 +1,88 @@
1
+ import colors from 'ansi-colors'
2
+ import log from 'fancy-log'
3
+ import {
4
+ existsSync,
5
+ rmSync
6
+ } from 'fs'
7
+ import {
8
+ basename,
9
+ dirname,
10
+ extname,
11
+ join
12
+ } from 'path'
13
+ import { rollup } from 'rollup'
14
+ import {
15
+ getConfigurationFrom,
16
+ getConfigurationPathFor,
17
+ logLoadingTask,
18
+ packageSourcesDirectory,
19
+ packageTestsBundlesDirectory
20
+ } from '../../_utils.mjs'
21
+
22
+ const {
23
+ red,
24
+ green,
25
+ magenta,
26
+ } = colors
27
+
28
+ const sourcesFilesLocation = join( 'tests', 'bundlings', 'check-bundling.conf.mjs' )
29
+ const sourcesFilesPath = getConfigurationPathFor( sourcesFilesLocation )
30
+
31
+ const configurationLocation = join( 'tests', 'bundlings', 'check-bundling-from-esm-files-direct.conf.mjs' )
32
+ const configurationPath = getConfigurationPathFor( configurationLocation )
33
+
34
+ /**
35
+ * @description In view to detect bundling side effects this task will
36
+ * create intermediary file for each individual export from this package
37
+ * and then create rollup config for each of them and bundle
38
+ * Todo: Check for different target env like next task below this one
39
+ */
40
+ const checkBundlingFromEsmFilesDirectTask = async ( done ) => {
41
+
42
+ const outputDir = join( packageTestsBundlesDirectory, 'from_files_direct' )
43
+ if ( existsSync( outputDir ) ) {
44
+ log( 'Clean up', magenta( outputDir ) )
45
+ rmSync( outputDir, { recursive: true } )
46
+ }
47
+
48
+ const sourcesFiles = await getConfigurationFrom( sourcesFilesPath )
49
+ const configuration = await getConfigurationFrom( configurationPath )
50
+
51
+ for ( let sourceFile of sourcesFiles ) {
52
+
53
+ const specificFilePath = sourceFile.replace( packageSourcesDirectory, '' )
54
+ const specificDir = dirname( specificFilePath )
55
+ const fileName = basename( sourceFile, extname( sourceFile ) )
56
+
57
+ const bundleFileName = `${ fileName }.bundle.js`
58
+ const bundleFilePath = join( outputDir, specificDir, bundleFileName )
59
+
60
+ configuration.input = sourceFile
61
+ configuration.output.file = bundleFilePath
62
+
63
+ try {
64
+
65
+ log( 'Bundling', green( configuration.output.file ) )
66
+
67
+ const bundle = await rollup( configuration )
68
+ await bundle.generate( configuration.output )
69
+ await bundle.write( configuration.output )
70
+
71
+ } catch ( error ) {
72
+
73
+ log( red( error.message ) )
74
+
75
+ }
76
+
77
+ }
78
+
79
+ done()
80
+
81
+ }
82
+ checkBundlingFromEsmFilesDirectTask.displayName = 'check-bundling-from-esm-files-direct'
83
+ checkBundlingFromEsmFilesDirectTask.description = 'In view to detect bundling side effects this task will create intermediary file for each individual export from this package and then create rollup config for each of them and bundle'
84
+ checkBundlingFromEsmFilesDirectTask.flags = null
85
+
86
+ logLoadingTask( import.meta.filename, checkBundlingFromEsmFilesDirectTask, configurationPath )
87
+
88
+ export { checkBundlingFromEsmFilesDirectTask }
@@ -0,0 +1,106 @@
1
+ import colors from 'ansi-colors'
2
+ import log from 'fancy-log'
3
+ import {
4
+ existsSync,
5
+ mkdirSync,
6
+ rmSync,
7
+ writeFileSync
8
+ } from 'fs'
9
+ import {
10
+ dirname,
11
+ join,
12
+ parse,
13
+ relative
14
+ } from 'path'
15
+ import { rollup } from 'rollup'
16
+ import {
17
+ getConfigurationFrom,
18
+ getConfigurationPathFor,
19
+ logLoadingTask,
20
+ packageSourcesDirectory as sourcesDir,
21
+ packageTestsBundlesDirectory as bundleDir
22
+ } from '../../_utils.mjs'
23
+
24
+ const {
25
+ red,
26
+ green,
27
+ magenta,
28
+ } = colors
29
+
30
+ const sourcesFilesLocation = join( 'tests', 'bundlings', 'check-bundling.conf.mjs' )
31
+ const sourcesFilesPath = getConfigurationPathFor( sourcesFilesLocation )
32
+
33
+ const configurationLocation = join( 'tests', 'bundlings', 'check-bundling-from-esm-files-import.conf.mjs' )
34
+ const configurationPath = getConfigurationPathFor( configurationLocation )
35
+
36
+ const checkBundlingFromEsmFilesImportTask = async ( done ) => {
37
+
38
+ const outputDir = join( bundleDir, 'from_files_import' )
39
+ const temporariesDir = join( outputDir, '.tmp' )
40
+
41
+ if ( existsSync( outputDir ) ) {
42
+ log( 'Clean up', magenta( outputDir ) )
43
+ rmSync( outputDir, { recursive: true } )
44
+ }
45
+
46
+ const sourcesFiles = await getConfigurationFrom( sourcesFilesPath )
47
+ const configuration = await getConfigurationFrom( configurationPath )
48
+
49
+ for ( let sourceFile of sourcesFiles ) {
50
+
51
+ const {
52
+ dir: sourceDir,
53
+ base: sourceBase,
54
+ name: sourceName
55
+ } = parse( sourceFile )
56
+ const specificFilePath = sourceFile.replace( sourcesDir, '' )
57
+ const specificDir = dirname( specificFilePath )
58
+
59
+ // Create temp import file per file in package
60
+ const temporaryFileName = `${ sourceName }.import.js`
61
+ const temporaryDir = join( temporariesDir, specificDir )
62
+ const temporaryFile = join( temporaryDir, temporaryFileName )
63
+ const importDir = relative( temporaryDir, sourceDir )
64
+ const importFile = join( importDir, sourceBase )
65
+ const temporaryFileData = `import '${ importFile.replace( /\\/g, '/' ) }'`
66
+
67
+ // Bundle tmp file and check content for side effects
68
+ const bundleFileName = `${ sourceName }.bundle.js`
69
+ const bundleFilePath = join( outputDir, specificDir, bundleFileName )
70
+
71
+ configuration.input = temporaryFile
72
+ configuration.output.file = bundleFilePath
73
+
74
+ // create tmp file
75
+ try {
76
+
77
+ mkdirSync( temporaryDir, { recursive: true } )
78
+ writeFileSync( temporaryFile, temporaryFileData )
79
+
80
+ const bundle = await rollup( configuration )
81
+ const { output } = await bundle.generate( configuration.output )
82
+
83
+ let code = output[ 0 ].code
84
+ if ( code.length > 1 ) {
85
+ log( red( `[${ specificFilePath }] contain side-effects !` ) )
86
+ await bundle.write( configuration.output )
87
+ } else {
88
+ log( green( `[${ specificFilePath }] is side-effect free.` ) )
89
+ }
90
+
91
+ } catch ( error ) {
92
+ log( red( error.message ) )
93
+ }
94
+
95
+ }
96
+
97
+ done()
98
+
99
+ }
100
+ checkBundlingFromEsmFilesImportTask.displayName = 'check-bundling-from-esm-files-import'
101
+ checkBundlingFromEsmFilesImportTask.description = 'In view to detect bundling side effects this task will create intermediary file for each individual export from this package and then create rollup config for each of them and bundle'
102
+ checkBundlingFromEsmFilesImportTask.flags = null
103
+
104
+ logLoadingTask( import.meta.filename, checkBundlingFromEsmFilesImportTask, configurationPath )
105
+
106
+ export { checkBundlingFromEsmFilesImportTask }
@@ -0,0 +1,23 @@
1
+ import { series } from 'gulp'
2
+ import { logLoadingTask } from '../../_utils.mjs'
3
+ import { checkBundlingFromEsmBuildImportTask } from './check-bundling-from-esm-build-import.task.mjs'
4
+ import { checkBundlingFromEsmFilesDirectTask } from './check-bundling-from-esm-files-direct.task.mjs'
5
+ import { checkBundlingFromEsmFilesImportTask } from './check-bundling-from-esm-files-import.task.mjs'
6
+
7
+ /**
8
+ * @description In view to detect bundling side effects this task will
9
+ * create intermediary file for each individual export from this package
10
+ * and then create rollup config for each of them and bundle
11
+ * Todo: Check for different targets env like next task below this one
12
+ */
13
+ const checkBundlingTask = series(
14
+ checkBundlingFromEsmFilesImportTask,
15
+ checkBundlingFromEsmBuildImportTask,
16
+ checkBundlingFromEsmFilesDirectTask
17
+ )
18
+ checkBundlingTask.displayName = 'check-bundling'
19
+ checkBundlingTask.description = 'In view to detect bundling side effects this task will create intermediary file for each individual export and then try to bundle them.'
20
+
21
+ logLoadingTask( import.meta.filename, checkBundlingTask )
22
+
23
+ export { checkBundlingTask }
@@ -0,0 +1,21 @@
1
+ import { series } from 'gulp'
2
+ import { logLoadingTask } from '../_utils.mjs'
3
+ import { runBenchmarksTestsTask } from './benchmarks/run-benchmarks.task.mjs'
4
+ import { runUnitTestsTask } from './units/run-unit-tests.task.mjs'
5
+
6
+ /**
7
+ * @method npm run test
8
+ * @global
9
+ * @description Will run unit tests and benchmarks for backend (node) and frontend (web-test-runner) environments
10
+ */
11
+ const runTestsTask = series(
12
+ runBenchmarksTestsTask,
13
+ runUnitTestsTask,
14
+ )
15
+ runTestsTask.displayName = 'run-tests'
16
+ runTestsTask.description = 'Will run unit tests and benchmarks for backend (node) and frontend (web-test-runner) environments.'
17
+ runTestsTask.flags = null
18
+
19
+ logLoadingTask( import.meta.filename, runTestsTask )
20
+
21
+ export { runTestsTask }