@itee/tasks 1.3.2 → 1.4.0

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.
@@ -21,10 +21,10 @@ import {
21
21
  } from '../../utils/loggings.mjs'
22
22
  import {
23
23
  getUnscopedPackageName,
24
+ iteePackageSourcesDirectory,
24
25
  packageNodeModulesDirectory,
25
26
  packageSourcesDirectory,
26
- packageTestsBenchmarksDirectory,
27
- packageTestsDirectory
27
+ packageTestsBenchmarksDirectory
28
28
  } from '../../utils/packages.mjs'
29
29
  import { getTaskConfigurationFor } from '../../utils/tasks.mjs'
30
30
  import { toCamelCase } from '../../utils/texts.mjs'
@@ -82,18 +82,17 @@ const computeBenchmarksTask = async ( done ) => {
82
82
  return false
83
83
  }
84
84
 
85
- // We don't care that data bloc have comment they are unused to generate benchmarks
86
- // const undocumented = data.undocumented
87
- // if ( undocumented ) {
88
- // return false
89
- // }
90
-
91
85
  const scope = data.scope
92
86
  if ( ![ 'global', 'static' ].includes( scope ) ) {
93
87
  return false
94
88
  }
95
89
 
96
- if ( longName.includes( ' ' ) || longName.includes( '~' ) || usedLongnames.includes( longName ) ) {
90
+ if ( longName.startsWith( '_' ) || longName.includes( ' ' ) || longName.includes( '~' ) || usedLongnames.includes( longName ) ) {
91
+ return false
92
+ }
93
+
94
+ const memberOf = data.memberof || ''
95
+ if ( memberOf.includes( '.' ) ) {
97
96
  return false
98
97
  }
99
98
 
@@ -153,9 +152,9 @@ const computeBenchmarksTask = async ( done ) => {
153
152
  }
154
153
 
155
154
  // compute relative level to get import wrappers
156
- const wrapperDirPath = relative( benchDirPath, packageTestsDirectory )
157
- const importBenchmarkFilePath = join( wrapperDirPath, 'import.benchmarks.js' )
158
- const importTestingFilePath = join( wrapperDirPath, 'import.testing.js' )
155
+ const wrapperDirPath = relative( benchDirPath, iteePackageSourcesDirectory )
156
+ const importBenchmarkFilePath = join( wrapperDirPath, 'utils', 'benchmarks.js' )
157
+ const importTestingFilePath = join( wrapperDirPath, 'utils', 'testing.js' )
159
158
 
160
159
  const template = '' +
161
160
  `import * as ${ nsName } from '${ importFilePath }'` + '\n' +
@@ -23,10 +23,11 @@ import {
23
23
  import {
24
24
  getPrettyPackageName,
25
25
  getUnscopedPackageName,
26
+ iteePackageSourcesDirectory,
26
27
  packageNodeModulesDirectory,
27
28
  packageSourcesDirectory,
28
29
  packageTestsUnitsDirectory
29
- } from '../../utils/packages.mjs'
30
+ } from '../../utils/packages.mjs'
30
31
  import { getTaskConfigurationFor } from '../../utils/tasks.mjs'
31
32
  import {
32
33
  Indenter,
@@ -473,11 +474,17 @@ const computeUnitTestsTask = async ( done ) => {
473
474
 
474
475
  }
475
476
 
477
+ const wrapperDirPath = relative( unitDirPath, iteePackageSourcesDirectory )
478
+ const importTestingFilePath = join( wrapperDirPath, 'utils', 'testing.js' )
479
+
476
480
  const template = '' +
477
481
  `import { expect } from 'chai'` + '\n' +
478
- `import { Testing } from 'itee-utils/sources/testings/benchmarks.js'` + '\n' +
482
+ `import { getTestingPackage } from '${ importTestingFilePath }'` + '\n' +
483
+ // `import { Testing } from 'itee-utils/sources/testings/benchmarks.js'` + '\n' +
479
484
  `import * as ${ nsName } from '${ importFilePath }'` + '\n' +
480
485
  '\n' +
486
+ `const Testing = await getTestingPackage()` + '\n' +
487
+ '\n' +
481
488
  `describe( '${ unitName }', function () {` + '\n' +
482
489
  '\n' +
483
490
  `${ I_ }let _dataMap` + '\n' +
@@ -0,0 +1,18 @@
1
+ /* global Benchmark */
2
+
3
+ async function getBenchmarkPackage() {
4
+
5
+ let _Benchmark
6
+
7
+ if (typeof Benchmark === 'undefined' || Benchmark === undefined) {
8
+ const benchmarkPackage = await import('benchmark')
9
+ _Benchmark = benchmarkPackage.default
10
+ } else {
11
+ _Benchmark = Benchmark
12
+ }
13
+
14
+ return _Benchmark
15
+
16
+ }
17
+
18
+ export { getBenchmarkPackage }
@@ -73,16 +73,14 @@ function computeBannerFor( format ) {
73
73
  const packageName = getPrettyPackageName( '.' )
74
74
  const packageVersion = getPrettyPackageVersion()
75
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
- )
76
+ const figletText = `${ packageName } ${ packageVersion } - ${ prettyFormat }`
77
+ const figletOptions = {
78
+ font: 'Tmplr',
79
+ horizontalLayout: 'default',
80
+ verticalLayout: 'default',
81
+ whitespaceBreak: true,
82
+ }
83
+ const figText = figlet.textSync( figletText, figletOptions )
86
84
 
87
85
  return convertBannerIntoComment( figText )
88
86
 
@@ -146,19 +144,15 @@ function createRollupConfigs( options = {} ) {
146
144
 
147
145
  const configs = []
148
146
 
149
- for ( let formatIndex = 0, numberOfFormats = formats.length ; formatIndex < numberOfFormats ; ++formatIndex ) {
147
+ for ( const format of formats ) {
148
+ for ( const env of envs ) {
150
149
 
151
- for ( let envIndex = 0, numberOfEnvs = envs.length ; envIndex < numberOfEnvs ; envIndex++ ) {
152
-
153
- const env = envs[ envIndex ]
154
150
  const isProd = ( env.includes( 'prod' ) )
155
- const format = formats[ formatIndex ]
156
151
  const extension = getOutputFileExtensionBasedOnFileFormat( format )
157
152
  const outputPath = ( isProd )
158
153
  ? join( output, `${ fileName }.min.${ extension }` )
159
154
  : join( output, `${ fileName }.${ extension }` )
160
-
161
- configs.push( {
155
+ const config = {
162
156
  input: input,
163
157
  external: ( format === 'cjs' ) ? [
164
158
  'fs'
@@ -218,10 +212,10 @@ function createRollupConfigs( options = {} ) {
218
212
  indent: '\t',
219
213
  strict: true
220
214
  }
221
- } )
215
+ }
222
216
 
217
+ configs.push(config)
223
218
  }
224
-
225
219
  }
226
220
 
227
221
  return configs
@@ -9,14 +9,13 @@ import {
9
9
  relative
10
10
  } from 'node:path'
11
11
  import {
12
- blue,
13
12
  cyan,
14
- magenta,
15
13
  red,
16
14
  } from './colors.mjs'
17
15
  import { getJsonFrom } from './files.mjs'
18
16
  import { log } from './loggings.mjs'
19
17
  import {
18
+ iteePackageRootDirectory,
20
19
  iteePackageSourcesDirectory,
21
20
  packageRootDirectory,
22
21
  packageTasksConfigurationsDirectory,
@@ -33,21 +32,11 @@ async function getTasksFrom( taskFiles = [] ) {
33
32
 
34
33
  const module = await import(taskFile)
35
34
 
36
- const exportStrings = []
37
35
  for ( const moduleKey in module ) {
38
36
  const task = module[ moduleKey ]
39
37
  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
38
  }
48
39
 
49
- //log( 'Process ', green( relativeTaskFile ), `with task${ ( exportStrings.length > 1 ) ? 's' : '' }`, exportStrings.join( ', ' ) )
50
-
51
40
  } catch ( error ) {
52
41
 
53
42
  log( 'Error ', red( relativeTaskFile ), error.message )
@@ -79,7 +68,7 @@ async function parallelizeTasksFrom( taskFiles = [] ) {
79
68
  function getTaskConfigurationPathFor( filename ) {
80
69
 
81
70
  // Get relative path of the task between internal or user defined
82
- let relativeTaskPath = filename.includes( iteePackageSourcesDirectory )
71
+ let relativeTaskPath = filename.includes( iteePackageRootDirectory )
83
72
  ? relative( iteePackageSourcesDirectory, filename )
84
73
  : relative( packageTasksDirectory, filename )
85
74
 
@@ -93,23 +82,24 @@ function getTaskConfigurationPathFor( filename ) {
93
82
  '.conf.mjs',
94
83
  ]
95
84
 
96
- const packageConfigurationPaths = []
97
- const defaultConfigurationPaths = []
98
-
85
+ // Generate all potential config file paths
86
+ const configurationPaths = []
99
87
  for ( const replaceValue of replaceValues ) {
100
88
  const configurationLocation = relativeTaskPath.replace( searchValue, replaceValue )
101
89
  const packageConfigurationPath = join( packageTasksConfigurationsDirectory, configurationLocation )
102
- const defaultConfigurationPath = join( iteePackageSourcesDirectory, configurationLocation )
103
90
 
104
- packageConfigurationPaths.push( packageConfigurationPath )
105
- defaultConfigurationPaths.push( defaultConfigurationPath )
91
+ configurationPaths.push( packageConfigurationPath )
106
92
  }
107
93
 
108
94
  // Take care of the configuration search order (package first then default !)
109
- const configurationPaths = [ ...packageConfigurationPaths, ...defaultConfigurationPaths ]
110
- let configurationPath = undefined
95
+ const defaultConfigFilename = filename.includes( '.task.' )
96
+ ? filename.replace( '.task.', '.conf.' )
97
+ : filename.replace( '.mjs', '.conf.mjs' )
98
+
99
+ configurationPaths.push( defaultConfigFilename )
111
100
 
112
101
  // Looking for existing configuration file
102
+ let configurationPath = undefined
113
103
  for ( const packageConfigurationPath of configurationPaths ) {
114
104
 
115
105
  if ( existsSync( packageConfigurationPath ) ) {
@@ -0,0 +1,11 @@
1
+ async function getTestingPackage() {
2
+
3
+ const testingPackage = ( typeof global === 'undefined' )
4
+ ? await import('itee-utils/sources/testings/benchmarks.js')
5
+ : await import('itee-utils/builds/itee-utils.cjs')
6
+
7
+ return testingPackage.Testing
8
+
9
+ }
10
+
11
+ export { getTestingPackage }
@@ -1,5 +1,11 @@
1
1
  import { unstyle } from './colors.mjs'
2
2
 
3
+ /**
4
+ *
5
+ * @param {string} text
6
+ * @param {number} width
7
+ * @returns {string}
8
+ */
3
9
  function alignTextCenter( text, width ) {
4
10
 
5
11
  const unstyledText = unstyle( text.repeat( 1 ) )
@@ -19,6 +25,12 @@ function alignTextCenter( text, width ) {
19
25
 
20
26
  }
21
27
 
28
+ /**
29
+ *
30
+ * @param {string} text
31
+ * @param {number} width
32
+ * @returns {string}
33
+ */
22
34
  function alignTextLeft( text, width ) {
23
35
 
24
36
  const unstyledText = unstyle( text.repeat( 1 ) )
@@ -29,6 +41,12 @@ function alignTextLeft( text, width ) {
29
41
 
30
42
  }
31
43
 
44
+ /**
45
+ *
46
+ * @param {string} text
47
+ * @param {number} width
48
+ * @returns {string}
49
+ */
32
50
  function alignTextRight( text, width ) {
33
51
 
34
52
  const unstyledText = unstyle( text.repeat( 1 ) )
@@ -55,8 +73,14 @@ function IndenterFactory( indentationChar = '\t', indentationLevel = 5 ) {
55
73
 
56
74
  }
57
75
 
76
+ /**
77
+ * @param {string} string
78
+ * @returns {string}
79
+ */
58
80
  function toCamelCase( string ) {
59
81
 
82
+ if(typeof string !== 'string') throw new TypeError(`Invalid type '${typeof string}' expect string.`)
83
+
60
84
  return string
61
85
  .trim()
62
86
  .toLowerCase()