@imtf/profile-scripts 1.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/bin/profile-scripts.js +58 -0
- package/package.json +36 -0
- package/scripts/esbuild.mjs +42 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const spawn = require('cross-spawn')
|
|
4
|
+
const concurrently = require('concurrently')
|
|
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]
|
|
9
|
+
|
|
10
|
+
const scriptPath = require.resolve(`../scripts/esbuild.mjs`)
|
|
11
|
+
|
|
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)
|
|
29
|
+
|
|
30
|
+
const child = spawn.sync('node', processArgs, {
|
|
31
|
+
stdio: 'inherit',
|
|
32
|
+
env: { ...process.env, NODE_ENV: 'production' },
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
if (child.signal) {
|
|
36
|
+
if (child.signal === 'SIGKILL') {
|
|
37
|
+
console.log(`
|
|
38
|
+
The build failed because the process exited too early.
|
|
39
|
+
This probably means the system ran out of memory or someone called
|
|
40
|
+
\`kill -9\` on the process.
|
|
41
|
+
`)
|
|
42
|
+
} else if (child.signal === 'SIGTERM') {
|
|
43
|
+
console.log(`
|
|
44
|
+
The build failed because the process exited too early.
|
|
45
|
+
Someone might have called \`kill\` or \`killall\`, or the system could
|
|
46
|
+
be shutting down.
|
|
47
|
+
`)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
process.exit(1)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
break
|
|
54
|
+
}
|
|
55
|
+
default:
|
|
56
|
+
console.log(`Unknown script "${script}".`)
|
|
57
|
+
break
|
|
58
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@imtf/profile-scripts",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Default scripts to bundle & transpile imtf front-end plugins",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"profile-scripts": "./bin/profile-scripts.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"scripts/esbuild.mjs",
|
|
11
|
+
".prettierrc.js",
|
|
12
|
+
"yarn.lock"
|
|
13
|
+
],
|
|
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"
|
|
19
|
+
},
|
|
20
|
+
"eslintConfig": {
|
|
21
|
+
"extends": "@imtf/eslint-config-react"
|
|
22
|
+
},
|
|
23
|
+
"prettier": "@imtf/prettier-config",
|
|
24
|
+
"author": "Luca Pillonel",
|
|
25
|
+
"license": "UNLICENSED",
|
|
26
|
+
"private": false,
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"concurrently": "^6.2.1",
|
|
29
|
+
"esbuild": "^0.14.8",
|
|
30
|
+
"esbuild-plugin-external-global": "^1.0.1",
|
|
31
|
+
"esbuild-plugin-svgr": "^1.0.0",
|
|
32
|
+
"serve": "^13.0.2",
|
|
33
|
+
"@imtf/prettier-config": "^1.0.0",
|
|
34
|
+
"@imtf/eslint-config-react": "^1.0.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { build } from 'esbuild'
|
|
2
|
+
import svgrPlugin from 'esbuild-plugin-svgr'
|
|
3
|
+
import externalGlobalPlugin from 'esbuild-plugin-external-global'
|
|
4
|
+
import minimist from 'minimist'
|
|
5
|
+
|
|
6
|
+
const { watch } = minimist(process.argv.slice(2))
|
|
7
|
+
|
|
8
|
+
build({
|
|
9
|
+
entryPoints: ['src/index.js'],
|
|
10
|
+
outfile: 'build/index.js',
|
|
11
|
+
platform: 'browser',
|
|
12
|
+
bundle: true,
|
|
13
|
+
target: 'es6',
|
|
14
|
+
|
|
15
|
+
watch: watch
|
|
16
|
+
? {
|
|
17
|
+
onRebuild(error, result) {
|
|
18
|
+
if (!error) {
|
|
19
|
+
console.log(`Rebuilt: ${new Date().getTime()}`)
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
: false,
|
|
24
|
+
|
|
25
|
+
minify:
|
|
26
|
+
process.env.NODE_ENV === 'production' &&
|
|
27
|
+
process.env.IMTF_MINIFY_WEBAPP !== 'false',
|
|
28
|
+
// jsx: 'transform',
|
|
29
|
+
loader: {
|
|
30
|
+
// Enable JSX in .js files too
|
|
31
|
+
'.js': 'jsx',
|
|
32
|
+
},
|
|
33
|
+
plugins: [
|
|
34
|
+
svgrPlugin(),
|
|
35
|
+
externalGlobalPlugin.externalGlobalPlugin({
|
|
36
|
+
react: 'window.React',
|
|
37
|
+
'react-dom': 'window.ReactDOM',
|
|
38
|
+
'react-router-dom': 'window.reactRouterDom',
|
|
39
|
+
IMTFPlugins: 'window.IMTFPlugins',
|
|
40
|
+
}),
|
|
41
|
+
],
|
|
42
|
+
})
|