@lipemat/js-boilerplate 10.6.0-beta.2 → 10.6.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.
|
@@ -19,6 +19,7 @@ const nodeArgs = scriptIndex > 0 ? args.slice( 0, scriptIndex ) : [];
|
|
|
19
19
|
const TS_CONVERTED_SCRIPTS = [
|
|
20
20
|
'test',
|
|
21
21
|
'lint',
|
|
22
|
+
'validate-css-modules',
|
|
22
23
|
];
|
|
23
24
|
|
|
24
25
|
switch ( script ) {
|
|
@@ -27,7 +28,8 @@ switch ( script ) {
|
|
|
27
28
|
case 'fix-pnp':
|
|
28
29
|
case 'lint':
|
|
29
30
|
case 'start':
|
|
30
|
-
case 'test':
|
|
31
|
+
case 'test':
|
|
32
|
+
case 'validate-css-modules': {
|
|
31
33
|
// If the ts-node command is not available install it globally.
|
|
32
34
|
if ( spawn.sync( 'ts-node', [ '-v' ] ).error ) {
|
|
33
35
|
console.log( 'Installing ts-node globally.' );
|
package/config/webpack.dist.js
CHANGED
|
@@ -12,6 +12,7 @@ const {getConfig, getTsConfigFile, getBrowsersList} = require( '../helpers/confi
|
|
|
12
12
|
const moduleHelpers = require( '../helpers/modules' );
|
|
13
13
|
const config = require( '../helpers/package-config' );
|
|
14
14
|
const {getEntries} = require( '../helpers/entries' );
|
|
15
|
+
const {getPackageConfig} = require( '../helpers/package-config' );
|
|
15
16
|
|
|
16
17
|
const postcssOptions = getConfig( 'postcss.config.js' );
|
|
17
18
|
const babelOptions = getConfig( 'babel.config.js' );
|
|
@@ -135,6 +136,13 @@ module.exports = {
|
|
|
135
136
|
test: /\.pcss$/,
|
|
136
137
|
use: [
|
|
137
138
|
MiniCssExtractPlugin.loader,
|
|
139
|
+
{
|
|
140
|
+
loader: '@teamsupercell/typings-for-css-modules-loader',
|
|
141
|
+
options: {
|
|
142
|
+
disableLocalsExport: true,
|
|
143
|
+
prettierConfigFile: path.resolve( __dirname, '../helpers/.prettierrc.json' ),
|
|
144
|
+
},
|
|
145
|
+
},
|
|
138
146
|
{
|
|
139
147
|
loader: 'css-loader',
|
|
140
148
|
options: cssLoaderOptions,
|
|
@@ -145,7 +153,12 @@ module.exports = {
|
|
|
145
153
|
postcssOptions,
|
|
146
154
|
},
|
|
147
155
|
},
|
|
148
|
-
]
|
|
156
|
+
].filter( loader => {
|
|
157
|
+
if ( ! getPackageConfig().cssTsFiles ) {
|
|
158
|
+
return loader.loader !== '@teamsupercell/typings-for-css-modules-loader';
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
} ),
|
|
149
162
|
},
|
|
150
163
|
],
|
|
151
164
|
},
|
package/package.json
CHANGED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import webpack from 'webpack';
|
|
2
|
+
import {getConfig} from '../helpers/config.js';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
const help = `
|
|
6
|
+
Validate CSS modules using .d.ts definition files for each CSS module.
|
|
7
|
+
|
|
8
|
+
- Generates .d.ts files for each CSS module.
|
|
9
|
+
- Runs \`dist\` to validate compilation using TS.
|
|
10
|
+
|
|
11
|
+
@notice PHPStorm will not support click through to CSS modules if the .pcss.d.ts files are present so this script should only be run in CI.
|
|
12
|
+
|
|
13
|
+
@see .github/workflows/pull-request-lint-action.yml
|
|
14
|
+
|
|
15
|
+
Usage: lipemat-js-boilerplate validate-css-modules
|
|
16
|
+
|
|
17
|
+
--help, -h Show help menu.`;
|
|
18
|
+
|
|
19
|
+
const args = process.argv.slice( 3 );
|
|
20
|
+
if ( '-h' === args[ 0 ] || '--help' === args[ 0 ] ) {
|
|
21
|
+
console.log( help );
|
|
22
|
+
process.exit( 0 );
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function validate() {
|
|
26
|
+
let webpackConfig: webpack.Configuration = getConfig( 'webpack.dist.js' );
|
|
27
|
+
webpackConfig.stats = 'errors-warnings';
|
|
28
|
+
|
|
29
|
+
// Add CSS module typings generation to webpack config.
|
|
30
|
+
webpackConfig.module?.rules?.map( ( rule: webpack.RuleSetRule ) => {
|
|
31
|
+
if ( rule.test?.toString() === /\.pcss$/.toString() ) {
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
rule.use?.splice( 1, 0, {
|
|
34
|
+
loader: '@teamsupercell/typings-for-css-modules-loader',
|
|
35
|
+
options: {
|
|
36
|
+
disableLocalsExport: true,
|
|
37
|
+
prettierConfigFile: path.resolve( __dirname, '../helpers/.prettierrc.json' ),
|
|
38
|
+
},
|
|
39
|
+
} )
|
|
40
|
+
}
|
|
41
|
+
return rule;
|
|
42
|
+
} )
|
|
43
|
+
|
|
44
|
+
// Wait for generation to finish before continuing.
|
|
45
|
+
await new Promise( ( resolve, reject ) => {
|
|
46
|
+
webpack( webpackConfig ).run( ( err, stats ) => {
|
|
47
|
+
if ( err ) {
|
|
48
|
+
reject( err );
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if ( stats && stats.hasErrors() ) {
|
|
52
|
+
console.error( stats.toString( webpackConfig.stats ) );
|
|
53
|
+
process.exit( 1 );
|
|
54
|
+
}
|
|
55
|
+
resolve( stats );
|
|
56
|
+
} );
|
|
57
|
+
} );
|
|
58
|
+
|
|
59
|
+
console.log( '>>> CSS Module definitions generated.' );
|
|
60
|
+
|
|
61
|
+
// A fresh config for CSS validation.
|
|
62
|
+
webpackConfig = getConfig( 'webpack.dist.js' );
|
|
63
|
+
webpackConfig.stats = 'errors-warnings';
|
|
64
|
+
webpack( webpackConfig ).run( ( err, stats ) => {
|
|
65
|
+
if ( err ) {
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if ( stats && stats.hasErrors() ) {
|
|
70
|
+
console.error( stats.toString( webpackConfig.stats ) );
|
|
71
|
+
process.exit( 1 );
|
|
72
|
+
}
|
|
73
|
+
console.log( '>>> CSS validation completed.' );
|
|
74
|
+
} );
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
validate();
|