@lipemat/js-boilerplate-shared 0.2.1 → 1.0.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.
- package/config/tsconfig.json +37 -0
- package/helpers/config.js +51 -0
- package/helpers/config.js.map +1 -1
- package/helpers/config.ts +50 -0
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"//~~": "PHPStorm will only see changes to the file if you re-save the project root's tsconfig.json file",
|
|
3
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
4
|
+
"display": "JS Boilerplate",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"allowImportingTsExtensions": true,
|
|
7
|
+
"allowSyntheticDefaultImports": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"jsx": "react-jsx",
|
|
11
|
+
"lib": [
|
|
12
|
+
"DOM",
|
|
13
|
+
"ES2022"
|
|
14
|
+
],
|
|
15
|
+
"module": "ESNext",
|
|
16
|
+
"moduleResolution": "bundler",
|
|
17
|
+
"noEmit": true,
|
|
18
|
+
"noFallthroughCasesInSwitch": true,
|
|
19
|
+
"noImplicitReturns": true,
|
|
20
|
+
"noImplicitThis": true,
|
|
21
|
+
"paths": {
|
|
22
|
+
"$src": [
|
|
23
|
+
"./js/src"
|
|
24
|
+
],
|
|
25
|
+
"$src/*": [
|
|
26
|
+
"./js/src/*"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"skipLibCheck": true,
|
|
30
|
+
"sourceMap": true,
|
|
31
|
+
"strict": true,
|
|
32
|
+
"strictBindCallApply": true,
|
|
33
|
+
"strictNullChecks": true,
|
|
34
|
+
"target": "ES2022",
|
|
35
|
+
"verbatimModuleSyntax": false
|
|
36
|
+
}
|
|
37
|
+
}
|
package/helpers/config.js
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
import { getPackageConfig } from './package-config.js';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
|
+
import { resolve } from 'path';
|
|
3
4
|
const requireModule = createRequire(import.meta.url);
|
|
5
|
+
/**
|
|
6
|
+
* Merged a configuration with a matching configuration from the project directory.
|
|
7
|
+
*
|
|
8
|
+
* For instance, if we have a file named config/babel.config.js in our project,
|
|
9
|
+
* we will merge the contents with our config/babel.config.js in favor of whatever
|
|
10
|
+
* is specified with the project's file.
|
|
11
|
+
*
|
|
12
|
+
* If the default export is a function, the existing configuration will be passed
|
|
13
|
+
* as the only argument. Otherwise, standard `exports` are also supported.
|
|
14
|
+
*
|
|
15
|
+
* @example ```ts
|
|
16
|
+
* // standard
|
|
17
|
+
*export default = {
|
|
18
|
+
* externals: {extra: 'Extra'}
|
|
19
|
+
* }
|
|
20
|
+
* // function
|
|
21
|
+
* export default function(config) {
|
|
22
|
+
* return {
|
|
23
|
+
* externals: {...config.externals, extra: 'Extra'}
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param {string} fileName - Filename without extension.
|
|
29
|
+
* @param {Object} mergedConfig - Existing config to merge with.
|
|
30
|
+
*
|
|
31
|
+
* @return {Object}
|
|
32
|
+
*/
|
|
33
|
+
export function mergeWithLocalConfig(fileName, mergedConfig = {}) {
|
|
34
|
+
try {
|
|
35
|
+
let localConfig = createRequire(import.meta.url)(resolve(getPackageConfig().packageDirectory, 'config', fileName.replace(/\.js$/, '')));
|
|
36
|
+
if ('default' in localConfig) {
|
|
37
|
+
localConfig = localConfig.default;
|
|
38
|
+
}
|
|
39
|
+
if ('function' === typeof localConfig) {
|
|
40
|
+
mergedConfig = { ...mergedConfig, ...localConfig(mergedConfig) };
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
mergedConfig = { ...mergedConfig, ...localConfig };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
if (e instanceof Error) {
|
|
48
|
+
if (!('code' in e) || ('MODULE_NOT_FOUND' !== e.code && 'ERR_MODULE_NOT_FOUND' !== e.code)) {
|
|
49
|
+
console.error(e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return mergedConfig;
|
|
54
|
+
}
|
|
4
55
|
/**
|
|
5
56
|
* Get a list of installed js-boilerplate extensions.
|
|
6
57
|
*
|
package/helpers/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAC;AAE7B,MAAM,aAAa,GAAG,aAAa,CAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAE,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,oBAAoB,CAAoB,QAAgB,EAAE,eAAuB,EAAE;IAClG,IAAI,CAAC;QACJ,IAAI,WAAW,GAAG,aAAa,CAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAE,CAAE,OAAO,CAAE,gBAAgB,EAAE,CAAC,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAE,OAAO,EAAE,EAAE,CAAE,CAAE,CAAE,CAAC;QAChJ,IAAK,SAAS,IAAI,WAAW,EAAG,CAAC;YAChC,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC;QACnC,CAAC;QAED,IAAK,UAAU,KAAK,OAAO,WAAW,EAAG,CAAC;YACzC,YAAY,G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AS,IAAI,eAAe,EAAG,CAAC;gBACpC,eAAe,GAAG,eAAe,CAAC,OAAO,CAAC;YAC3C,CAAC;YACD,IAAK,UAAU,KAAK,OAAO,eAAe,EAAG,CAAC;gBAC7C,YAAY,GAAG,EAAC,GAAG,YAAY,EAAE,GAAG,eAAe,CAAE,EAAC,GAAG,aAAa,EAAE,GAAG,YAAY,EAAC,CAAE,EAAC,CAAC;YAC7F,CAAC;iBAAM,CAAC;gBACP,YAAY,GAAG,EAAC,GAAG,YAAY,EAAE,GAAG,eAAe,EAAC,CAAC;YACtD,CAAC;QACF,CAAC;QAAC,OAAQ,CAAC,EAAG,CAAC;YACd,IAAK,CAAC,YAAY,KAAK,EAAG,CAAC;gBAC1B,IAAK,CAAE,CAAE,MAAM,IAAI,CAAC,CAAE,IAAI,kBAAkB,KAAK,CAAC,CAAC,IAAI,EAAG,CAAC;oBAC1D,OAAO,CAAC,KAAK,CAAE,CAAC,CAAE,CAAC;gBACpB,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,YAAY,CAAC;AACrB,CAAC;AAGD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAE,QAAgB;IAClD,MAAM,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAE,YAAY,EAAE,EAAE,CAAE,CAAC;IAC9D,IAAK,CAAE,gBAAgB,CAAC,QAAQ,CAAE,KAAK,CAAE,EAAG,CAAC;QAC5C,OAAO,gBAAgB,GAAG,KAAK,CAAC;IACjC,CAAC;IACD,OAAO,gBAAgB,CAAC;AACzB,CAAC"}
|
package/helpers/config.ts
CHANGED
|
@@ -1,8 +1,58 @@
|
|
|
1
1
|
import {getPackageConfig} from './package-config.js';
|
|
2
2
|
import {createRequire} from 'node:module';
|
|
3
|
+
import {resolve} from 'path';
|
|
3
4
|
|
|
4
5
|
const requireModule = createRequire( import.meta.url );
|
|
5
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Merged a configuration with a matching configuration from the project directory.
|
|
9
|
+
*
|
|
10
|
+
* For instance, if we have a file named config/babel.config.js in our project,
|
|
11
|
+
* we will merge the contents with our config/babel.config.js in favor of whatever
|
|
12
|
+
* is specified with the project's file.
|
|
13
|
+
*
|
|
14
|
+
* If the default export is a function, the existing configuration will be passed
|
|
15
|
+
* as the only argument. Otherwise, standard `exports` are also supported.
|
|
16
|
+
*
|
|
17
|
+
* @example ```ts
|
|
18
|
+
* // standard
|
|
19
|
+
*export default = {
|
|
20
|
+
* externals: {extra: 'Extra'}
|
|
21
|
+
* }
|
|
22
|
+
* // function
|
|
23
|
+
* export default function(config) {
|
|
24
|
+
* return {
|
|
25
|
+
* externals: {...config.externals, extra: 'Extra'}
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @param {string} fileName - Filename without extension.
|
|
31
|
+
* @param {Object} mergedConfig - Existing config to merge with.
|
|
32
|
+
*
|
|
33
|
+
* @return {Object}
|
|
34
|
+
*/
|
|
35
|
+
export function mergeWithLocalConfig<T extends object>( fileName: string, mergedConfig: object = {} ): T {
|
|
36
|
+
try {
|
|
37
|
+
let localConfig = createRequire( import.meta.url )( resolve( getPackageConfig().packageDirectory, 'config', fileName.replace( /\.js$/, '' ) ) );
|
|
38
|
+
if ( 'default' in localConfig ) {
|
|
39
|
+
localConfig = localConfig.default;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if ( 'function' === typeof localConfig ) {
|
|
43
|
+
mergedConfig = {...mergedConfig, ...localConfig( mergedConfig )};
|
|
44
|
+
} else {
|
|
45
|
+
mergedConfig = {...mergedConfig, ...localConfig};
|
|
46
|
+
}
|
|
47
|
+
} catch ( e ) {
|
|
48
|
+
if ( e instanceof Error ) {
|
|
49
|
+
if ( ! ( 'code' in e ) || ( 'MODULE_NOT_FOUND' !== e.code && 'ERR_MODULE_NOT_FOUND' !== e.code ) ) {
|
|
50
|
+
console.error( e );
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return mergedConfig as T;
|
|
55
|
+
}
|
|
6
56
|
|
|
7
57
|
/**
|
|
8
58
|
* Get a list of installed js-boilerplate extensions.
|