@lipemat/js-boilerplate 8.0.0-beta.4 → 8.0.1

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 CHANGED
@@ -15,18 +15,13 @@ A zero configuration starting point for a React or non React app.
15
15
  yarn add @lipemat/js-boilerplate
16
16
  ```
17
17
 
18
- ## Version 7
19
-
20
- **Version 7 has some backward incompatibilities and should be updated with focus and thoroughness.**
21
-
22
- [Migration instructions are here.](https://github.com/lipemat/js-boilerplate/wiki/Version-7-Migration)
23
-
24
18
  ## Usage
25
19
  Add the following to your package.json. (this may also be found in the `templates` directory.
26
20
 
27
21
  ```json
28
22
  {
29
- "theme_path": "/wp-content/themes/core/",
23
+ "jsPath": "./js",
24
+ "themeUrlPath": "/wp-content/themes/core/",
30
25
  "scripts": {
31
26
  "browserslist": "lipemat-js-boilerplate browserslist",
32
27
  "dist": "lipemat-js-boilerplate dist",
@@ -37,14 +32,16 @@ Add the following to your package.json. (this may also be found in the `template
37
32
  },
38
33
  "devDependencies": {},
39
34
  "dependencies": {
40
- "@lipemat/js-boilerplate": "^5.6.0"
35
+ "@lipemat/js-boilerplate": "^8.0.0"
41
36
  }
42
37
  }
43
38
 
44
39
  ```
45
-
46
40
  **_You may adjust things as needed but be sure to leave the `scripts` as is._**
47
41
 
42
+ * `jsPath`: Path of JS application relative to `package.json`. If `package.json` is in same directory as the JS application, this may be omitted.
43
+ * `themeUrlPath`: Path of `package.json` file relative to site's domain.
44
+
48
45
  ## Code Completion In PHPStorm
49
46
  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
47
 
@@ -80,7 +77,6 @@ Babel will automatically compile TypeScript files into the finished javascript,
80
77
 
81
78
  ### Configuration Overrides
82
79
  All configurations are found in the `config` directory and may be extended by adding a matching file within your project directory.
83
-
84
80
  For instance is you want to adjust `webpack.dev.js` you may add a `config/webpack.dev.js` file in your project directory.
85
81
 
86
82
  All declarations are merged in favor of the project config.
@@ -125,7 +121,7 @@ An alternative/extra location is `../pcss/globals/variables.css`.
125
121
  The app will automatically detect any packages in your `package.json` which do not support ES5 and add them to the list
126
122
  of files that Babel will transform into ES5 code.
127
123
 
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
124
+ 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
125
  in your `package.json` to have it transformed.
130
126
 
131
127
  **Example**
@@ -149,4 +145,3 @@ If you are using https in your local environment, you may point to the certifica
149
145
  }
150
146
  }
151
147
  ```
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( { pkg, shouldNotifyInNpmScript:true } ).notify();
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 => x === 'browserslist' || x === 'start' || x === 'dist' || x === 'test' || x === 'lint' || x === 'fix-pnp'
13
+ x => 'browserslist' === x || 'start' === x || 'dist' === x || 'test' === x || 'lint' === x || 'fix-pnp' === x,
14
14
  );
15
- const script = scriptIndex === -1 ? args[ 0 ] : args[ scriptIndex ];
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
- { stdio: 'inherit' }
30
+ {stdio: 'inherit'},
31
31
  );
32
32
  if ( result.signal ) {
33
- if ( result.signal === 'SIGKILL' ) {
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 === 'SIGTERM' ) {
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 );
@@ -3,26 +3,35 @@ const packageConfig = require( '../helpers/package-config' );
3
3
 
4
4
  const url = new URL( packageConfig.url );
5
5
 
6
- let https = 'https:' === url.protocol;
6
+ let server = 'https:' === url.protocol ? 'https' : 'http';
7
7
  // Load local certificates for https during development.
8
8
  if ( 'object' === typeof ( packageConfig.certificates ) ) {
9
- https = {
10
- cert: fs.readFileSync( packageConfig.certificates.cert ),
11
- key: fs.readFileSync( packageConfig.certificates.key ),
9
+ server = {
10
+ type: 'https',
11
+ options: {
12
+ cert: fs.readFileSync( packageConfig.certificates.cert ),
13
+ key: fs.readFileSync( packageConfig.certificates.key ),
14
+ },
12
15
  };
13
16
  }
14
17
 
15
18
  module.exports = {
16
19
  allowedHosts: 'all',
17
- compress: false,
18
- host: url.hostname,
19
- hot: true,
20
- https,
20
+ client: {
21
+ logging: 'warn',
22
+ overlay: {
23
+ errors: true,
24
+ warnings: false,
25
+ },
26
+ },
21
27
  headers: {
22
28
  'Access-Control-Allow-Origin': '*',
23
29
  'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
24
30
  'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
25
31
  },
32
+ host: '0.0.0.0', // Allow connections from any IP.
33
+ hot: true,
26
34
  port: 3000,
35
+ server,
27
36
  static: false,
28
37
  };
@@ -17,7 +17,7 @@ const plugins = [
17
17
  } ),
18
18
  ];
19
19
 
20
- // Loads a thread which verifies any TypeScripts on changes.
20
+ // Loads a thread, which verifies any TypeScripts on changes.
21
21
  // Only use this if the project has a tsconfig.json file.
22
22
  if ( configHelper.hasLocalOverride( 'tsconfig.json', true ) ) {
23
23
  plugins.push( new ForkTsCheckerWebpackPlugin( {
@@ -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-cheap-module-source-map',
47
+ devtool: 'eval-source-map',
50
48
  entry,
51
49
  mode: 'development',
52
50
  stats: 'minimal',
package/helpers/config.js CHANGED
@@ -8,19 +8,19 @@ const extensions = Object.keys( packageConfig.dependencies ).filter( name => nam
8
8
  /**
9
9
  * Check to see if a local config file exists.
10
10
  *
11
- * @param {string} $fileName
12
- * @param {boolean} $inRoot - Look in the root their project directory instead of their /config directory
11
+ * @param {string} fileName
12
+ * @param {boolean} inWorkingDirectory - Look in working directory instead of their /config directory
13
13
  *
14
14
  * @return {boolean}
15
15
  */
16
- function hasLocalOverride( $fileName, $inRoot = false ) {
16
+ function hasLocalOverride( fileName, inWorkingDirectory = false ) {
17
17
  let hasLocal = false;
18
18
  try {
19
- if ( $inRoot ) {
20
- require( path.resolve( packageConfig.workingDirectory, $fileName ) );
19
+ if ( inWorkingDirectory ) {
20
+ require( path.resolve( packageConfig.workingDirectory, fileName ) );
21
21
  hasLocal = true;
22
22
  } else {
23
- require( path.resolve( packageConfig.workingDirectory + '/config', $fileName ) );
23
+ require( path.resolve( packageConfig.packageDirectory + '/config', fileName ) );
24
24
  hasLocal = true;
25
25
  }
26
26
  } catch ( e ) {
@@ -44,7 +44,7 @@ function hasLocalOverride( $fileName, $inRoot = false ) {
44
44
  function getConfig( $fileName ) {
45
45
  let config = {...require( '../config/' + $fileName ), ...getExtensionsConfig( $fileName )};
46
46
  try {
47
- const localConfig = require( path.resolve( packageConfig.workingDirectory + '/config', $fileName ) );
47
+ const localConfig = require( path.resolve( packageConfig.packageDirectory + '/config', $fileName ) );
48
48
  config = {...config, ...localConfig};
49
49
  } catch ( e ) {
50
50
  }
@@ -52,8 +52,8 @@ function getConfig( $fileName ) {
52
52
  }
53
53
 
54
54
  /**
55
- * Get a config from any existing extension's /config directory's
56
- * merged together into one.
55
+ * Get a config from any existing extension's /config directories
56
+ * merged into one.
57
57
  *
58
58
  * @param {string} $fileName
59
59
  *
@@ -6,12 +6,13 @@ const fs = require( 'fs' );
6
6
  const workingDirectory = fs.realpathSync( process.cwd() );
7
7
 
8
8
  let packageConfig = require( path.resolve( workingDirectory, 'package.json' ) );
9
- packageConfig.workingDirectory = packageConfig.jsPath ? path.resolve( packageConfig.jsPath ) : workingDirectory;
9
+ packageConfig.es6Modules = packageConfig.es6Modules || [];
10
+ // Path of the package.json file (root).
11
+ packageConfig.packageDirectory = workingDirectory;
10
12
  packageConfig.themeUrlPath = packageConfig.themeUrlPath || '/';
11
13
  packageConfig.url = packageConfig.url || 'http://localhost';
12
- packageConfig.root = packageConfig.root || './';
13
- packageConfig.regenerate_revision = packageConfig.regenerate_revision || false;
14
- packageConfig.es6Modules = packageConfig.es6Modules || [];
14
+ // Path of JS application files.
15
+ packageConfig.workingDirectory = packageConfig.jsPath ? path.resolve( packageConfig.jsPath ) : workingDirectory;
15
16
 
16
17
  try {
17
18
  const localConfig = require( path.resolve( workingDirectory, './local-config.json' ) );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lipemat/js-boilerplate",
3
- "version": "8.0.0-beta.4",
3
+ "version": "8.0.1",
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": "./bin/lipemat-js-boilerplace.js"
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/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 root of your project.
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
  */
@@ -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
- }