@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
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import childProcess from 'child_process'
|
|
2
|
+
import {
|
|
3
|
+
dirname,
|
|
4
|
+
join
|
|
5
|
+
} from 'node:path'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import {
|
|
8
|
+
red,
|
|
9
|
+
yellow
|
|
10
|
+
} from './colors.mjs'
|
|
11
|
+
import { getJsonFrom } from './files.mjs'
|
|
12
|
+
import { log } from './loggings.mjs'
|
|
13
|
+
|
|
14
|
+
function _getPackageRootDirectory() {
|
|
15
|
+
|
|
16
|
+
let __dirname
|
|
17
|
+
|
|
18
|
+
if ( import.meta.dirname ) {
|
|
19
|
+
__dirname = import.meta.dirname
|
|
20
|
+
} else if ( import.meta.filename ) {
|
|
21
|
+
__dirname = dirname( import.meta.filename )
|
|
22
|
+
} else if ( import.meta.url ) {
|
|
23
|
+
const __filename = fileURLToPath( import.meta.url )
|
|
24
|
+
__dirname = dirname( __filename )
|
|
25
|
+
} else {
|
|
26
|
+
throw new Error( 'Unable to retrieve module dirname.' )
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return join( __dirname, '../../' )
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const iteePackageRootDirectory = _getPackageRootDirectory()
|
|
34
|
+
const iteePackageJsonPath = join( iteePackageRootDirectory, 'package.json' )
|
|
35
|
+
const iteePackageNodeModulesDirectory = join( iteePackageRootDirectory, 'node_modules' )
|
|
36
|
+
const iteePackageSourcesDirectory = join( iteePackageRootDirectory, 'sources' )
|
|
37
|
+
|
|
38
|
+
const packageRootDirectory = iteePackageRootDirectory.includes( 'node_modules' ) ? join( iteePackageRootDirectory, '../../../' ) : iteePackageRootDirectory
|
|
39
|
+
const packageTasksDirectory = join( packageRootDirectory, '.tasks' )
|
|
40
|
+
const packageTasksConfigurationsDirectory = join( packageTasksDirectory, 'configs' )
|
|
41
|
+
const packageNodeModulesDirectory = join( packageRootDirectory, 'node_modules' )
|
|
42
|
+
const packageBuildsDirectory = join( packageRootDirectory, 'builds' )
|
|
43
|
+
const packageSourcesDirectory = join( packageRootDirectory, 'sources' )
|
|
44
|
+
const packageSourcesBackendDirectory = join( packageSourcesDirectory, 'backend' )
|
|
45
|
+
const packageSourcesCommonDirectory = join( packageSourcesDirectory, 'common' )
|
|
46
|
+
const packageSourcesFrontendDirectory = join( packageSourcesDirectory, 'frontend' )
|
|
47
|
+
const packageTestsDirectory = join( packageRootDirectory, 'tests' )
|
|
48
|
+
const packageTestsBenchmarksDirectory = join( packageTestsDirectory, 'benchmarks' )
|
|
49
|
+
const packageTestsBundlesDirectory = join( packageTestsDirectory, 'bundles' )
|
|
50
|
+
const packageTestsUnitsDirectory = join( packageTestsDirectory, 'units' )
|
|
51
|
+
const packageDocsDirectory = join( packageRootDirectory, 'docs' )
|
|
52
|
+
const packageTutorialsDirectory = join( packageRootDirectory, 'tutorials' )
|
|
53
|
+
const packageJsonPath = join( packageRootDirectory, 'package.json' )
|
|
54
|
+
|
|
55
|
+
///
|
|
56
|
+
|
|
57
|
+
const packageJson = getJsonFrom( packageJsonPath )
|
|
58
|
+
const packageName = packageJson.name
|
|
59
|
+
const packageVersion = packageJson.version
|
|
60
|
+
const packageDescription = packageJson.description
|
|
61
|
+
const packageAuthor = packageJson.author
|
|
62
|
+
const packageLicense = packageJson.license
|
|
63
|
+
const packageMain = packageJson.main
|
|
64
|
+
|
|
65
|
+
function getUnscopedPackageName() {
|
|
66
|
+
|
|
67
|
+
return packageName.startsWith( '@' )
|
|
68
|
+
? packageName.split( '/' )[ 1 ]
|
|
69
|
+
: packageName.split( '-' )[ 1 ]
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getPrettyPackageName( separator = ' ' ) {
|
|
74
|
+
|
|
75
|
+
let prettyPackageName = ''
|
|
76
|
+
|
|
77
|
+
const nameSplits = packageName.startsWith( '@' )
|
|
78
|
+
? packageName.slice( 1 ).split( '/' )
|
|
79
|
+
: packageName.split( '-' )
|
|
80
|
+
|
|
81
|
+
for ( const nameSplit of nameSplits ) {
|
|
82
|
+
prettyPackageName += nameSplit.charAt( 0 ).toUpperCase() + nameSplit.slice( 1 ) + separator
|
|
83
|
+
}
|
|
84
|
+
prettyPackageName = prettyPackageName.slice( 0, -1 )
|
|
85
|
+
|
|
86
|
+
return prettyPackageName
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function getPrettyPackageVersion() {
|
|
91
|
+
|
|
92
|
+
return 'v' + packageVersion
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function getPrettyNodeVersion() {
|
|
97
|
+
|
|
98
|
+
let nodeVersion = 'vX.x.ₓ'
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
nodeVersion = childProcess.execFileSync( 'node', [ '--version' ] )
|
|
102
|
+
.toString()
|
|
103
|
+
.replace( /(\r\n|\n|\r)/gm, '' )
|
|
104
|
+
} catch ( e ) {
|
|
105
|
+
log( red( e ) )
|
|
106
|
+
|
|
107
|
+
if ( e.message.includes( 'ENOENT' ) ) {
|
|
108
|
+
nodeVersion += yellow( ' Not seems to be accessible from the path environment.' )
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return ' node: ' + nodeVersion
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function getPrettyNpmVersion() {
|
|
117
|
+
|
|
118
|
+
let npmVersion = 'X.x.ₓ'
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
npmVersion = childProcess.execFileSync( 'npm', [ '--version' ] )
|
|
122
|
+
.toString()
|
|
123
|
+
.replace( /(\r\n|\n|\r)/gm, '' )
|
|
124
|
+
} catch ( e ) {
|
|
125
|
+
log( red( e ) )
|
|
126
|
+
|
|
127
|
+
if ( e.message.includes( 'ENOENT' ) ) {
|
|
128
|
+
npmVersion += yellow( ' Not seems to be accessible from the path environment.' )
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return ' npm: v' + npmVersion
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
export {
|
|
138
|
+
iteePackageRootDirectory,
|
|
139
|
+
iteePackageJsonPath,
|
|
140
|
+
iteePackageNodeModulesDirectory,
|
|
141
|
+
iteePackageSourcesDirectory,
|
|
142
|
+
|
|
143
|
+
packageRootDirectory,
|
|
144
|
+
packageTasksDirectory,
|
|
145
|
+
packageTasksConfigurationsDirectory,
|
|
146
|
+
packageNodeModulesDirectory,
|
|
147
|
+
packageBuildsDirectory,
|
|
148
|
+
packageSourcesDirectory,
|
|
149
|
+
packageSourcesBackendDirectory,
|
|
150
|
+
packageSourcesCommonDirectory,
|
|
151
|
+
packageSourcesFrontendDirectory,
|
|
152
|
+
packageTestsDirectory,
|
|
153
|
+
packageTestsBenchmarksDirectory,
|
|
154
|
+
packageTestsBundlesDirectory,
|
|
155
|
+
packageTestsUnitsDirectory,
|
|
156
|
+
packageDocsDirectory,
|
|
157
|
+
packageTutorialsDirectory,
|
|
158
|
+
packageJsonPath,
|
|
159
|
+
|
|
160
|
+
packageJson,
|
|
161
|
+
packageName,
|
|
162
|
+
packageVersion,
|
|
163
|
+
packageDescription,
|
|
164
|
+
packageAuthor,
|
|
165
|
+
packageLicense,
|
|
166
|
+
packageMain,
|
|
167
|
+
getUnscopedPackageName,
|
|
168
|
+
getPrettyPackageName,
|
|
169
|
+
getPrettyPackageVersion,
|
|
170
|
+
getPrettyNodeVersion,
|
|
171
|
+
getPrettyNpmVersion,
|
|
172
|
+
}
|
|
@@ -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
|
+
}
|