@itee/tasks 1.3.1 → 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.
Files changed (66) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/docs/cleans_clean.task.mjs.html +10 -11
  3. package/docs/global.html +14 -170
  4. package/docs/helps_help.task.mjs.html +24 -22
  5. package/docs/index.html +4 -4
  6. package/docs/lints_lint.task.mjs.html +14 -12
  7. package/docs/patches_patch.task.mjs.html +13 -5
  8. package/docs/quicksearch.html +1 -1
  9. package/docs/releases_release.task.mjs.html +5 -5
  10. package/docs/tests_benchmarks_compute-benchmarks.task.mjs.html +35 -38
  11. package/docs/tests_benchmarks_run-benchmarks-for-backend.task.mjs.html +20 -18
  12. package/docs/tests_benchmarks_run-benchmarks-for-frontend.task.mjs.html +10 -14
  13. package/docs/tests_bundlings_check-bundling-from-esm-files-direct.task.mjs.html +22 -34
  14. package/docs/tests_bundlings_check-bundling.task.mjs.html +5 -5
  15. package/docs/tests_run-tests.task.mjs.html +5 -5
  16. package/docs/tests_units_compute-unit-tests.task.mjs.html +40 -42
  17. package/docs/tests_units_run-unit-tests-for-backend.task.mjs.html +21 -19
  18. package/docs/tests_units_run-unit-tests-for-frontend.task.mjs.html +9 -13
  19. package/package.json +4 -4
  20. package/{sources → scripts}/refresh.mjs +10 -12
  21. package/sources/builds/build.conf.mjs +3 -0
  22. package/sources/builds/build.task.mjs +12 -14
  23. package/{configs → sources}/cleans/clean.conf.mjs +1 -1
  24. package/sources/cleans/clean.task.mjs +6 -7
  25. package/{configs → sources}/docs/doc.conf.mjs +8 -7
  26. package/sources/docs/doc.task.mjs +7 -8
  27. package/sources/helps/help.task.mjs +19 -17
  28. package/{configs → sources}/lints/lint.conf.mjs +18 -18
  29. package/sources/lints/lint.task.mjs +10 -8
  30. package/sources/patches/patch.task.mjs +9 -1
  31. package/sources/releases/release.task.mjs +1 -1
  32. package/sources/{index.mjs → tasks.js} +7 -2
  33. package/sources/tests/benchmarks/compute-benchmarks.conf.mjs +5 -0
  34. package/sources/tests/benchmarks/compute-benchmarks.task.mjs +31 -34
  35. package/sources/tests/benchmarks/run-benchmarks-for-backend.task.mjs +16 -14
  36. package/{configs → sources}/tests/benchmarks/run-benchmarks-for-frontend.conf.mjs +6 -6
  37. package/sources/tests/benchmarks/run-benchmarks-for-frontend.task.mjs +6 -10
  38. package/{configs → sources}/tests/benchmarks/run-benchmarks.conf.mjs +2 -2
  39. package/sources/tests/benchmarks/run-benchmarks.task.mjs +3 -3
  40. package/{configs → sources}/tests/bundlings/check-bundling-from-esm-build-import.conf.mjs +12 -10
  41. package/sources/tests/bundlings/check-bundling-from-esm-build-import.task.mjs +17 -17
  42. package/{configs → sources}/tests/bundlings/check-bundling-from-esm-files-direct.conf.mjs +20 -14
  43. package/sources/tests/bundlings/check-bundling-from-esm-files-direct.task.mjs +17 -29
  44. package/{configs → sources}/tests/bundlings/check-bundling-from-esm-files-import.conf.mjs +15 -13
  45. package/sources/tests/bundlings/check-bundling-from-esm-files-import.task.mjs +17 -29
  46. package/sources/tests/bundlings/check-bundling.task.mjs +1 -1
  47. package/sources/tests/run-tests.task.mjs +1 -1
  48. package/sources/tests/units/compute-unit-tests.conf.mjs +5 -0
  49. package/sources/tests/units/compute-unit-tests.task.mjs +36 -38
  50. package/sources/tests/units/run-unit-tests-for-backend.task.mjs +17 -15
  51. package/{configs → sources}/tests/units/run-unit-tests-for-frontend.conf.mjs +1 -1
  52. package/sources/tests/units/run-unit-tests-for-frontend.task.mjs +5 -9
  53. package/{configs → sources}/tests/units/run-unit-tests.conf.mjs +2 -2
  54. package/sources/tests/units/run-unit-tests.task.mjs +3 -3
  55. package/sources/utils/builds.mjs +238 -0
  56. package/sources/utils/colors.mjs +19 -0
  57. package/sources/utils/files.mjs +70 -0
  58. package/sources/utils/loggings.mjs +33 -0
  59. package/sources/utils/packages.mjs +172 -0
  60. package/sources/utils/tasks.mjs +170 -0
  61. package/sources/utils/texts.mjs +98 -0
  62. package/configs/builds/build.conf.mjs +0 -3
  63. package/configs/tests/benchmarks/compute-benchmarks.conf.mjs +0 -5
  64. package/configs/tests/units/compute-unit-tests.conf.mjs +0 -5
  65. package/sources/_utils.mjs +0 -692
  66. /package/{configs → scripts}/refresh.conf.mjs +0 -0
