@imtf/profile-scripts 1.0.7 → 1.1.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.
@@ -1,36 +1,30 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const concurrently = require('concurrently')
4
- const spawn = require('cross-spawn')
3
+ const concurrently = require('concurrently');
4
+ const spawn = require('cross-spawn');
5
5
 
6
- const args = process.argv.slice(2)
7
- const scriptIndex = args.findIndex(x => x === 'build' || x === 'start')
8
- const script = scriptIndex === -1 ? args[0] : args[scriptIndex]
6
+ const args = process.argv.slice(2);
7
+ const scriptIndex = args.findIndex((x) => x === 'build' || x === 'start');
8
+ const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
9
9
 
10
- const scriptPath = require.resolve(`../scripts/esbuild.mjs`)
10
+ const scriptPath = require.resolve(`../scripts/esbuild.mjs`);
11
11
 
12
12
  switch (script) {
13
- case 'start': {
14
- concurrently([
15
- {
16
- command: `node ${scriptPath} --watch`,
17
- name: 'watch',
18
- cwd: undefined,
19
- },
20
- { command: 'serve build -l 3010', name: 'serve' },
21
- ])
22
-
23
- break
24
- }
13
+ case 'start':
25
14
  case 'build': {
26
- const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []
27
- const scriptArgs = args.slice(scriptIndex + 1)
28
- const processArgs = nodeArgs.concat(scriptPath).concat(scriptArgs)
15
+ const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
16
+ const scriptArgs = args.slice(scriptIndex + 1);
17
+
18
+ if (script === 'start') {
19
+ scriptArgs.push('--watch');
20
+ }
21
+
22
+ const processArgs = nodeArgs.concat(scriptPath).concat(scriptArgs);
29
23
 
30
24
  const child = spawn.sync('node', processArgs, {
31
25
  stdio: 'inherit',
32
26
  env: { ...process.env, NODE_ENV: 'production' },
33
- })
27
+ });
34
28
 
