andoncloud-library-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/library-scripts.js +45 -0
- package/config/build.js +16 -0
- package/config/paths.js +18 -0
- package/package.json +35 -0
- package/scripts/build-watch.js +50 -0
- package/scripts/build.js +57 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
// Makes the script crash on unhandled rejections instead of silently ignoring them
|
|
6
|
+
process.on("unhandledRejection", (err) => {
|
|
7
|
+
throw err;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const spawn = require("react-dev-utils/crossSpawn");
|
|
11
|
+
const args = process.argv.slice(2);
|
|
12
|
+
|
|
13
|
+
const scriptIndex = args.findIndex((x) => x === "build" || x === "build-watch");
|
|
14
|
+
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
|
|
15
|
+
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
|
|
16
|
+
|
|
17
|
+
if (["build", "build-watch"].includes(script)) {
|
|
18
|
+
const result = spawn.sync(
|
|
19
|
+
process.execPath,
|
|
20
|
+
nodeArgs
|
|
21
|
+
.concat(require.resolve("../scripts/" + script))
|
|
22
|
+
.concat(args.slice(scriptIndex + 1)),
|
|
23
|
+
{ stdio: "inherit" }
|
|
24
|
+
);
|
|
25
|
+
if (result.signal) {
|
|
26
|
+
if (result.signal === "SIGKILL") {
|
|
27
|
+
console.log(
|
|
28
|
+
"The build failed because the process exited too early. " +
|
|
29
|
+
"This probably means the system ran out of memory or someone called " +
|
|
30
|
+
"`kill -9` on the process."
|
|
31
|
+
);
|
|
32
|
+
} else if (result.signal === "SIGTERM") {
|
|
33
|
+
console.log(
|
|
34
|
+
"The build failed because the process exited too early. " +
|
|
35
|
+
"Someone might have called `kill` or `killall`, or the system could " +
|
|
36
|
+
"be shutting down."
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
process.exit(result.status);
|
|
42
|
+
} else {
|
|
43
|
+
console.log('Unknown script "' + script + '".');
|
|
44
|
+
console.log("Perhaps you need to update library-scripts?");
|
|
45
|
+
}
|
package/config/build.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
BASE_EXTERNAL: [
|
|
5
|
+
"react",
|
|
6
|
+
"react-dom",
|
|
7
|
+
"react-is",
|
|
8
|
+
"graphql-request",
|
|
9
|
+
"@emotion/react",
|
|
10
|
+
"@emotion/styled",
|
|
11
|
+
"@mui/icons-material",
|
|
12
|
+
"@mui/lab",
|
|
13
|
+
"@mui/material",
|
|
14
|
+
".*/assets/.*",
|
|
15
|
+
].join(","),
|
|
16
|
+
};
|
package/config/paths.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
|
|
6
|
+
// Make sure any symlinks in the project folder are resolved
|
|
7
|
+
const libDirectory = fs.realpathSync(process.cwd());
|
|
8
|
+
const resolveWidget = (relativePath) =>
|
|
9
|
+
path.resolve(libDirectory, relativePath);
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
libPath: resolveWidget("."),
|
|
13
|
+
libDist: resolveWidget("dist"),
|
|
14
|
+
libPackageJson: resolveWidget("package.json"),
|
|
15
|
+
libVersionFile: resolveWidget("src/version.ts"),
|
|
16
|
+
assetsSrc: resolveWidget("src/assets"),
|
|
17
|
+
assetsDist: resolveWidget("dist/assets"),
|
|
18
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "andoncloud-library-scripts",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Scripts for Andoncloud library",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=14.0.0"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"config",
|
|
12
|
+
"scripts"
|
|
13
|
+
],
|
|
14
|
+
"bin": {
|
|
15
|
+
"library-scripts": "./bin/library-scripts.js"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"execa": "^5.1.1",
|
|
19
|
+
"microbundle": "^0.15.0",
|
|
20
|
+
"ora": "^5.4.1",
|
|
21
|
+
"react-dev-utils": "^12.0.1"
|
|
22
|
+
},
|
|
23
|
+
"browserslist": {
|
|
24
|
+
"production": [
|
|
25
|
+
">0.2%",
|
|
26
|
+
"not dead",
|
|
27
|
+
"not op_mini all"
|
|
28
|
+
],
|
|
29
|
+
"development": [
|
|
30
|
+
"last 1 chrome version",
|
|
31
|
+
"last 1 firefox version",
|
|
32
|
+
"last 1 safari version"
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Do this as the first thing so that any code reading it knows the right env
|
|
4
|
+
process.env.NODE_ENV = "production";
|
|
5
|
+
|
|
6
|
+
// Makes the script crash on unhandled rejections instead of silently ignoring them
|
|
7
|
+
process.on("unhandledRejection", (err) => {
|
|
8
|
+
throw err;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const execa = require("execa");
|
|
12
|
+
const fs = require("fs-extra");
|
|
13
|
+
|
|
14
|
+
const buildConf = require("../config/build");
|
|
15
|
+
const paths = require("../config/paths");
|
|
16
|
+
|
|
17
|
+
const argv = process.argv.slice(2);
|
|
18
|
+
|
|
19
|
+
function copyAssets() {
|
|
20
|
+
return fs.copySync(paths.assetsSrc, paths.assetsDist);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
(() => {
|
|
24
|
+
const argExternal = argv.length && argv[0] === "--external" ? argv[1] : "";
|
|
25
|
+
const allExternal = argExternal
|
|
26
|
+
? `${buildConf.BASE_EXTERNAL},${argExternal}`
|
|
27
|
+
: buildConf.BASE_EXTERNAL;
|
|
28
|
+
const libVersion = require(paths.libPackageJson).version;
|
|
29
|
+
|
|
30
|
+
console.log(`\nBuilding version ${libVersion} in watch mode:`);
|
|
31
|
+
|
|
32
|
+
copyAssets();
|
|
33
|
+
|
|
34
|
+
console.log(`\nExternals: ${allExternal}\n`);
|
|
35
|
+
|
|
36
|
+
execa.sync(
|
|
37
|
+
"npx",
|
|
38
|
+
[
|
|
39
|
+
"microbundle",
|
|
40
|
+
"watch",
|
|
41
|
+
"--jsx",
|
|
42
|
+
"React.createElement",
|
|
43
|
+
"--external=" + allExternal,
|
|
44
|
+
"--format",
|
|
45
|
+
"cjs",
|
|
46
|
+
"--no-compress",
|
|
47
|
+
],
|
|
48
|
+
{ cwd: paths.libPath, stdout: process.stdout, stderr: process.stderr }
|
|
49
|
+
);
|
|
50
|
+
})();
|
package/scripts/build.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Do this as the first thing so that any code reading it knows the right env
|
|
4
|
+
process.env.NODE_ENV = "production";
|
|
5
|
+
|
|
6
|
+
// Makes the script crash on unhandled rejections instead of silently ignoring them
|
|
7
|
+
process.on("unhandledRejection", (err) => {
|
|
8
|
+
throw err;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const execa = require("execa");
|
|
12
|
+
const fs = require("fs-extra");
|
|
13
|
+
const ora = require("ora");
|
|
14
|
+
|
|
15
|
+
const buildConf = require("../config/build");
|
|
16
|
+
const paths = require("../config/paths");
|
|
17
|
+
|
|
18
|
+
const argv = process.argv.slice(2);
|
|
19
|
+
|
|
20
|
+
function copyAssets() {
|
|
21
|
+
return fs.copySync(paths.assetsSrc, paths.assetsDist);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
(async () => {
|
|
25
|
+
const argExternal = argv.length && argv[0] === "--external" ? argv[1] : "";
|
|
26
|
+
const allExternal = argExternal
|
|
27
|
+
? `${buildConf.BASE_EXTERNAL},${argExternal}`
|
|
28
|
+
: buildConf.BASE_EXTERNAL;
|
|
29
|
+
const libVersion = require(paths.libPackageJson).version;
|
|
30
|
+
|
|
31
|
+
console.log(`\nBuilding version ${libVersion}:`);
|
|
32
|
+
|
|
33
|
+
fs.writeFile(
|
|
34
|
+
paths.libVersionFile,
|
|
35
|
+
`export const LIBRARY_VERSION = '${libVersion}';`
|
|
36
|
+
);
|
|
37
|
+
copyAssets();
|
|
38
|
+
|
|
39
|
+
console.log(`\nExternals: ${allExternal}\n`);
|
|
40
|
+
|
|
41
|
+
await ora.promise(
|
|
42
|
+
execa(
|
|
43
|
+
"npx",
|
|
44
|
+
[
|
|
45
|
+
"microbundle",
|
|
46
|
+
"--jsx",
|
|
47
|
+
"React.createElement",
|
|
48
|
+
"--external=" + allExternal,
|
|
49
|
+
"--format",
|
|
50
|
+
"cjs",
|
|
51
|
+
"--no-compress",
|
|
52
|
+
],
|
|
53
|
+
{ cwd: paths.libPath, stdout: process.stdout, stderr: process.stderr }
|
|
54
|
+
),
|
|
55
|
+
"Building library...\n"
|
|
56
|
+
);
|
|
57
|
+
})();
|