@lipemat/js-boilerplate 10.7.1 → 10.8.0-beta.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.
- package/bin/build.ts +33 -0
- package/bin/lipemat-js-boilerplate.js +0 -0
- package/bin/watch.ts +21 -0
- package/config/babel.config.d.ts +15 -0
- package/config/babel.config.js +7 -11
- package/config/jest.config.d.ts +4 -0
- package/config/jest.config.js +18 -32
- package/helpers/config.d.ts +98 -5
- package/helpers/config.js +25 -37
- package/helpers/package-config.d.ts +41 -38
- package/helpers/package-config.js +21 -19
- package/package.json +7 -4
- package/scripts/lint.ts +2 -2
- package/tsconfig.json +0 -17
package/bin/build.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {execSync} from 'node:child_process';
|
|
2
|
+
import {ESLint} from 'eslint';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
|
|
5
|
+
const FILES = [
|
|
6
|
+
'config/babel.config',
|
|
7
|
+
'config/jest.config',
|
|
8
|
+
'helpers/config',
|
|
9
|
+
'helpers/package-config',
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
console.log( chalk.blue( '[TS] ' ) + ' Compiling the files from the src directory.' );
|
|
13
|
+
execSync( 'tsc -p src', {stdio: 'inherit'} );
|
|
14
|
+
|
|
15
|
+
FILES.forEach( async file => {
|
|
16
|
+
const destination = `${file}`;
|
|
17
|
+
console.log( chalk.blueBright( '[ESLint] ' ) + `Reformatting ${destination}.js.` );
|
|
18
|
+
|
|
19
|
+
// 1. Create an instance with the `fix` and `cache` options.
|
|
20
|
+
const eslint = new ESLint( {
|
|
21
|
+
fix: true,
|
|
22
|
+
cache: true,
|
|
23
|
+
cacheStrategy: 'content',
|
|
24
|
+
} );
|
|
25
|
+
|
|
26
|
+
// 2. Lint files. This doesn't modify target files.
|
|
27
|
+
const results: ESLint.LintResult[] = await eslint.lintFiles( [
|
|
28
|
+
file + '*.{js,jsx,ts,tsx}',
|
|
29
|
+
] );
|
|
30
|
+
|
|
31
|
+
// 3. Modify the files with the fixed code.
|
|
32
|
+
await ESLint.outputFixes( results );
|
|
33
|
+
} );
|
|
File without changes
|
package/bin/watch.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import chokidar from 'chokidar';
|
|
2
|
+
import {exec} from 'child_process';
|
|
3
|
+
import {red} from 'chalk';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Watch for changes in the src directory and run the build script when a change is detected.
|
|
7
|
+
*/
|
|
8
|
+
chokidar.watch( 'src', {ignored: /(^|[\/\\])\../} )
|
|
9
|
+
.on( 'change', path => {
|
|
10
|
+
console.log( `${path} changed` );
|
|
11
|
+
exec( 'yarn run build', ( err, stdout ) => {
|
|
12
|
+
if ( err ) {
|
|
13
|
+
console.error( red( stdout ) );
|
|
14
|
+
} else {
|
|
15
|
+
console.log( stdout );
|
|
16
|
+
}
|
|
17
|
+
} );
|
|
18
|
+
} )
|
|
19
|
+
.once( 'ready', () => {
|
|
20
|
+
console.log( 'Watching for changes in the src directory...' );
|
|
21
|
+
} )
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type {TransformOptions} from '@babel/core';
|
|
2
|
+
export type BabelConfig = Pick<BabelFull, 'presets' | 'plugins' | 'cacheDirectory'>;
|
|
3
|
+
export type BabelFull = Partial<TransformOptions> & BabelLoader;
|
|
4
|
+
/**
|
|
5
|
+
* @link https://webpack.js.org/loaders/babel-loader/#options
|
|
6
|
+
*/
|
|
7
|
+
export type BabelLoader = {
|
|
8
|
+
cacheDirectory?: boolean | string;
|
|
9
|
+
cacheIdentifier?: string;
|
|
10
|
+
cacheCompression?: boolean;
|
|
11
|
+
customize?: string;
|
|
12
|
+
metadataSubscribers?: string[];
|
|
13
|
+
};
|
|
14
|
+
declare const babelConfig: BabelConfig;
|
|
15
|
+
export default babelConfig;
|
package/config/babel.config.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @notice This file must NOT be a TS file because it is used
|
|
5
|
-
* as part of the JEST configuration.
|
|
6
|
-
*/
|
|
7
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty( exports, '__esModule', {value: true} );
|
|
3
|
+
const config_1 = require( '../helpers/config' );
|
|
8
4
|
/**
|
|
9
5
|
* Use Babel's preset-env to add support for target browsers.
|
|
10
6
|
*
|
|
@@ -25,13 +21,11 @@ const presetEnv = {
|
|
|
25
21
|
ignoreBrowserslistConfig: true,
|
|
26
22
|
shippedProposals: false,
|
|
27
23
|
targets: {
|
|
28
|
-
browsers: getBrowsersList(),
|
|
24
|
+
browsers: ( 0, config_1.getBrowsersList )(),
|
|
29
25
|
},
|
|
30
26
|
useBuiltIns: 'usage',
|
|
31
27
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
module.exports = {
|
|
28
|
+
const babelConfig = {
|
|
35
29
|
cacheDirectory: true,
|
|
36
30
|
presets: [
|
|
37
31
|
[ '@babel/preset-env', presetEnv ],
|
|
@@ -45,3 +39,5 @@ module.exports = {
|
|
|
45
39
|
'@babel/plugin-syntax-dynamic-import',
|
|
46
40
|
],
|
|
47
41
|
};
|
|
42
|
+
exports.default = babelConfig;
|
|
43
|
+
module.exports = babelConfig;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type {Config} from 'jest';
|
|
2
|
+
export type JestConfig = Pick<Config, 'globals' | 'moduleNameMapper' | 'roots' | 'testEnvironment' | 'testEnvironmentOptions' | 'transform' | 'transformIgnorePatterns' | 'setupFilesAfterEnv'>;
|
|
3
|
+
declare const jestConfig: Config;
|
|
4
|
+
export default jestConfig;
|
package/config/jest.config.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty( exports, '__esModule', {value: true} );
|
|
3
|
+
const path_1 = require( 'path' );
|
|
4
|
+
const fs_1 = require( 'fs' );
|
|
5
|
+
const package_config_1 = require( '../helpers/package-config' );
|
|
6
|
+
const config_1 = require( '../helpers/config' );
|
|
7
|
+
const {workingDirectory, url} = ( 0, package_config_1.getPackageConfig )();
|
|
8
|
+
const babelConfig = ( 0, config_1.getConfig )( 'babel.config' );
|
|
6
9
|
delete babelConfig.cacheDirectory;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @todo Rename this file to `jest.config.ts` in version 11.
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
let jestConfig = {
|
|
10
|
+
const jestConfig = {
|
|
14
11
|
globals: {
|
|
15
12
|
__TEST__: true,
|
|
16
13
|
},
|
|
@@ -24,32 +21,21 @@ let jestConfig = {
|
|
|
24
21
|
],
|
|
25
22
|
testEnvironment: 'jsdom',
|
|
26
23
|
testEnvironmentOptions: {
|
|
27
|
-
url
|
|
24
|
+
url,
|
|
28
25
|
},
|
|
29
26
|
transform: {
|
|
30
27
|
'^.+\\.[tj]sx?$': [ 'babel-jest', babelConfig ],
|
|
31
28
|
},
|
|
29
|
+
transformIgnorePatterns: [
|
|
30
|
+
'node_modules/(?!@lipemat)',
|
|
31
|
+
],
|
|
32
32
|
setupFilesAfterEnv: [
|
|
33
33
|
// @todo Remove old "tests" directory in version 11.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
( 0, path_1.resolve )( workingDirectory, 'tests/setup.js' ),
|
|
35
|
+
( 0, path_1.resolve )( workingDirectory, 'tests/setup.ts' ),
|
|
37
36
|
// New location.
|
|
38
|
-
|
|
39
|
-
].filter(
|
|
37
|
+
( 0, path_1.resolve )( workingDirectory, 'jest/setup.ts' ),
|
|
38
|
+
].filter( fs_1.existsSync ),
|
|
40
39
|
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Allows overriding configurations in the project `/config/jest.config.js` file.
|
|
44
|
-
* We don't actually need to do this because `jest.config.js` in the project root
|
|
45
|
-
* is already an override of this file, but we support it anyway to keep things consistent.
|
|
46
|
-
*
|
|
47
|
-
* @todo Remove in version 11.
|
|
48
|
-
*/
|
|
49
|
-
try {
|
|
50
|
-
const localConfig = require( path.resolve( packageConfig.workingDirectory + '/config', 'jest.config.js' ) );
|
|
51
|
-
jestConfig = {...jestConfig, ...localConfig};
|
|
52
|
-
} catch ( e ) {
|
|
53
|
-
}
|
|
54
|
-
|
|
40
|
+
exports.default = jestConfig;
|
|
55
41
|
module.exports = jestConfig;
|
package/helpers/config.d.ts
CHANGED
|
@@ -1,7 +1,100 @@
|
|
|
1
|
+
import type {BabelConfig} from '../config/babel.config';
|
|
2
|
+
import type {JestConfig} from '../config/jest.config';
|
|
3
|
+
type Configs = {
|
|
4
|
+
'babel.config': BabelConfig;
|
|
5
|
+
'jest.config': JestConfig;
|
|
6
|
+
};
|
|
1
7
|
/**
|
|
2
|
-
*
|
|
8
|
+
* Check to see if a local config file exists.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} fileName
|
|
11
|
+
* @param {boolean} inWorkingDirectory - Look in working directory instead of their /config directory
|
|
12
|
+
*
|
|
13
|
+
* @return {boolean}
|
|
3
14
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
15
|
+
export declare function hasLocalOverride( fileName: string, inWorkingDirectory?: boolean ): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Get a config from our /config directory merged with any
|
|
18
|
+
* matching configuration from the project directory.
|
|
19
|
+
*
|
|
20
|
+
* For instance if we have a file named config/babel.config.js in our project
|
|
21
|
+
* we will merge the contents with our config/babel.config.js in favor of whatever
|
|
22
|
+
* is specified with the project's file.
|
|
23
|
+
*
|
|
24
|
+
* If the `module.exports` are a function, the existing configuration will be passed
|
|
25
|
+
* as the only argument. Otherwise, standard `module.exports` are also supported.
|
|
26
|
+
*
|
|
27
|
+
* @example ```ts
|
|
28
|
+
* // standard
|
|
29
|
+
* module.export = {
|
|
30
|
+
* externals: {extra: 'Extra'}
|
|
31
|
+
* }
|
|
32
|
+
* // function
|
|
33
|
+
* module.exports = function( config ) {
|
|
34
|
+
* return {
|
|
35
|
+
* externals: {...config.externals, extra: 'Extra'}
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param {string} fileName
|
|
41
|
+
*
|
|
42
|
+
* @return {Object}
|
|
43
|
+
*/
|
|
44
|
+
export declare function getConfig<T extends keyof Configs>( fileName: T ): Configs[T];
|
|
45
|
+
/**
|
|
46
|
+
* Get a config from any existing extension's /config directories
|
|
47
|
+
* merged into one.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} fileName
|
|
50
|
+
* @param {Object} defaultConfig - Default config from this package.
|
|
51
|
+
* Used for passing to an extension callback.
|
|
52
|
+
*
|
|
53
|
+
* @see getConfig
|
|
54
|
+
*
|
|
55
|
+
* @return {Object}
|
|
56
|
+
*/
|
|
57
|
+
export declare function getExtensionsConfig<T extends object>( fileName: string, defaultConfig: T ): T;
|
|
58
|
+
/**
|
|
59
|
+
* Get the path to the "tsconfig.json" file if it exists.
|
|
60
|
+
*
|
|
61
|
+
* 1. The working directory.
|
|
62
|
+
* 2. The package directory.
|
|
63
|
+
*
|
|
64
|
+
* The package directory takes priority over the working directory.
|
|
65
|
+
*
|
|
66
|
+
*
|
|
67
|
+
* @return {string}
|
|
68
|
+
*/
|
|
69
|
+
export declare function getTsConfigFile(): string;
|
|
70
|
+
/**
|
|
71
|
+
* Get the browserslist from the current project.
|
|
72
|
+
*
|
|
73
|
+
* - If specified using standard browserslist config, we will use that.
|
|
74
|
+
*
|
|
75
|
+
* @link https://github.com/browserslist/browserslist#config-file
|
|
76
|
+
*/
|
|
77
|
+
export declare function getBrowsersList(): readonly string[];
|
|
78
|
+
/**
|
|
79
|
+
* If browserslist is not specified, we fall back to WordPress defaults.
|
|
80
|
+
*
|
|
81
|
+
* - Return the default browserslist if the current project does not specify one.
|
|
82
|
+
* - Return false if a browserslist is specified.
|
|
83
|
+
*
|
|
84
|
+
* Used in cases where we can fall back to standard browserslist config if the project
|
|
85
|
+
* has not specified one.
|
|
86
|
+
*
|
|
87
|
+
* @deprecated Use getBrowsersList instead.
|
|
88
|
+
*
|
|
89
|
+
* @link https://github.com/browserslist/browserslist#config-file
|
|
90
|
+
*
|
|
91
|
+
* @return {boolean | string[]}
|
|
92
|
+
*/
|
|
93
|
+
export declare const getDefaultBrowsersList: () => false | string[];
|
|
94
|
+
/**
|
|
95
|
+
* Adjust the browserslist to include our defaults.
|
|
96
|
+
*
|
|
97
|
+
* @todo Remove `not op_mini all` after 3/8/2024 if it does not creep back in to the defaults.
|
|
98
|
+
*/
|
|
99
|
+
export declare function adjustBrowserslist( browserRules: string[] ): string[];
|
|
100
|
+
export {};
|
package/helpers/config.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty( exports, '__esModule', {value: true} );
|
|
3
|
+
exports.adjustBrowserslist = exports.getDefaultBrowsersList = exports.getBrowsersList = exports.getTsConfigFile = exports.getExtensionsConfig = exports.getConfig = exports.hasLocalOverride = void 0;
|
|
4
|
+
const fs_1 = require( 'fs' );
|
|
5
|
+
const path_1 = require( 'path' );
|
|
3
6
|
const browserslist = require( 'browserslist' );
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
+
const package_config_1 = require( './package-config' );
|
|
8
|
+
const {dependencies, devDependencies, workingDirectory, packageDirectory} = ( 0, package_config_1.getPackageConfig )();
|
|
7
9
|
const extensions = [
|
|
8
|
-
...Object.keys(
|
|
9
|
-
...Object.keys(
|
|
10
|
+
...Object.keys( dependencies ?? {} ).filter( name => name.includes( 'js-boilerplate-' ) ),
|
|
11
|
+
...Object.keys( devDependencies ?? {} ).filter( name => name.includes( 'js-boilerplate-' ) ),
|
|
10
12
|
];
|
|
11
|
-
|
|
12
13
|
/**
|
|
13
14
|
* Check to see if a local config file exists.
|
|
14
15
|
*
|
|
@@ -17,22 +18,21 @@ const extensions = [
|
|
|
17
18
|
*
|
|
18
19
|
* @return {boolean}
|
|
19
20
|
*/
|
|
20
|
-
function hasLocalOverride( fileName, inWorkingDirectory = false
|
|
21
|
+
function hasLocalOverride( fileName, inWorkingDirectory = false ) {
|
|
21
22
|
let hasLocal = false;
|
|
22
23
|
try {
|
|
23
24
|
if ( inWorkingDirectory ) {
|
|
24
|
-
require(
|
|
25
|
+
require( ( 0, path_1.resolve )( workingDirectory, fileName ) );
|
|
25
26
|
hasLocal = true;
|
|
26
27
|
} else {
|
|
27
|
-
require(
|
|
28
|
+
require( ( 0, path_1.resolve )( packageDirectory + '/config', fileName ) );
|
|
28
29
|
hasLocal = true;
|
|
29
30
|
}
|
|
30
31
|
} catch ( e ) {
|
|
31
32
|
}
|
|
32
|
-
|
|
33
33
|
return hasLocal;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
exports.hasLocalOverride = hasLocalOverride;
|
|
36
36
|
/**
|
|
37
37
|
* Get a config from our /config directory merged with any
|
|
38
38
|
* matching configuration from the project directory.
|
|
@@ -65,7 +65,7 @@ function getConfig( fileName ) {
|
|
|
65
65
|
let mergedConfig = require( '../config/' + fileName );
|
|
66
66
|
mergedConfig = {...mergedConfig, ...getExtensionsConfig( fileName, mergedConfig )};
|
|
67
67
|
try {
|
|
68
|
-
const localConfig = require(
|
|
68
|
+
const localConfig = require( ( 0, path_1.resolve )( packageDirectory + '/config', fileName ) );
|
|
69
69
|
if ( 'function' === typeof localConfig ) {
|
|
70
70
|
mergedConfig = {...mergedConfig, ...localConfig( mergedConfig )};
|
|
71
71
|
} else {
|
|
@@ -75,7 +75,7 @@ function getConfig( fileName ) {
|
|
|
75
75
|
}
|
|
76
76
|
return mergedConfig;
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
exports.getConfig = getConfig;
|
|
79
79
|
/**
|
|
80
80
|
* Get a config from any existing extension's /config directories
|
|
81
81
|
* merged into one.
|
|
@@ -101,10 +101,9 @@ function getExtensionsConfig( fileName, defaultConfig ) {
|
|
|
101
101
|
} catch ( e ) {
|
|
102
102
|
}
|
|
103
103
|
} );
|
|
104
|
-
|
|
105
104
|
return mergedConfig;
|
|
106
105
|
}
|
|
107
|
-
|
|
106
|
+
exports.getExtensionsConfig = getExtensionsConfig;
|
|
108
107
|
/**
|
|
109
108
|
* Get the path to the "tsconfig.json" file if it exists.
|
|
110
109
|
*
|
|
@@ -119,18 +118,16 @@ function getExtensionsConfig( fileName, defaultConfig ) {
|
|
|
119
118
|
function getTsConfigFile() {
|
|
120
119
|
const possibles = [
|
|
121
120
|
// Backward compatible for before @lipemat/eslint-config version 3.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
];
|
|
121
|
+
( 0, path_1.resolve )( workingDirectory + '/tsconfig.json' ),
|
|
122
|
+
( 0, path_1.resolve )( packageDirectory + '/tsconfig.json' ),
|
|
123
|
+
].filter( fs_1.existsSync );
|
|
125
124
|
let tsConfig = '';
|
|
126
125
|
possibles.forEach( filePath => {
|
|
127
|
-
|
|
128
|
-
tsConfig = filePath;
|
|
129
|
-
}
|
|
126
|
+
tsConfig = filePath;
|
|
130
127
|
} );
|
|
131
128
|
return tsConfig;
|
|
132
129
|
}
|
|
133
|
-
|
|
130
|
+
exports.getTsConfigFile = getTsConfigFile;
|
|
134
131
|
/**
|
|
135
132
|
* Get the browserslist from the current project.
|
|
136
133
|
*
|
|
@@ -146,7 +143,7 @@ function getBrowsersList() {
|
|
|
146
143
|
}
|
|
147
144
|
return projectBrowsersList;
|
|
148
145
|
}
|
|
149
|
-
|
|
146
|
+
exports.getBrowsersList = getBrowsersList;
|
|
150
147
|
/**
|
|
151
148
|
* If browserslist is not specified, we fall back to WordPress defaults.
|
|
152
149
|
*
|
|
@@ -157,6 +154,7 @@ function getBrowsersList() {
|
|
|
157
154
|
* has not specified one.
|
|
158
155
|
*
|
|
159
156
|
* @deprecated Use getBrowsersList instead.
|
|
157
|
+
*
|
|
160
158
|
* @link https://github.com/browserslist/browserslist#config-file
|
|
161
159
|
*
|
|
162
160
|
* @return {boolean | string[]}
|
|
@@ -168,7 +166,7 @@ const getDefaultBrowsersList = () => {
|
|
|
168
166
|
}
|
|
169
167
|
return false;
|
|
170
168
|
};
|
|
171
|
-
|
|
169
|
+
exports.getDefaultBrowsersList = getDefaultBrowsersList;
|
|
172
170
|
/**
|
|
173
171
|
* Adjust the browserslist to include our defaults.
|
|
174
172
|
*
|
|
@@ -178,14 +176,4 @@ function adjustBrowserslist( browserRules ) {
|
|
|
178
176
|
browserRules.push( 'not op_mini all' );
|
|
179
177
|
return browserRules;
|
|
180
178
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
module.exports = {
|
|
184
|
-
adjustBrowserslist,
|
|
185
|
-
getBrowsersList,
|
|
186
|
-
getConfig,
|
|
187
|
-
getDefaultBrowsersList,
|
|
188
|
-
getExtensionsConfig,
|
|
189
|
-
getTsConfigFile,
|
|
190
|
-
hasLocalOverride,
|
|
191
|
-
};
|
|
179
|
+
exports.adjustBrowserslist = adjustBrowserslist;
|
|
@@ -1,46 +1,49 @@
|
|
|
1
1
|
export interface PackageConfig {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
author?: string;
|
|
3
|
+
brotliFiles: boolean;
|
|
4
|
+
certificates?: Certificates;
|
|
5
|
+
combinedJson: boolean;
|
|
6
|
+
cssTsFiles: boolean;
|
|
7
|
+
css_folder: string;
|
|
8
|
+
default: PackageConfig;
|
|
9
|
+
dependencies: Dependencies;
|
|
10
|
+
description?: string;
|
|
11
|
+
devDependencies: Dependencies;
|
|
12
|
+
es6Modules?: string[];
|
|
13
|
+
getPackageConfig: () => PackageConfig;
|
|
14
|
+
jsPath: string;
|
|
15
|
+
license?: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
packageDirectory: string;
|
|
18
|
+
packageManager?: string;
|
|
19
|
+
resolutions?: Dependencies;
|
|
20
|
+
scripts: Partial<Scripts>;
|
|
21
|
+
shortCssClasses: boolean;
|
|
22
|
+
url: string;
|
|
23
|
+
version?: string;
|
|
24
|
+
workingDirectory: string;
|
|
23
25
|
}
|
|
24
|
-
|
|
25
26
|
export interface Dependencies {
|
|
26
|
-
|
|
27
|
+
[name: string]: string;
|
|
27
28
|
}
|
|
28
|
-
|
|
29
29
|
export interface Certificates {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
cert: string;
|
|
31
|
+
key: string;
|
|
32
32
|
}
|
|
33
|
-
|
|
34
33
|
export interface Scripts {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
browserslist: string;
|
|
35
|
+
dist: string;
|
|
36
|
+
lint: string;
|
|
37
|
+
postinstall: string;
|
|
38
|
+
start: string;
|
|
39
|
+
test: string;
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Helper function to get the results of `packageConfig`.
|
|
43
|
+
*
|
|
44
|
+
* - Allows mocking the results of `packageConfig` for testing.
|
|
45
|
+
* - Allows getting the config through a callback instead of an import.
|
|
46
|
+
*
|
|
47
|
+
* @since 10.3.0
|
|
48
|
+
*/
|
|
49
|
+
export declare function getPackageConfig(): PackageConfig;
|
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty( exports, '__esModule', {value: true} );
|
|
3
|
+
exports.getPackageConfig = void 0;
|
|
4
|
+
const path_1 = require( 'path' );
|
|
5
|
+
const node_fs_1 = require( 'node:fs' );
|
|
6
|
+
const workingDirectory = ( 0, node_fs_1.realpathSync )( process.cwd() );
|
|
7
|
+
const defaults = {
|
|
8
|
+
brotliFiles: false,
|
|
9
|
+
es6Modules: [],
|
|
10
|
+
jsPath: '',
|
|
11
|
+
packageDirectory: workingDirectory,
|
|
12
|
+
url: 'http://localhost',
|
|
13
|
+
shortCssClasses: false,
|
|
14
|
+
cssTsFiles: false,
|
|
15
|
+
};
|
|
16
|
+
let packageConfig = require( ( 0, path_1.resolve )( workingDirectory, 'package.json' ) );
|
|
17
|
+
packageConfig = {...defaults, ...packageConfig};
|
|
18
|
+
packageConfig.workingDirectory = packageConfig.jsPath !== '' ? ( 0, path_1.resolve )( packageConfig.jsPath ) : workingDirectory;
|
|
17
19
|
try {
|
|
18
|
-
const localConfig = require(
|
|
20
|
+
const localConfig = require( ( 0, path_1.resolve )( workingDirectory, './local-config.json' ) );
|
|
19
21
|
packageConfig = {...packageConfig, ...localConfig};
|
|
20
22
|
} catch ( e ) {
|
|
21
23
|
}
|
|
22
|
-
|
|
23
24
|
/**
|
|
24
25
|
* Helper function to get the results of `packageConfig`.
|
|
25
26
|
*
|
|
@@ -31,6 +32,7 @@ try {
|
|
|
31
32
|
function getPackageConfig() {
|
|
32
33
|
return packageConfig;
|
|
33
34
|
}
|
|
35
|
+
exports.getPackageConfig = getPackageConfig;
|
|
34
36
|
packageConfig.getPackageConfig = getPackageConfig;
|
|
35
|
-
|
|
37
|
+
packageConfig.default = packageConfig;
|
|
36
38
|
module.exports = packageConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lipemat/js-boilerplate",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.8.0-beta.3",
|
|
4
4
|
"description": "Dependencies and scripts for a no config JavaScript app",
|
|
5
5
|
"author": "Mat Lipe",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"no-config"
|
|
24
24
|
],
|
|
25
25
|
"files": [
|
|
26
|
-
"tsconfig.json",
|
|
27
26
|
"bin/",
|
|
28
27
|
"config/",
|
|
29
28
|
"helpers/",
|
|
@@ -35,7 +34,10 @@
|
|
|
35
34
|
},
|
|
36
35
|
"scripts": {
|
|
37
36
|
"browserslist": "lipemat-js-boilerplate browserslist",
|
|
38
|
-
"
|
|
37
|
+
"build": "ts-node ./bin/build.ts",
|
|
38
|
+
"prepublishOnly": "yarn run build",
|
|
39
|
+
"test": "lipemat-js-boilerplate test",
|
|
40
|
+
"watch": "ts-node ./bin/watch.ts"
|
|
39
41
|
},
|
|
40
42
|
"dependencies": {
|
|
41
43
|
"@babel/core": "^7.4.3",
|
|
@@ -97,10 +99,11 @@
|
|
|
97
99
|
"devDependencies": {
|
|
98
100
|
"@types/jest": "^29.5.3",
|
|
99
101
|
"@types/minimist": "^1",
|
|
102
|
+
"chokidar": "^3.5.3",
|
|
100
103
|
"eslint": "^8",
|
|
101
104
|
"glob": "^10.3.3",
|
|
102
105
|
"memfs": "^3.5.3",
|
|
103
106
|
"setimmediate": "^1.0.5"
|
|
104
107
|
},
|
|
105
|
-
"packageManager": "yarn@4.0
|
|
108
|
+
"packageManager": "yarn@4.1.0"
|
|
106
109
|
}
|
package/scripts/lint.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {ESLint} from 'eslint';
|
|
|
2
2
|
import minimist from 'minimist';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import {getPackageConfig} from '../helpers/package-config';
|
|
6
6
|
|
|
7
7
|
// Command line arguments.
|
|
8
8
|
const flags = minimist( process.argv.slice( 2 ) );
|
|
@@ -35,7 +35,7 @@ function errorOccurred( results: ESLint.LintResult[] ): boolean {
|
|
|
35
35
|
|
|
36
36
|
// 2. Lint files. This doesn't modify target files.
|
|
37
37
|
const results: ESLint.LintResult[] = await eslint.lintFiles( [
|
|
38
|
-
|
|
38
|
+
getPackageConfig().workingDirectory + '/src/**/*.{js,jsx,ts,tsx}',
|
|
39
39
|
] );
|
|
40
40
|
|
|
41
41
|
// 3. Modify the files with the fixed code.
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./config/tsconfig.json",
|
|
3
|
-
"$schema": "https://json.schemastore.org/tsconfig",
|
|
4
|
-
"display": "JS Boilerplate",
|
|
5
|
-
"include": [
|
|
6
|
-
"bin/**/*",
|
|
7
|
-
"config/**/*",
|
|
8
|
-
"helpers/**/*",
|
|
9
|
-
"lib/**/*",
|
|
10
|
-
"jest/**/*",
|
|
11
|
-
"scripts/**/*"
|
|
12
|
-
],
|
|
13
|
-
"compilerOptions": {
|
|
14
|
-
"esModuleInterop": true,
|
|
15
|
-
"module": "CommonJS"
|
|
16
|
-
}
|
|
17
|
-
}
|