35
29
  if (child.signal) {
36
30
  if (child.signal === 'SIGKILL') {
@@ -38,21 +32,21 @@ switch (script) {
38
32
  The build failed because the process exited too early.
39
33
  This probably means the system ran out of memory or someone called
40
34
  \`kill -9\` on the process.
41
- `)
35
+ `);
42
36
  } else if (child.signal === 'SIGTERM') {
43
37
  console.log(`
44
38
  The build failed because the process exited too early.
45
39
  Someone might have called \`kill\` or \`killall\`, or the system could
46
40
  be shutting down.
47
- `)
41
+ `);
48
42
  }
49
43
 
50
- process.exit(1)
44
+ process.exit(1);
51
45
  }
52
46
 
53
- break
47
+ break;
54
48
  }
55
49
  default:
56
- console.log(`Unknown script "${script}".`)
57
- break
50
+ console.log(`Unknown script "${script}".`);
51
+ break;
58
52
  }
package/changelog.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  Here you can find a resume of all changes between versions.
4
4
 
5
+ ## 1.1.0
6
+
7
+ ### Features
8
+
9
+ - Upgraded dependencies
10
+ - Use new ESBuild 0.17 APIs for dev watch & rebuild
11
+ - Properly build TS files
12
+
5
13
  ## 1.0.7
6
14
 
7
15
  ### Features
@@ -25,9 +33,9 @@ Here you can find a resume of all changes between versions.
25
33
  ### Features
26
34
 
27
35
  - Use differents loaders for svgs :
28
- * Svgs part of /src except ones that are in /src/assets will be
29
- loaded as React components with svgr.
30
- * Others will be loaded as dataurl (base64)
36
+ - Svgs part of /src except ones that are in /src/assets will be
37
+ loaded as React components with svgr.
38
+ - Others will be loaded as dataurl (base64)
31
39
 
32
40
  ## 1.0.3
33
41
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imtf/profile-scripts",
3
- "version": "1.0.7",
3
+ "version": "1.1.0",
4
4
  "description": "Default scripts to bundle & transpile imtf front-end plugins",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -13,9 +13,7 @@
13
13
  ],
14
14
  "scripts": {
15
15
  "build": "NODE_ENV=production node scripts/esbuild.mjs",
16
- "watch": "node scripts/esbuild.mjs --watch",
17
- "serve": "serve build -l 3010",
18
- "start": "concurrently yarn:watch yarn:serve"
16
+ "start": "node scripts/esbuild.mjs --watch"
19
17
  },
20
18
  "eslintConfig": {
21
19
  "extends": "@imtf/eslint-config-react"
@@ -25,16 +23,16 @@
25
23
  "license": "UNLICENSED",
26
24
  "private": false,
27
25
  "dependencies": {
28
- "@svgr/core": "^6.2.0",
29
- "@svgr/plugin-jsx": "^6.2.0",
30
- "@svgr/plugin-svgo": "^6.2.0",
31
- "concurrently": "^7.0.0",
32
- "esbuild": "^0.14.8",
26
+ "@svgr/core": "^7.0.0",
27
+ "@svgr/plugin-jsx": "^7.0.0",
28
+ "@svgr/plugin-svgo": "^7.0.0",
29
+ "concurrently": "^8.0.1",
30
+ "esbuild": "^0.17.16",
33
31
  "esbuild-plugin-external-global": "^1.0.1",
34
- "serve": "^13.0.2"
32
+ "serve": "^14.1.2"
35
33
  },
36
34
  "devDependencies": {
37
35
  "@imtf/eslint-config-react": "^1.0.0",
38
- "@imtf/prettier-config": "^1.0.0"
36
+ "@imtf/prettier-config": "^2.0.0"
39
37
  }
40
38
  }
@@ -1,35 +1,35 @@
1
- import { build } from 'esbuild'
2
- import externalGlobalPlugin from 'esbuild-plugin-external-global'
3
- import minimist from 'minimist'
1
+ import { context, build } from 'esbuild';
2
+ import externalGlobalPlugin from 'esbuild-plugin-external-global';
3
+ import minimist from 'minimist';
4
4
 
5
- import svgPlugin from './svgPlugin.mjs'
5
+ import notifierPlugin from './notifierPlugin.mjs';
6
+ import svgPlugin from './svgPlugin.mjs';
6
7
 
7
- const { watch } = minimist(process.argv.slice(2))
8
+ const { watch, entryPoint } = minimist(process.argv.slice(2));
8
9
 
9
- build({
10
- entryPoints: ['src/index.js'],
11
- // outfile: 'build/index.js',
10
+ const entryPoints = entryPoint
11
+ ? typeof entryPoint === 'string'
12
+ ? [entryPoint]
13
+ : entryPoint
14
+ : ['src/index.js'];
15
+
16
+ /**
17
+ * @type {import('esbuild').BuildOptions}
18
+ */
19
+ const config = {
20
+ entryPoints,
12
21
  outdir: 'build',
13
22
  platform: 'browser',
14
23
  bundle: true,
15
- target: 'es6',
16
-
17
- watch: watch
18
- ? {
19
- onRebuild(error, result) {
20
- if (!error) {
21
- console.log(`Rebuilt: ${new Date().getTime()}`)
22
- }
23
- },
24
- }
25
- : false,
24
+ target: 'es2020',
26
25
 
27
26
  minify:
28
27
  process.env.NODE_ENV === 'production' &&
29
28
  process.env.IMTF_MINIFY_WEBAPP !== 'false',
29
+
30
30
  loader: {
31
- // Enable JSX in .js files too
32
31
  '.css': 'text',
32
+ // Enable JSX in .js files too
33
33
  '.js': 'jsx',
34
34
  // Embed fonts
35
35
  '.eot': 'dataurl',
@@ -41,6 +41,7 @@ build({
41
41
  '.jpg': 'dataurl',
42
42
  '.png': 'dataurl',
43
43
  },
44
+
44
45
  plugins: [
45
46
  svgPlugin(),
46
47
  externalGlobalPlugin.externalGlobalPlugin({
@@ -49,5 +50,20 @@ build({
49
50
  'react-router-dom': 'window.reactRouterDom',
50
51
  IMTFPlugins: 'window.IMTFPlugins',
51
52
  }),
53
+ notifierPlugin(),
52
54
  ],
53
- })
55
+ };
56
+
57
+ if (watch) {
58
+ const ctx = await context(config);
59
+
60
+ // Enable watch mode
61
+ await ctx.watch();
62
+
63
+ // Enable serve mode
64
+ await ctx.serve({
65
+ port: 3010,
66
+ });
67
+ } else {
68
+ build(config);
69
+ }
@@ -0,0 +1,20 @@
1
+ const notifierPlugin = (options = {}) => ({
2
+ name: 'svgr',
3
+ setup(build) {
4
+ let count = 0
5
+
6
+ build.onEnd(result => {
7
+ if (result.errors.length > 0) {
8
+ return
9
+ }
10
+
11
+ if (count++ === 0) {
12
+ console.log(`1st build: ${new Date().getTime()}`)
13
+ } else {
14
+ console.log(`Rebuilt: ${new Date().getTime()}`)
15
+ }
16
+ })
17
+ },
18
+ })
19
+
20
+ export default notifierPlugin