@@ -0,0 +1,170 @@
1
+ import {
2
+ parallel,
3
+ series
4
+ } from 'gulp'
5
+ import { existsSync } from 'node:fs'
6
+ import {
7
+ extname,
8
+ join,
9
+ relative
10
+ } from 'node:path'
11
+ import {
12
+ blue,
13
+ cyan,
14
+ magenta,
15
+ red,
16
+ } from './colors.mjs'
17
+ import { getJsonFrom } from './files.mjs'
18
+ import { log } from './loggings.mjs'
19
+ import {
20
+ iteePackageSourcesDirectory,
21
+ packageRootDirectory,
22
+ packageTasksConfigurationsDirectory,
23
+ packageTasksDirectory
24
+ } from './packages.mjs'
25
+
26
+ async function getTasksFrom( taskFiles = [] ) {
27
+
28
+ const tasks = []
29
+ for ( const taskFile of taskFiles ) {
30
+ const relativeTaskFile = relative( packageRootDirectory, taskFile )
31
+
32
+ try {
33
+
34
+ const module = await import(taskFile)
35
+
36
+ const exportStrings = []
37
+ for ( const moduleKey in module ) {
38
+ const task = module[ moduleKey ]
39
+ tasks.push( task )
40
+
41
+ const name = task.name ?? null
42
+ const displayName = task.displayName ?? null
43
+ const fullName = ( moduleKey !== name ) ? `${ blue( moduleKey ) }( ${ magenta( name ) } )` : `${ blue( name ) }`
44
+ const exportAs = ( displayName ) ? ` as ${ cyan( displayName ) }` : ''
45
+ const exportString = fullName + exportAs
46
+ exportStrings.push( exportString )
47
+ }
48
+
49
+ //log( 'Process ', green( relativeTaskFile ), `with task${ ( exportStrings.length > 1 ) ? 's' : '' }`, exportStrings.join( ', ' ) )
50
+
51
+ } catch ( error ) {
52
+
53
+ log( 'Error ', red( relativeTaskFile ), error.message )
54
+
55
+ }
56
+
57
+ }
58
+
59
+ return tasks
60
+
61
+ }
62
+
63
+ async function serializeTasksFrom( taskFiles = [] ) {
64
+
65
+ const tasks = await getTasksFrom( taskFiles )
66
+ return series( ...tasks )
67
+
68
+ }
69
+
70
+ async function parallelizeTasksFrom( taskFiles = [] ) {
71
+
72
+ const tasks = await getTasksFrom( taskFiles )
73
+ return parallel( ...tasks )
74
+
75
+ }
76
+
77
+ /// Task configuration management
78
+
79
+ function getTaskConfigurationPathFor( filename ) {
80
+
81
+ // Get relative path of the task between internal or user defined
82
+ let relativeTaskPath = filename.includes( iteePackageSourcesDirectory )
83
+ ? relative( iteePackageSourcesDirectory, filename )
84
+ : relative( packageTasksDirectory, filename )
85
+
86
+ // Generate all possible config file path depending on file extension and default or user defined
87
+ const terminalExtension = extname( relativeTaskPath )
88
+ const searchValue = relativeTaskPath.includes( '.task.' ) ? `.task${ terminalExtension }` : terminalExtension
89
+ const replaceValues = [
90
+ '.conf.json',
91
+ '.conf.js',
92
+ '.conf.cjs',
93
+ '.conf.mjs',
94
+ ]
95
+
96
+ const packageConfigurationPaths = []
97
+ const defaultConfigurationPaths = []
98
+
99
+ for ( const replaceValue of replaceValues ) {
100
+ const configurationLocation = relativeTaskPath.replace( searchValue, replaceValue )
101
+ const packageConfigurationPath = join( packageTasksConfigurationsDirectory, configurationLocation )
102
+ const defaultConfigurationPath = join( iteePackageSourcesDirectory, configurationLocation )
103
+
104
+ packageConfigurationPaths.push( packageConfigurationPath )
105
+ defaultConfigurationPaths.push( defaultConfigurationPath )
106
+ }
107
+
108
+ // Take care of the configuration search order (package first then default !)
109
+ const configurationPaths = [ ...packageConfigurationPaths, ...defaultConfigurationPaths ]
110
+ let configurationPath = undefined
111
+
112
+ // Looking for existing configuration file
113
+ for ( const packageConfigurationPath of configurationPaths ) {
114
+
115
+ if ( existsSync( packageConfigurationPath ) ) {
116
+ configurationPath = packageConfigurationPath
117
+ break
118
+ }
119
+
120
+ }
121
+
122
+ // Else throw an error
123
+ if ( !configurationPath ) {
124
+ throw new Error( `Unable to find configuration in package configuration paths ${ configurationPaths.join( ', ' ) }.` )
125
+ }
126
+
127
+ return configurationPath
128
+
129
+ }
130
+
131
+ async function getTaskConfigurationFor( filename ) {
132
+
133
+ const configurationFilePath = getTaskConfigurationPathFor( filename )
134
+
135
+ log( `Loading configuration from ${ cyan( configurationFilePath ) }` )
136
+
137
+ let configuration = null
138
+
139
+ try {
140
+
141
+ if ( extname( configurationFilePath ) === '.json' ) {
142
+
143
+ configuration = getJsonFrom( configurationFilePath )
144
+
145
+ } else {
146
+
147
+ const moduleData = await import( configurationFilePath )
148
+ configuration = moduleData.default
149
+
150
+ }
151
+
152
+ } catch ( e ) {
153
+
154
+ log( red( e ) )
155
+
156
+ }
157
+
158
+ return configuration
159
+
160
+ }
161
+
162
+
163
+ export {
164
+ getTasksFrom,
165
+ serializeTasksFrom,
166
+ parallelizeTasksFrom,
167
+
168
+ getTaskConfigurationPathFor,
169
+ getTaskConfigurationFor,
170
+ }
@@ -0,0 +1,98 @@
1
+ import { unstyle } from './colors.mjs'
2
+
3
+ function alignTextCenter( text, width ) {
4
+
5
+ const unstyledText = unstyle( text.repeat( 1 ) )
6
+ const marginLength = ( width - unstyledText.length ) / 2
7
+
8
+ let leftMargin, rightMargin
9
+ if ( Number.isInteger( marginLength ) ) {
10
+ leftMargin = marginLength
11
+ rightMargin = marginLength
12
+ } else {
13
+ const flooredMargin = Math.floor( marginLength )
14
+ leftMargin = flooredMargin
15
+ rightMargin = flooredMargin + 1
16
+ }
17
+
18
+ return ' '.repeat( leftMargin ) + text + ' '.repeat( rightMargin )
19
+
20
+ }
21
+
22
+ function alignTextLeft( text, width ) {
23
+
24
+ const unstyledText = unstyle( text.repeat( 1 ) )
25
+ let repeatTime = width - unstyledText.length
26
+ repeatTime = ( repeatTime > 0 ) ? repeatTime : 0
27
+
28
+ return text + ' '.repeat( repeatTime )
29
+
30
+ }
31
+
32
+ function alignTextRight( text, width ) {
33
+
34
+ const unstyledText = unstyle( text.repeat( 1 ) )
35
+ let repeatTime = width - unstyledText.length
36
+ repeatTime = ( repeatTime > 0 ) ? repeatTime : 0
37
+
38
+ return ' '.repeat( repeatTime ) + text
39
+
40
+ }
41
+
42
+ function IndenterFactory( indentationChar = '\t', indentationLevel = 5 ) {
43
+
44
+ const indentationLevels = {}
45
+ let currentProperty = 'I_'
46
+ for ( let currentIndentationLevel = 1 ; currentIndentationLevel <= indentationLevel ; currentIndentationLevel++ ) {
47
+ indentationLevels[ currentProperty ] = indentationChar.repeat( currentIndentationLevel )
48
+ currentProperty += '_'
49
+ }
50
+
51
+ return {
52
+ I: new Indenter( indentationChar ),
53
+ ...indentationLevels
54
+ }
55
+
56
+ }
57
+
58
+ function toCamelCase( string ) {
59
+
60
+ return string
61
+ .trim()
62
+ .toLowerCase()
63
+ .replace( /[^a-zA-Z0-9]+(.)/g, ( _, char ) => char.toUpperCase() )
64
+ .replace( /^[A-Z]/, ( char ) => char.toLowerCase() )
65
+
66
+ }
67
+
68
+ class Indenter {
69
+
70
+ constructor( indentationChar = '\t' ) {
71
+
72
+ this.indentationChar = indentationChar
73
+ this.currentIndentationLevel = 0
74
+
75
+ }
76
+
77
+ _( indentationLevel = null ) {
78
+ return this.indentationChar.repeat( indentationLevel ?? this.currentIndentationLevel )
79
+ }
80
+
81
+ deeper( level = 1 ) {
82
+ this.currentIndentationLevel += level
83
+ }
84
+
85
+ shallower( level = 1 ) {
86
+ this.currentIndentationLevel -= level
87
+ }
88
+
89
+ }
90
+
91
+
92
+ export {
93
+ alignTextCenter,
94
+ alignTextLeft,
95
+ alignTextRight,
96
+ toCamelCase,
97
+ IndenterFactory as Indenter
98
+ }
@@ -1,3 +0,0 @@
1
- import { createRollupConfigs } from '../../sources/_utils.mjs'
2
-
3
- export default createRollupConfigs()
@@ -1,5 +0,0 @@
1
- import { packageName } from '../../../sources/_utils.mjs'
2
-
3
- export default [
4
- `${ packageName }.js`
5
- ]
@@ -1,5 +0,0 @@
1
- import { packageName } from '../../../sources/_utils.mjs'
2
-
3
- export default [
4
- `${ packageName }.js`
5
- ]