@imtf/profile-scripts 1.0.8 → 1.1.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.
@@ -1,58 +1,52 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const concurrently = require('concurrently')
4
- const spawn = require('cross-spawn')
3
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
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
- }
25
- 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)
13
+ case "start":
14
+ case "build": {
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
- const child = spawn.sync('node', processArgs, {
31
- stdio: 'inherit',
32
- env: { ...process.env, NODE_ENV: 'production' },
33
- })
24
+ const child = spawn.sync("node", processArgs, {
25
+ stdio: "inherit",
26
+ env: { ...process.env, NODE_ENV: "production" },
27
+ });
34
28
 
35
29
  if (child.signal) {
36
- if (child.signal === 'SIGKILL') {
30
+ if (child.signal === "SIGKILL") {
37
31
  console.log(`
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
- `)
42
- } else if (child.signal === 'SIGTERM') {
35
+ `);
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,20 @@
2
2
 
3
3
  Here you can find a resume of all changes between versions.
4
4
 
5
+ ## 1.1.1
6
+
7
+ ### Chores
8
+
9
+ - Upgraded dependencies
10
+
11
+ ## 1.1.0
12
+
13
+ ### Features
14
+
15
+ - Upgraded dependencies
16
+ - Use new ESBuild 0.17 APIs for dev watch & rebuild
17
+ - Properly build TS files
18
+
5
19
  ## 1.0.7
6
20
 
7
21
  ### Features
@@ -25,9 +39,9 @@ Here you can find a resume of all changes between versions.
25
39
  ### Features
26
40
 
27
41
  - 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)
42
+ - Svgs part of /src except ones that are in /src/assets will be
43
+ loaded as React components with svgr.
44
+ - Others will be loaded as dataurl (base64)
31
45
 
32
46
  ## 1.0.3
33
47
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imtf/profile-scripts",
3
- "version": "1.0.8",
3
+ "version": "1.1.1",
4
4
  "description": "Default scripts to bundle & transpile imtf front-end plugins",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -12,29 +12,29 @@
12
12
  "changelog.md"
13
13
  ],
14
14
  "scripts": {
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"
15
+ "build": "NODE_ENV=production node scripts/esbuild.mjs --entryPoint=index.tsx",
16
+ "start": "node scripts/esbuild.mjs --entryPoint=index.tsx --watch"
19
17
  },
20
18
  "eslintConfig": {
21
- "extends": "@imtf/eslint-config-react"
19
+ "extends": "@imtf/eslint-config-react",
20
+ "rules": {
21
+ "import/default": "off"
22
+ }
22
23
  },
23
24
  "prettier": "@imtf/prettier-config",
24
- "author": "Luca Pillonel",
25
25
  "license": "UNLICENSED",
26
26
  "private": false,
27
27
  "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.16.17",
28
+ "@svgr/core": "^8.0.0",
29
+ "@svgr/plugin-jsx": "^8.0.1",
30
+ "@svgr/plugin-svgo": "^8.0.1",
31
+ "concurrently": "^8.0.1",
32
+ "esbuild": "^0.18.6",
33
33
  "esbuild-plugin-external-global": "^1.0.1",
34
34
  "serve": "^14.1.2"
35
35
  },
36
36
  "devDependencies": {
37
- "@imtf/eslint-config-react": "^1.0.0",
38
- "@imtf/prettier-config": "^1.0.0"
37
+ "@imtf/eslint-config-react": "^3.0.0",
38
+ "@imtf/prettier-config": "^3.0.0"
39
39
  }
40
40
  }
@@ -1,53 +1,72 @@
1
- import { build } from 'esbuild'
2
- import externalGlobalPlugin from 'esbuild-plugin-external-global'
3
- import minimist from 'minimist'
1
+ import { build, context } from "esbuild";
2
+ import esbuild from "esbuild-plugin-external-global";
3
+ import minimist from "minimist";
4
4
 
5
- import svgPlugin from './svgPlugin.mjs'
5
+ // eslint-disable-next-line import/no-named-as-default-member
6
+ const externalGlobalPlugin = esbuild.externalGlobalPlugin;
6
7
 
7
- const { watch } = minimist(process.argv.slice(2))
8
+ import notifierPlugin from "./notifierPlugin.mjs";
9
+ import svgPlugin from "./svgPlugin.mjs";
8
10
 
9
- build({
10
- entryPoints: ['src/index.js'],
11
- // outfile: 'build/index.js',
12
- outdir: 'build',
13
- platform: 'browser',
11
+ const { watch, entryPoint } = minimist(process.argv.slice(2));
12
+
13
+ const entryPoints = entryPoint
14
+ ? typeof entryPoint === "string"
15
+ ? [entryPoint]
16
+ : entryPoint
17
+ : ["src/index.js"];
18
+
19
+ /**
20
+ * @type {import('esbuild').BuildOptions}
21
+ */
22
+ const config = {
23
+ entryPoints,
24
+ outdir: "build",
25
+ platform: "browser",
14
26
  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,
27
+ target: "es2020",
26
28
 
27
29
  minify:
28
- process.env.NODE_ENV === 'production' &&
29
- process.env.IMTF_MINIFY_WEBAPP !== 'false',
30
+ process.env.NODE_ENV === "production" &&
31
+ process.env.IMTF_MINIFY_WEBAPP !== "false",
32
+
30
33
  loader: {
34
+ ".css": "text",
31
35
  // Enable JSX in .js files too
32
- '.css': 'text',
33
- '.js': 'jsx',
36
+ ".js": "jsx",
34
37
  // Embed fonts
35
- '.eot': 'dataurl',
36
- '.ttf': 'dataurl',
37
- '.woff': 'dataurl',
38
- '.woff2': 'dataurl',
38
+ ".eot": "dataurl",
39
+ ".ttf": "dataurl",
40
+ ".woff": "dataurl",
41
+ ".woff2": "dataurl",
39
42
  // Embed images
40
- '.gif': 'dataurl',
41
- '.jpg': 'dataurl',
42
- '.png': 'dataurl',
43
+ ".gif": "dataurl",
44
+ ".jpg": "dataurl",
45
+ ".png": "dataurl",
43
46
  },
47
+
44
48
  plugins: [
45
49
  svgPlugin(),
46
- externalGlobalPlugin.externalGlobalPlugin({
47
- react: 'window.React',
48
- 'react-dom': 'window.ReactDOM',
49
- 'react-router-dom': 'window.reactRouterDom',
50
- IMTFPlugins: 'window.IMTFPlugins',
50
+ externalGlobalPlugin({
51
+ react: "window.React",
52
+ "react-dom": "window.ReactDOM",
53
+ "react-router-dom": "window.reactRouterDom",
54
+ IMTFPlugins: "window.IMTFPlugins",
51
55
  }),
56
+ notifierPlugin(),
52
57
  ],
53
- })
58
+ };
59
+
60
+ if (watch) {
61
+ const ctx = await context(config);
62
+
63
+ // Enable watch mode
64
+ await ctx.watch();
65
+
66
+ // Enable serve mode
67
+ await ctx.serve({
68
+ port: 3010,
69
+ });
70
+ } else {
71
+ build(config);
72
+ }
@@ -0,0 +1,20 @@
1
+ const notifierPlugin = () => ({
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;
@@ -1,44 +1,44 @@
1
- import { transform } from '@svgr/core'
2
- import fs from 'fs'
3
- import path from 'path'
1
+ import { transform } from "@svgr/core";
2
+ import fs from "fs";
3
+ import path from "path";
4
4
 
5
5
  const svgPlugin = (options = {}) => ({
6
- name: 'svgr',
6
+ name: "svgr",
7
7
  setup(build) {
8
- build.onLoad({ filter: /\.svg$/ }, async args => {
8
+ build.onLoad({ filter: /\.svg$/ }, async (args) => {
9
9
  // Read file content
10
- const svg = await fs.promises.readFile(args.path, 'utf8')
10
+ const svg = await fs.promises.readFile(args.path, "utf8");
11
11
 
12
12
  // Determine relative path
13
- const relativePath = path.relative(process.cwd(), args.path)
13
+ const relativePath = path.relative(process.cwd(), args.path);
14
14
 
15
15
  // This is an asset ==> dataurl
16
16
  if (
17
- !relativePath.startsWith('src/') ||
18
- relativePath.startsWith('src/assets/')
17
+ !relativePath.startsWith("src/") ||
18
+ relativePath.startsWith("src/assets/")
19
19
  ) {
20
20
  return {
21
21
  contents: svg,
22
- loader: 'dataurl',
23
- }
22
+ loader: "dataurl",
23
+ };
24
24
  }
25
25
 
26
26
  // Otherwise it's a react component
27
27
  const contents = await transform(
28
28
  svg,
29
29
  {
30
- plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx'],
30
+ plugins: ["@svgr/plugin-svgo", "@svgr/plugin-jsx"],
31
31
  ...options,
32
32
  },
33
33
  { filePath: args.path }
34
- )
34
+ );
35
35
 
36
36
  return {
37
37
  contents,
38
- loader: 'jsx',
39
- }
40
- })
38
+ loader: "jsx",
39
+ };
40
+ });
41
41
  },
42
- })
42
+ });
43
43
 
44
- export default svgPlugin
44
+ export default svgPlugin;