@lipemat/js-boilerplate 8.0.0-beta.3 → 8.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/README.md +10 -6
- package/bin/{lipemat-js-boilerplace.js → lipemat-js-boilerplate.js} +8 -8
- package/config/dev-server.config.js +15 -16
- package/config/webpack.dev.js +1 -3
- package/helpers/package-config.js +0 -2
- package/package.json +4 -3
- package/scripts/dist.js +0 -4
- package/scripts/start.js +0 -6
- package/scripts/test.js +1 -1
- package/helpers/revision.js +0 -31
package/README.md
CHANGED
|
@@ -26,7 +26,8 @@ Add the following to your package.json. (this may also be found in the `template
|
|
|
26
26
|
|
|
27
27
|
```json
|
|
28
28
|
{
|
|
29
|
-
"
|
|
29
|
+
"jsPath": "./js",
|
|
30
|
+
"themeUrlPath": "/wp-content/themes/core/",
|
|
30
31
|
"scripts": {
|
|
31
32
|
"browserslist": "lipemat-js-boilerplate browserslist",
|
|
32
33
|
"dist": "lipemat-js-boilerplate dist",
|
|
@@ -37,14 +38,16 @@ Add the following to your package.json. (this may also be found in the `template
|
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {},
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"@lipemat/js-boilerplate": "^
|
|
41
|
+
"@lipemat/js-boilerplate": "^8.0.0"
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
```
|
|
45
|
-
|
|
46
46
|
**_You may adjust things as needed but be sure to leave the `scripts` as is._**
|
|
47
47
|
|
|
48
|
+
* `jsPath`: Path of JS application relative to `package.json`. If `package.json` is in same directory as the JS application, this may be omitted.
|
|
49
|
+
* `themeUrlPath`: Path of `package.json` file relative to site's domain.
|
|
50
|
+
|
|
48
51
|
## Code Completion In PHPStorm
|
|
49
52
|
Some `@types` have been specified in this library to assist with code completion and allow using the built-in TypeScript support. Unfortunately, some typescripts still send errors to PHPStorm like "Default export is not declared in an imported module". I've found that it's easier to just remove this warning by un-checking `Editor -> Inspections -> JavaScript -> General -> Validate Imports`. (this may not need to be un-checked if you enable the built-in TypeScript support).
|
|
50
53
|
|
|
@@ -80,9 +83,11 @@ Babel will automatically compile TypeScript files into the finished javascript,
|
|
|
80
83
|
|
|
81
84
|
### Configuration Overrides
|
|
82
85
|
All configurations are found in the `config` directory and may be extended by adding a matching file within your project directory.
|
|
83
|
-
|
|
84
86
|
For instance is you want to adjust `webpack.dev.js` you may add a `config/webpack.dev.js` file in your project directory.
|
|
85
87
|
|
|
88
|
+
**@note** The `jsPath` will be taken into account so if you specified a `jsPath` the `config` directory must be placed
|
|
89
|
+
inside it. (e.g. `js/config/wepack.dev.js`).
|
|
90
|
+
|
|
86
91
|
All declarations are merged in favor of the project config.
|
|
87
92
|
|
|
88
93
|
### Extensions
|
|
@@ -125,7 +130,7 @@ An alternative/extra location is `../pcss/globals/variables.css`.
|
|
|
125
130
|
The app will automatically detect any packages in your `package.json` which do not support ES5 and add them to the list
|
|
126
131
|
of files that Babel will transform into ES5 code.
|
|
127
132
|
|
|
128
|
-
If you have a package which has a dependency which does not support ES5, you will need to add it to a `es6Modules` key
|
|
133
|
+
If you have a package, which has a dependency, which does not support ES5, you will need to add it to a `es6Modules` key
|
|
129
134
|
in your `package.json` to have it transformed.
|
|
130
135
|
|
|
131
136
|
**Example**
|
|
@@ -149,4 +154,3 @@ If you are using https in your local environment, you may point to the certifica
|
|
|
149
154
|
}
|
|
150
155
|
}
|
|
151
156
|
```
|
|
152
|
-
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
// Update notifier.
|
|
5
5
|
const updateNotifier = require( 'update-notifier' );
|
|
6
6
|
const pkg = require( '../package.json' );
|
|
7
|
-
updateNotifier( {
|
|
7
|
+
updateNotifier( {pkg, shouldNotifyInNpmScript: true} ).notify();
|
|
8
8
|
|
|
9
9
|
const spawn = require( 'cross-spawn' );
|
|
10
10
|
const args = process.argv.slice( 2 );
|
|
11
11
|
|
|
12
12
|
const scriptIndex = args.findIndex(
|
|
13
|
-
x =>
|
|
13
|
+
x => 'browserslist' === x || 'start' === x || 'dist' === x || 'test' === x || 'lint' === x || 'fix-pnp' === x,
|
|
14
14
|
);
|
|
15
|
-
const script =
|
|
15
|
+
const script = -1 === scriptIndex ? args[ 0 ] : args[ scriptIndex ];
|
|
16
16
|
const nodeArgs = scriptIndex > 0 ? args.slice( 0, scriptIndex ) : [];
|
|
17
17
|
|
|
18
18
|
switch ( script ) {
|
|
@@ -27,20 +27,20 @@ switch ( script ) {
|
|
|
27
27
|
nodeArgs
|
|
28
28
|
.concat( require.resolve( '../scripts/' + script ) )
|
|
29
29
|
.concat( args.slice( scriptIndex + 1 ) ),
|
|
30
|
-
{
|
|
30
|
+
{stdio: 'inherit'},
|
|
31
31
|
);
|
|
32
32
|
if ( result.signal ) {
|
|
33
|
-
if ( result.signal
|
|
33
|
+
if ( 'SIGKILL' === result.signal ) {
|
|
34
34
|
console.log(
|
|
35
35
|
'The build failed because the process exited too early. ' +
|
|
36
36
|
'This probably means the system ran out of memory or someone called ' +
|
|
37
|
-
'`kill -9` on the process.'
|
|
37
|
+
'`kill -9` on the process.',
|
|
38
38
|
);
|
|
39
|
-
} else if ( result.signal
|
|
39
|
+
} else if ( 'SIGTERM' === result.signal ) {
|
|
40
40
|
console.log(
|
|
41
41
|
'The build failed because the process exited too early. ' +
|
|
42
42
|
'Someone might have called `kill` or `killall`, or the system could ' +
|
|
43
|
-
'be shutting down.'
|
|
43
|
+
'be shutting down.',
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
process.exit( 1 );
|
|
@@ -1,38 +1,37 @@
|
|
|
1
1
|
const fs = require( 'fs' );
|
|
2
|
-
const configHelper = require( '../helpers/config' );
|
|
3
|
-
const webpackConfig = configHelper.getConfig( 'webpack.dev.js' );
|
|
4
2
|
const packageConfig = require( '../helpers/package-config' );
|
|
5
3
|
|
|
6
4
|
const url = new URL( packageConfig.url );
|
|
7
5
|
|
|
8
|
-
let
|
|
6
|
+
let server = 'https:' === url.protocol ? 'https' : 'http';
|
|
9
7
|
// Load local certificates for https during development.
|
|
10
8
|
if ( 'object' === typeof ( packageConfig.certificates ) ) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
server = {
|
|
10
|
+
type: 'https',
|
|
11
|
+
options: {
|
|
12
|
+
cert: fs.readFileSync( packageConfig.certificates.cert ),
|
|
13
|
+
key: fs.readFileSync( packageConfig.certificates.key ),
|
|
14
|
+
},
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
module.exports = {
|
|
18
19
|
allowedHosts: 'all',
|
|
19
20
|
client: {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
logging: 'warn',
|
|
22
|
+
overlay: {
|
|
23
|
+
errors: true,
|
|
24
|
+
warnings: false,
|
|
23
25
|
},
|
|
24
26
|
},
|
|
25
|
-
compress: false,
|
|
26
|
-
host: '0.0.0.0', // Allow connections from outside localhost to support mobile debugging
|
|
27
|
-
hot: true,
|
|
28
|
-
https,
|
|
29
|
-
historyApiFallback: true,
|
|
30
27
|
headers: {
|
|
31
28
|
'Access-Control-Allow-Origin': '*',
|
|
32
29
|
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
|
33
30
|
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
|
|
34
31
|
},
|
|
32
|
+
host: '0.0.0.0', // Allow connections from any IP.
|
|
33
|
+
hot: true,
|
|
35
34
|
port: 3000,
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
server,
|
|
36
|
+
static: false,
|
|
38
37
|
};
|
package/config/webpack.dev.js
CHANGED
|
@@ -33,8 +33,6 @@ if ( configHelper.hasLocalOverride( 'tsconfig.json', true ) ) {
|
|
|
33
33
|
|
|
34
34
|
const entry = {
|
|
35
35
|
master: [
|
|
36
|
-
'webpack-dev-server/client?' + config.url + ':3000',
|
|
37
|
-
'webpack/hot/only-dev-server',
|
|
38
36
|
config.workingDirectory + '/src/index.js',
|
|
39
37
|
],
|
|
40
38
|
};
|
|
@@ -46,7 +44,7 @@ if ( fs.existsSync( path.resolve( config.workingDirectory, 'src/admin.js' ) ) )
|
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
module.exports = {
|
|
49
|
-
devtool: 'eval-
|
|
47
|
+
devtool: 'eval-source-map',
|
|
50
48
|
entry,
|
|
51
49
|
mode: 'development',
|
|
52
50
|
stats: 'minimal',
|
|
@@ -9,8 +9,6 @@ let packageConfig = require( path.resolve( workingDirectory, 'package.json' ) );
|
|
|
9
9
|
packageConfig.workingDirectory = packageConfig.jsPath ? path.resolve( packageConfig.jsPath ) : workingDirectory;
|
|
10
10
|
packageConfig.themeUrlPath = packageConfig.themeUrlPath || '/';
|
|
11
11
|
packageConfig.url = packageConfig.url || 'http://localhost';
|
|
12
|
-
packageConfig.root = packageConfig.root || './';
|
|
13
|
-
packageConfig.regenerate_revision = packageConfig.regenerate_revision || false;
|
|
14
12
|
packageConfig.es6Modules = packageConfig.es6Modules || [];
|
|
15
13
|
|
|
16
14
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lipemat/js-boilerplate",
|
|
3
|
-
"version": "8.0.0
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Dependencies and scripts for a no config JavaScript app",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=14.17.6"
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"scripts/"
|
|
24
24
|
],
|
|
25
25
|
"bin": {
|
|
26
|
-
"lipemat-js-boilerplate": "
|
|
26
|
+
"lipemat-js-boilerplate": "bin/lipemat-js-boilerplate.js"
|
|
27
27
|
},
|
|
28
28
|
"author": "Mat Lipe",
|
|
29
29
|
"license": "MIT",
|
|
@@ -85,5 +85,6 @@
|
|
|
85
85
|
"bugs": {
|
|
86
86
|
"url": "https://github.com/lipemat/js-boilerplate/issues"
|
|
87
87
|
},
|
|
88
|
-
"homepage": "https://github.com/lipemat/js-boilerplate#readme"
|
|
88
|
+
"homepage": "https://github.com/lipemat/js-boilerplate#readme",
|
|
89
|
+
"packageManager": "yarn@3.1.1"
|
|
89
90
|
}
|
package/scripts/dist.js
CHANGED
|
@@ -3,7 +3,6 @@ process.env.NODE_ENV = 'production';
|
|
|
3
3
|
|
|
4
4
|
const webpack = require( 'webpack' );
|
|
5
5
|
const webpackConfig = require( '../helpers/config' ).getConfig( 'webpack.dist.js' );
|
|
6
|
-
const updateRevisionFile = require( '../helpers/revision' ).updateRevisionFile;
|
|
7
6
|
|
|
8
7
|
async function build( config ) {
|
|
9
8
|
// Compiler Instance.
|
|
@@ -23,11 +22,8 @@ async function build( config ) {
|
|
|
23
22
|
} else {
|
|
24
23
|
console.log( stats.toString( config.stats ) );
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
updateRevisionFile();
|
|
28
25
|
} );
|
|
29
26
|
}
|
|
30
27
|
|
|
31
28
|
|
|
32
29
|
build( webpackConfig );
|
|
33
|
-
|
package/scripts/start.js
CHANGED
|
@@ -15,10 +15,4 @@ const server = new WebpackDevServer( devServerConfig, webpack( webpackConfig ) )
|
|
|
15
15
|
} catch ( err ) {
|
|
16
16
|
return console.log( err );
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
if ( devServerConfig.https ) {
|
|
20
|
-
console.log( `Listening at https://${devServerConfig.host}:${devServerConfig.port}/` );
|
|
21
|
-
} else {
|
|
22
|
-
console.log( `Listening at http://${devServerConfig.host}:${devServerConfig.port}/` );
|
|
23
|
-
}
|
|
24
18
|
} )();
|
package/scripts/test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Runs `jest` with any arguments passed via the terminal or yarn.
|
|
3
3
|
*
|
|
4
|
-
* @notice you must add `/templates/jest.config.js` to the
|
|
4
|
+
* @notice you must add `/templates/jest.config.js` to the `jsPath` of your project.
|
|
5
5
|
*
|
|
6
6
|
* @example `lipemat-js-boilerplate test`
|
|
7
7
|
*/
|
package/helpers/revision.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const fs = require( 'fs' );
|
|
2
|
-
const path = require( 'path' );
|
|
3
|
-
const packageConfig = require( '../helpers/package-config' );
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Bump the .revision file to the current timestamp.
|
|
7
|
-
*
|
|
8
|
-
* Useful when PWA is active because Chrome will get the old service worker
|
|
9
|
-
* cached resources unless we bump the revision.
|
|
10
|
-
* Also helps with sha integrity issues on developing locally.
|
|
11
|
-
*
|
|
12
|
-
* If not using PWA and using another form of .revision generation such as
|
|
13
|
-
* Beanstalk or a deploy script, it's probably better to disable this so you
|
|
14
|
-
* can match the git hash to the .revision file.
|
|
15
|
-
*
|
|
16
|
-
* May be enabled by adding "regenerate_revision":true to your package.json.
|
|
17
|
-
*/
|
|
18
|
-
function updateRevisionFile() {
|
|
19
|
-
if ( packageConfig.regenerate_revision && packageConfig.root ) {
|
|
20
|
-
fs.writeFile( path.resolve( packageConfig.root, '.revision' ), Date.now(), err => {
|
|
21
|
-
if ( err ) {
|
|
22
|
-
throw err;
|
|
23
|
-
}
|
|
24
|
-
console.log( '\n', 'Generated .revision file', '\n' );
|
|
25
|
-
} );
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = {
|
|
30
|
-
updateRevisionFile
|
|
31
|
-
}
|