@imtf/profile-scripts 1.1.0 → 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.
- package/bin/profile-scripts.js +12 -12
- package/changelog.md +6 -0
- package/package.json +13 -11
- package/scripts/esbuild.mjs +29 -26
- package/scripts/notifierPlugin.mjs +10 -10
- package/scripts/svgPlugin.mjs +18 -18
package/bin/profile-scripts.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const spawn = require(
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
4
|
+
const spawn = require("cross-spawn");
|
|
5
5
|
|
|
6
6
|
const args = process.argv.slice(2);
|
|
7
|
-
const scriptIndex = args.findIndex((x) => x ===
|
|
7
|
+
const scriptIndex = args.findIndex((x) => x === "build" || x === "start");
|
|
8
8
|
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
|
|
9
9
|
|
|
10
10
|
const scriptPath = require.resolve(`../scripts/esbuild.mjs`);
|
|
11
11
|
|
|
12
12
|
switch (script) {
|
|
13
|
-
case
|
|
14
|
-
case
|
|
13
|
+
case "start":
|
|
14
|
+
case "build": {
|
|
15
15
|
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
|
|
16
16
|
const scriptArgs = args.slice(scriptIndex + 1);
|
|
17
17
|
|
|
18
|
-
if (script ===
|
|
19
|
-
scriptArgs.push(
|
|
18
|
+
if (script === "start") {
|
|
19
|
+
scriptArgs.push("--watch");
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const processArgs = nodeArgs.concat(scriptPath).concat(scriptArgs);
|
|
23
23
|
|
|
24
|
-
const child = spawn.sync(
|
|
25
|
-
stdio:
|
|
26
|
-
env: { ...process.env, NODE_ENV:
|
|
24
|
+
const child = spawn.sync("node", processArgs, {
|
|
25
|
+
stdio: "inherit",
|
|
26
|
+
env: { ...process.env, NODE_ENV: "production" },
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
if (child.signal) {
|
|
30
|
-
if (child.signal ===
|
|
30
|
+
if (child.signal === "SIGKILL") {
|
|
31
31
|
console.log(`
|
|
32
32
|
The build failed because the process exited too early.
|
|
33
33
|
This probably means the system ran out of memory or someone called
|
|
34
34
|
\`kill -9\` on the process.
|
|
35
35
|
`);
|
|
36
|
-
} else if (child.signal ===
|
|
36
|
+
} else if (child.signal === "SIGTERM") {
|
|
37
37
|
console.log(`
|
|
38
38
|
The build failed because the process exited too early.
|
|
39
39
|
Someone might have called \`kill\` or \`killall\`, or the system could
|
package/changelog.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imtf/profile-scripts",
|
|
3
|
-
"version": "1.1.
|
|
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,27 +12,29 @@
|
|
|
12
12
|
"changelog.md"
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
|
-
"build": "NODE_ENV=production node scripts/esbuild.mjs",
|
|
16
|
-
"start": "node scripts/esbuild.mjs --watch"
|
|
15
|
+
"build": "NODE_ENV=production node scripts/esbuild.mjs --entryPoint=index.tsx",
|
|
16
|
+
"start": "node scripts/esbuild.mjs --entryPoint=index.tsx --watch"
|
|
17
17
|
},
|
|
18
18
|
"eslintConfig": {
|
|
19
|
-
"extends": "@imtf/eslint-config-react"
|
|
19
|
+
"extends": "@imtf/eslint-config-react",
|
|
20
|
+
"rules": {
|
|
21
|
+
"import/default": "off"
|
|
22
|
+
}
|
|
20
23
|
},
|
|
21
24
|
"prettier": "@imtf/prettier-config",
|
|
22
|
-
"author": "Luca Pillonel",
|
|
23
25
|
"license": "UNLICENSED",
|
|
24
26
|
"private": false,
|
|
25
27
|
"dependencies": {
|
|
26
|
-
"@svgr/core": "^
|
|
27
|
-
"@svgr/plugin-jsx": "^
|
|
28
|
-
"@svgr/plugin-svgo": "^
|
|
28
|
+
"@svgr/core": "^8.0.0",
|
|
29
|
+
"@svgr/plugin-jsx": "^8.0.1",
|
|
30
|
+
"@svgr/plugin-svgo": "^8.0.1",
|
|
29
31
|
"concurrently": "^8.0.1",
|
|
30
|
-
"esbuild": "^0.
|
|
32
|
+
"esbuild": "^0.18.6",
|
|
31
33
|
"esbuild-plugin-external-global": "^1.0.1",
|
|
32
34
|
"serve": "^14.1.2"
|
|
33
35
|
},
|
|
34
36
|
"devDependencies": {
|
|
35
|
-
"@imtf/eslint-config-react": "^
|
|
36
|
-
"@imtf/prettier-config": "^
|
|
37
|
+
"@imtf/eslint-config-react": "^3.0.0",
|
|
38
|
+
"@imtf/prettier-config": "^3.0.0"
|
|
37
39
|
}
|
|
38
40
|
}
|
package/scripts/esbuild.mjs
CHANGED
|
@@ -1,54 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import minimist from
|
|
1
|
+
import { build, context } from "esbuild";
|
|
2
|
+
import esbuild from "esbuild-plugin-external-global";
|
|
3
|
+
import minimist from "minimist";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// eslint-disable-next-line import/no-named-as-default-member
|
|
6
|
+
const externalGlobalPlugin = esbuild.externalGlobalPlugin;
|
|
7
|
+
|
|
8
|
+
import notifierPlugin from "./notifierPlugin.mjs";
|
|
9
|
+
import svgPlugin from "./svgPlugin.mjs";
|
|
7
10
|
|
|
8
11
|
const { watch, entryPoint } = minimist(process.argv.slice(2));
|
|
9
12
|
|
|
10
13
|
const entryPoints = entryPoint
|
|
11
|
-
? typeof entryPoint ===
|
|
14
|
+
? typeof entryPoint === "string"
|
|
12
15
|
? [entryPoint]
|
|
13
16
|
: entryPoint
|
|
14
|
-
: [
|
|
17
|
+
: ["src/index.js"];
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* @type {import('esbuild').BuildOptions}
|
|
18
21
|
*/
|
|
19
22
|
const config = {
|
|
20
23
|
entryPoints,
|
|
21
|
-
outdir:
|
|
22
|
-
platform:
|
|
24
|
+
outdir: "build",
|
|
25
|
+
platform: "browser",
|
|
23
26
|
bundle: true,
|
|
24
|
-
target:
|
|
27
|
+
target: "es2020",
|
|
25
28
|
|
|
26
29
|
minify:
|
|
27
|
-
process.env.NODE_ENV ===
|
|
28
|
-
process.env.IMTF_MINIFY_WEBAPP !==
|
|
30
|
+
process.env.NODE_ENV === "production" &&
|
|
31
|
+
process.env.IMTF_MINIFY_WEBAPP !== "false",
|
|
29
32
|
|
|
30
33
|
loader: {
|
|
31
|
-
|
|
34
|
+
".css": "text",
|
|
32
35
|
// Enable JSX in .js files too
|
|
33
|
-
|
|
36
|
+
".js": "jsx",
|
|
34
37
|
// Embed fonts
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
".eot": "dataurl",
|
|
39
|
+
".ttf": "dataurl",
|
|
40
|
+
".woff": "dataurl",
|
|
41
|
+
".woff2": "dataurl",
|
|
39
42
|
// Embed images
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
".gif": "dataurl",
|
|
44
|
+
".jpg": "dataurl",
|
|
45
|
+
".png": "dataurl",
|
|
43
46
|
},
|
|
44
47
|
|
|
45
48
|
plugins: [
|
|
46
49
|
svgPlugin(),
|
|
47
|
-
externalGlobalPlugin
|
|
48
|
-
react:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
IMTFPlugins:
|
|
50
|
+
externalGlobalPlugin({
|
|
51
|
+
react: "window.React",
|
|
52
|
+
"react-dom": "window.ReactDOM",
|
|
53
|
+
"react-router-dom": "window.reactRouterDom",
|
|
54
|
+
IMTFPlugins: "window.IMTFPlugins",
|
|
52
55
|
}),
|
|
53
56
|
notifierPlugin(),
|
|
54
57
|
],
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
const notifierPlugin = (
|
|
2
|
-
name:
|
|
1
|
+
const notifierPlugin = () => ({
|
|
2
|
+
name: "svgr",
|
|
3
3
|
setup(build) {
|
|
4
|
-
let count = 0
|
|
4
|
+
let count = 0;
|
|
5
5
|
|
|
6
|
-
build.onEnd(result => {
|
|
6
|
+
build.onEnd((result) => {
|
|
7
7
|
if (result.errors.length > 0) {
|
|
8
|
-
return
|
|
8
|
+
return;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
if (count++ === 0) {
|
|
12
|
-
console.log(`1st build: ${new Date().getTime()}`)
|
|
12
|
+
console.log(`1st build: ${new Date().getTime()}`);
|
|
13
13
|
} else {
|
|
14
|
-
console.log(`Rebuilt: ${new Date().getTime()}`)
|
|
14
|
+
console.log(`Rebuilt: ${new Date().getTime()}`);
|
|
15
15
|
}
|
|
16
|
-
})
|
|
16
|
+
});
|
|
17
17
|
},
|
|
18
|
-
})
|
|
18
|
+
});
|
|
19
19
|
|
|
20
|
-
export default notifierPlugin
|
|
20
|
+
export default notifierPlugin;
|
package/scripts/svgPlugin.mjs
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { transform } from
|
|
2
|
-
import fs from
|
|
3
|
-
import path from
|
|
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:
|
|
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,
|
|
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(
|
|
18
|
-
relativePath.startsWith(
|
|
17
|
+
!relativePath.startsWith("src/") ||
|
|
18
|
+
relativePath.startsWith("src/assets/")
|
|
19
19
|
) {
|
|
20
20
|
return {
|
|
21
21
|
contents: svg,
|
|
22
|
-
loader:
|
|
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: [
|
|
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:
|
|
39
|
-
}
|
|
40
|
-
})
|
|
38
|
+
loader: "jsx",
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
41
|
},
|
|
42
|
-
})
|
|
42
|
+
});
|
|
43
43
|
|
|
44
|
-
export default svgPlugin
|
|
44
|
+
export default svgPlugin;
|