orc-scripts 1.2.0-pre.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/LICENSE +19 -0
- package/README.md +76 -0
- package/babel.js +1 -0
- package/eslint.js +1 -0
- package/jest.js +1 -0
- package/package.json +164 -0
- package/prettier.js +1 -0
- package/src/__mocks__/fileMock.js +1 -0
- package/src/config/babel-preset.js +4 -0
- package/src/config/babel-transform.js +4 -0
- package/src/config/babel-whitelist.json +1 -0
- package/src/config/babelrc.js +38 -0
- package/src/config/eslintrc.js +15 -0
- package/src/config/jest-resolver.js +35 -0
- package/src/config/jest.config.js +45 -0
- package/src/config/jestSetupFiles.js +4 -0
- package/src/config/prettier.config.js +9 -0
- package/src/config/setAssetPath.js +1 -0
- package/src/config/unexpected-form.js +317 -0
- package/src/config/unexpected-form.test.js +2397 -0
- package/src/config/unexpected-module.js +112 -0
- package/src/config/unexpected-module.test.js +1106 -0
- package/src/config/unexpected-styles.js +44 -0
- package/src/config/unexpected-styles.test.js +118 -0
- package/src/config/unexpected.js +117 -0
- package/src/config/unexpected.test.js +393 -0
- package/src/config/webpack.config.js +103 -0
- package/src/index.js +19 -0
- package/src/run-script.js +99 -0
- package/src/scripts/build/cli.js +43 -0
- package/src/scripts/build/index.js +9 -0
- package/src/scripts/build/web.js +24 -0
- package/src/scripts/buildDep.js +122 -0
- package/src/scripts/buildIconsSheet.js +50 -0
- package/src/scripts/clean.js +8 -0
- package/src/scripts/extract-messages.js +22 -0
- package/src/scripts/generateApi.js +152 -0
- package/src/scripts/getDist.js +20 -0
- package/src/scripts/mergeTranslations.js +32 -0
- package/src/scripts/prep.js +28 -0
- package/src/scripts/start.js +45 -0
- package/src/scripts/tag.js +76 -0
- package/src/scripts/test.js +26 -0
- package/src/scripts/validateTranslations.js +72 -0
- package/src/utils.js +95 -0
- package/src/utils.test.js +93 -0
- package/webpack.js +1 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const webpack = require("webpack");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const readPkgUp = require("read-pkg-up");
|
|
4
|
+
const { parseEnv } = require("../utils");
|
|
5
|
+
|
|
6
|
+
const { packageJson } = readPkgUp.sync({ normalize: false }) || {};
|
|
7
|
+
|
|
8
|
+
const here = p => path.join(__dirname, p);
|
|
9
|
+
|
|
10
|
+
const babelWhitelist = require("./babel-whitelist.json");
|
|
11
|
+
|
|
12
|
+
const config = {
|
|
13
|
+
entry: [here("setAssetPath.js"), "url-polyfill", "core-js", "whatwg-fetch", path.resolve("./src/index.js")],
|
|
14
|
+
output: {
|
|
15
|
+
chunkFilename: "[id].[chunkhash].js",
|
|
16
|
+
filename: "bundle.js",
|
|
17
|
+
path: path.resolve(process.cwd(), "dist"),
|
|
18
|
+
},
|
|
19
|
+
resolve: {
|
|
20
|
+
alias: {},
|
|
21
|
+
modules: [
|
|
22
|
+
// Always resolve in local src and node_modules
|
|
23
|
+
path.resolve(process.cwd(), "src"),
|
|
24
|
+
path.resolve(process.cwd(), "node_modules"),
|
|
25
|
+
],
|
|
26
|
+
symlinks: false,
|
|
27
|
+
},
|
|
28
|
+
module: {
|
|
29
|
+
rules: [
|
|
30
|
+
{
|
|
31
|
+
resource: {
|
|
32
|
+
test: /\.js$/, // Only JavaScript files
|
|
33
|
+
or: [
|
|
34
|
+
// One of these conditions must be true
|
|
35
|
+
{ not: [/node_modules/] }, // No dependencies unless explicitly allowed by whitelist
|
|
36
|
+
].concat(
|
|
37
|
+
// Allowed by whitelist
|
|
38
|
+
babelWhitelist.map(
|
|
39
|
+
lib => new RegExp("node_modules(?:/|\\\\)" + lib.replace("/", "(?:/|\\\\)") + "(?:/|\\\\)"),
|
|
40
|
+
),
|
|
41
|
+
),
|
|
42
|
+
},
|
|
43
|
+
use: [
|
|
44
|
+
{
|
|
45
|
+
loader: "babel-loader",
|
|
46
|
+
options: require("./babelrc.js"),
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
test: /\.svg$/,
|
|
52
|
+
loader: "svg-inline-loader",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
test: /\.(jpe?g|png|gif)$/i,
|
|
56
|
+
use: ["file-loader", "img-loader"],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
test: /\.css$/i,
|
|
60
|
+
use: ["style-loader", "css-loader"],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
|
|
64
|
+
use: {
|
|
65
|
+
loader: "url-loader",
|
|
66
|
+
options: {
|
|
67
|
+
limit: 50000,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
plugins: [
|
|
74
|
+
new webpack.DefinePlugin({
|
|
75
|
+
BUILD_ID: `"${process.env.BUILD_BUILDID}"`,
|
|
76
|
+
BUILD_NUMBER: `"${process.env.BUILD_BUILDNUMBER}"`,
|
|
77
|
+
}),
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const locales = packageJson.locales;
|
|
82
|
+
const overtureModule = packageJson.overtureModule;
|
|
83
|
+
const dependencies = packageJson.dependencies;
|
|
84
|
+
|
|
85
|
+
config.plugins.push(
|
|
86
|
+
new webpack.DefinePlugin({
|
|
87
|
+
SUPPORTED_LOCALES: JSON.stringify(locales && locales.length ? locales : null),
|
|
88
|
+
OVERTURE_MODULE: JSON.stringify((overtureModule && overtureModule.name) || ""),
|
|
89
|
+
DEPENDENCIES: JSON.stringify(dependencies || {}),
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
if (parseEnv("NODE_ENV") === "production") {
|
|
94
|
+
config.devtool = "source-map";
|
|
95
|
+
config.mode = "production";
|
|
96
|
+
} else {
|
|
97
|
+
config.devtool = "inline-source-map";
|
|
98
|
+
config.optimization = { usedExports: true };
|
|
99
|
+
config.plugins.push(new webpack.NamedModulesPlugin(), new webpack.HotModuleReplacementPlugin());
|
|
100
|
+
config.mode = "development";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = config;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
require("dotenv").config();
|
|
4
|
+
|
|
5
|
+
global.amOrcScripts = /orc-scripts$/.test(require("pkg-dir").sync() || "");
|
|
6
|
+
|
|
7
|
+
let shouldThrow;
|
|
8
|
+
try {
|
|
9
|
+
shouldThrow = Number(process.version.slice(1).split(".")[0]) < 10;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
// ignore
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (shouldThrow) {
|
|
15
|
+
const msg = "You must use Node version 10 or greater to use orc-scripts.";
|
|
16
|
+
throw new Error(msg);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
require("./run-script");
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const spawn = require("cross-spawn");
|
|
3
|
+
const glob = require("glob");
|
|
4
|
+
|
|
5
|
+
const [, , script, ...args] = process.argv;
|
|
6
|
+
const executor = global.amOrcScripts ? "node" : process.argv[0];
|
|
7
|
+
|
|
8
|
+
if (script) {
|
|
9
|
+
spawnScript();
|
|
10
|
+
} else {
|
|
11
|
+
const scriptsPath = path.join(__dirname, "scripts/");
|
|
12
|
+
const scriptsAvailable = glob.sync(path.join(__dirname, "scripts", "*"));
|
|
13
|
+
// `glob.sync` returns paths with unix style path separators even on Windows.
|
|
14
|
+
// So we normalize it before attempting to strip out the scripts path.
|
|
15
|
+
const scriptsAvailableMessage = scriptsAvailable
|
|
16
|
+
.map(path.normalize)
|
|
17
|
+
.map(s =>
|
|
18
|
+
s
|
|
19
|
+
.replace(scriptsPath, "")
|
|
20
|
+
.replace(/__tests__/, "")
|
|
21
|
+
.replace(/\.js$/, ""),
|
|
22
|
+
)
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
.join("\n ")
|
|
25
|
+
.trim();
|
|
26
|
+
const fullMessage = `
|
|
27
|
+
Usage: orc-scripts [script] [parameters]
|
|
28
|
+
Available Scripts:
|
|
29
|
+
${scriptsAvailableMessage}
|
|
30
|
+
Parameters:
|
|
31
|
+
All parameters depend on the script. See documentation in orc-scripts/docs.
|
|
32
|
+
`.trim();
|
|
33
|
+
console.log(`\n${fullMessage}\n`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getEnv() {
|
|
37
|
+
// this is required to address an issue in cross-spawn
|
|
38
|
+
// https://github.com/kentcdodds/kcd-scripts/issues/4
|
|
39
|
+
return Object.keys(process.env)
|
|
40
|
+
.filter(key => process.env[key] !== undefined)
|
|
41
|
+
.reduce(
|
|
42
|
+
(envCopy, key) => {
|
|
43
|
+
envCopy[key] = process.env[key];
|
|
44
|
+
return envCopy;
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
[`SCRIPTS_${script.toUpperCase()}`]: true,
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function spawnScript() {
|
|
53
|
+
const relativeScriptPath = path.join(__dirname, "./scripts", script);
|
|
54
|
+
const scriptPath = attemptResolve(relativeScriptPath);
|
|
55
|
+
|
|
56
|
+
if (!scriptPath) {
|
|
57
|
+
throw new Error(`Unknown script "${script}".`);
|
|
58
|
+
}
|
|
59
|
+
const nodeArgs = [
|
|
60
|
+
"--preserve-symlinks",
|
|
61
|
+
"--preserve-symlinks-main",
|
|
62
|
+
"--icu-data-dir=node_modules" + path.sep + "full-icu",
|
|
63
|
+
];
|
|
64
|
+
const result = spawn.sync(executor, [...nodeArgs, scriptPath, ...args], {
|
|
65
|
+
stdio: "inherit",
|
|
66
|
+
env: getEnv(),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (result.signal) {
|
|
70
|
+
handleSignal(result);
|
|
71
|
+
} else {
|
|
72
|
+
process.exit(result.status);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function attemptResolve(...resolveArgs) {
|
|
77
|
+
try {
|
|
78
|
+
return require.resolve(...resolveArgs);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function handleSignal(result) {
|
|
85
|
+
if (result.signal === "SIGKILL") {
|
|
86
|
+
console.log(
|
|
87
|
+
`The script "${script}" failed because the process exited too early. ` +
|
|
88
|
+
"This probably means the system ran out of memory or someone called " +
|
|
89
|
+
"`kill -9` on the process.",
|
|
90
|
+
);
|
|
91
|
+
} else if (result.signal === "SIGTERM") {
|
|
92
|
+
console.log(
|
|
93
|
+
`The script "${script}" failed because the process exited too early. ` +
|
|
94
|
+
"Someone might have called `kill` or `killall`, or the system could " +
|
|
95
|
+
"be shutting down.",
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const { hasPkgProp, resolveBin, hasFile } = require("../../utils");
|
|
3
|
+
const spawn = require("cross-spawn");
|
|
4
|
+
|
|
5
|
+
const here = p => path.join(__dirname, p);
|
|
6
|
+
|
|
7
|
+
const args = process.argv.slice(2);
|
|
8
|
+
|
|
9
|
+
const useSpecifiedOutDir = args.includes("--out-dir");
|
|
10
|
+
const outDir = useSpecifiedOutDir ? [] : ["--out-dir", "dist"];
|
|
11
|
+
|
|
12
|
+
const copyFiles = args.includes("--no-copy-files") ? [] : ["--copy-files"];
|
|
13
|
+
|
|
14
|
+
const useBuiltinConfig =
|
|
15
|
+
!args.includes("--presets") && (!hasFile(".babelrc") || !hasFile("babel.config.js")) && !hasPkgProp("babel");
|
|
16
|
+
const config = useBuiltinConfig ? ["--presets", here("../../config/babel-preset.js")] : [];
|
|
17
|
+
|
|
18
|
+
const verbosity = args.includes("--quiet") ? [] : ["--verbose"];
|
|
19
|
+
|
|
20
|
+
const ignore = args.includes("--ignore") ? [] : ["--ignore", "**/*.test.js,**/__mocks__"];
|
|
21
|
+
|
|
22
|
+
const babelUnacceptedArgs = ["--no-copy-files"];
|
|
23
|
+
|
|
24
|
+
const filteredArgs = args.filter(arg => !babelUnacceptedArgs.includes(arg));
|
|
25
|
+
|
|
26
|
+
const child = spawn(
|
|
27
|
+
resolveBin("@babel/cli", { executable: "babel" }),
|
|
28
|
+
[...outDir, ...copyFiles, ...ignore, ...verbosity, ...config, "src"].concat(filteredArgs),
|
|
29
|
+
{ stdio: "inherit" },
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
child.on("error", err => {
|
|
33
|
+
console.error("An error occurred:");
|
|
34
|
+
console.error(err);
|
|
35
|
+
process.exit(-1);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
child.on("exit", exitCode => {
|
|
39
|
+
if (exitCode !== 0) {
|
|
40
|
+
console.error("Babel finished with non-zero exit code", exitCode);
|
|
41
|
+
}
|
|
42
|
+
process.exit(exitCode);
|
|
43
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const config = require("../../config/webpack.config");
|
|
2
|
+
const webpack = require("webpack");
|
|
3
|
+
|
|
4
|
+
const args = process.argv.slice(2);
|
|
5
|
+
|
|
6
|
+
if (args.includes("--stats")) {
|
|
7
|
+
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
|
|
8
|
+
config.plugins.push(new BundleAnalyzerPlugin());
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
webpack(config, (err, stats) => {
|
|
12
|
+
if (err) {
|
|
13
|
+
console.error(err.stack || err);
|
|
14
|
+
process.exit(-2);
|
|
15
|
+
}
|
|
16
|
+
console.log(
|
|
17
|
+
stats.toString({
|
|
18
|
+
colors: true,
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
if (stats.hasErrors()) {
|
|
22
|
+
process.exit(-1);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const util = require("util");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const readPkgUp = require("read-pkg-up");
|
|
4
|
+
const makeDir = require("make-dir");
|
|
5
|
+
const rimraf = util.promisify(require("rimraf"));
|
|
6
|
+
const copyFile = util.promisify(require("ncp").ncp);
|
|
7
|
+
const spawn = require("cross-spawn");
|
|
8
|
+
|
|
9
|
+
let repos;
|
|
10
|
+
const gitMatch = /^(git@github\.com:|https:\/\/)/;
|
|
11
|
+
repos = process.argv.find(element => gitMatch.test(element));
|
|
12
|
+
if (!repos) {
|
|
13
|
+
console.error("No target repository given");
|
|
14
|
+
process.exit(-11);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const gitBranchResult = spawn.sync("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
18
|
+
if (gitBranchResult.status !== 0) {
|
|
19
|
+
console.error(gitBranchResult.stderr.toString("utf-8"));
|
|
20
|
+
process.exit(-12);
|
|
21
|
+
}
|
|
22
|
+
const currentBranch = gitBranchResult.stdout.toString("utf-8").trim();
|
|
23
|
+
|
|
24
|
+
const master = process.argv.includes("--master") || currentBranch === "master";
|
|
25
|
+
let release;
|
|
26
|
+
if (process.argv.includes("--release")) {
|
|
27
|
+
release = process.argv[process.argv.indexOf("--release") + 1];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const releaseBranch = master ? "master" : release ? "release/" + release : "develop";
|
|
31
|
+
|
|
32
|
+
async function build(repos) {
|
|
33
|
+
const name = repos.match(/([^/]*)\.git$/)[1];
|
|
34
|
+
const folder = path.resolve(process.cwd(), "builds/" + name);
|
|
35
|
+
let pack;
|
|
36
|
+
|
|
37
|
+
const versionString = name + " " + releaseBranch;
|
|
38
|
+
console.log(`Building ${versionString} from repository ${repos}
|
|
39
|
+
in ${folder}`);
|
|
40
|
+
|
|
41
|
+
const { packageJson } = readPkgUp.sync({ normalize: false }) || {};
|
|
42
|
+
if (packageJson.scripts && packageJson.scripts.build) {
|
|
43
|
+
const buildResult = spawn.sync("npm", ["run", "build"]);
|
|
44
|
+
if (buildResult.status !== 0) {
|
|
45
|
+
console.error(buildResult.stderr.toString("utf-8"));
|
|
46
|
+
return -1;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const packResult = spawn.sync("npm", ["pack"]);
|
|
50
|
+
if (packResult.status !== 0) {
|
|
51
|
+
console.error(packResult.stderr.toString("utf-8"));
|
|
52
|
+
return -2;
|
|
53
|
+
}
|
|
54
|
+
const packName = packResult.stdout.toString("utf-8").trim();
|
|
55
|
+
console.log("Packaged to " + packName);
|
|
56
|
+
|
|
57
|
+
pack = path.resolve(process.cwd(), packName);
|
|
58
|
+
try {
|
|
59
|
+
try {
|
|
60
|
+
await rimraf(folder);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
console.error(err.message);
|
|
63
|
+
return -3;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
await makeDir("builds");
|
|
68
|
+
} catch (_) {}
|
|
69
|
+
|
|
70
|
+
const releaseArgs = ["--branch", releaseBranch, "--single-branch"];
|
|
71
|
+
|
|
72
|
+
const gitResult = spawn.sync("git", ["clone", repos, ...releaseArgs, folder]);
|
|
73
|
+
if (gitResult.status !== 0) {
|
|
74
|
+
console.error(gitResult.stderr.toString("utf-8"));
|
|
75
|
+
return -4;
|
|
76
|
+
}
|
|
77
|
+
console.log("Git repository was cloned");
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
await copyFile(path.resolve(folder, ".env.example"), path.resolve(folder, ".env"));
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.error(err.message);
|
|
83
|
+
return -5;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const installResult = spawn.sync("npm", ["install"], { cwd: folder });
|
|
87
|
+
if (installResult.status !== 0) {
|
|
88
|
+
console.error(installResult.stderr.toString("utf-8"));
|
|
89
|
+
return -6;
|
|
90
|
+
}
|
|
91
|
+
console.log("Dependencies installed");
|
|
92
|
+
|
|
93
|
+
const packInstallResult = spawn.sync("npm", ["install", pack], {
|
|
94
|
+
cwd: folder,
|
|
95
|
+
});
|
|
96
|
+
if (packInstallResult.status !== 0) {
|
|
97
|
+
console.error(packInstallResult.stderr.toString("utf-8"));
|
|
98
|
+
return -7;
|
|
99
|
+
}
|
|
100
|
+
console.log("Package installed");
|
|
101
|
+
|
|
102
|
+
const testResult = spawn.sync("npm", ["test", "--", "--no-watch"], {
|
|
103
|
+
cwd: folder,
|
|
104
|
+
stdio: "inherit",
|
|
105
|
+
});
|
|
106
|
+
if (testResult.status !== 0) {
|
|
107
|
+
return 1;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
console.log("Tests passed");
|
|
111
|
+
return 0;
|
|
112
|
+
} finally {
|
|
113
|
+
if (pack) await rimraf(pack);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
build(repos).then(returnCode => {
|
|
118
|
+
if (returnCode) {
|
|
119
|
+
console.log("Errors occurred.");
|
|
120
|
+
}
|
|
121
|
+
process.exit(returnCode);
|
|
122
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const baseDir = path.resolve(process.cwd(), "src");
|
|
3
|
+
const content = path.resolve(baseDir, "content");
|
|
4
|
+
const icons = path.resolve(content, "icons");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
|
|
7
|
+
const iconsSheet = path.resolve(content, "iconsSheet.svg");
|
|
8
|
+
|
|
9
|
+
const outStream = fs.createWriteStream(iconsSheet);
|
|
10
|
+
outStream.addListener("open", () => {
|
|
11
|
+
outStream.write('<svg xmlns="http://www.w3.org/2000/svg">\n');
|
|
12
|
+
// Beware of any files with spaces in filenames, they're bad
|
|
13
|
+
const fileList = fs.readdirSync(icons).filter(file => file.endsWith(".svg"));
|
|
14
|
+
|
|
15
|
+
fileList.forEach(fileName => {
|
|
16
|
+
const pathToIcon = path.resolve(icons, fileName);
|
|
17
|
+
|
|
18
|
+
const fileNameWithoutExtension = fileName.replace(".svg", "");
|
|
19
|
+
|
|
20
|
+
const svgContent = fs.readFileSync(pathToIcon).toString();
|
|
21
|
+
|
|
22
|
+
let strippedContent = svgContent
|
|
23
|
+
.replace("<svg", "<symbol")
|
|
24
|
+
.replace("</svg>", "</symbol>\n")
|
|
25
|
+
.replace("<symbol", `<symbol id="icon-${fileNameWithoutExtension}"`)
|
|
26
|
+
.replace(/width(.*)" /, "")
|
|
27
|
+
.replace(/height(.*)" /, "");
|
|
28
|
+
|
|
29
|
+
if (/<!-- no post-processing -->/g.test(strippedContent) === false) {
|
|
30
|
+
if (strippedContent.includes('fill="none"') === false) {
|
|
31
|
+
strippedContent = strippedContent.replace(/fill="(.*?)"/, "");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (strippedContent.includes("stroke") === false) {
|
|
35
|
+
console.log(fileNameWithoutExtension + ": adding stroke=none");
|
|
36
|
+
strippedContent = strippedContent.replace(/<path /gm, '<path stroke="none" ');
|
|
37
|
+
} else {
|
|
38
|
+
strippedContent = strippedContent.replace(/stroke="(.*?)"/, "");
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
console.log(fileNameWithoutExtension + ": skipping post-processing");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
strippedContent = strippedContent.replace(/\s*<!--\s*no post-processing\s*-->\s*/gm, "");
|
|
45
|
+
strippedContent = strippedContent.replace(/^\s*[\r\n]/gm, "").replace(/ +/g, " ");
|
|
46
|
+
|
|
47
|
+
outStream.write(strippedContent);
|
|
48
|
+
});
|
|
49
|
+
outStream.end("</svg>");
|
|
50
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const readPkgUp = require("read-pkg-up");
|
|
3
|
+
const extractReactIntlMessages = require("extract-react-intl-messages");
|
|
4
|
+
|
|
5
|
+
const { packageJson } = readPkgUp.sync({ normalize: false }) || {};
|
|
6
|
+
const locales = packageJson.locales.map(l => l.cultureIso);
|
|
7
|
+
|
|
8
|
+
if (!locales.length) {
|
|
9
|
+
console.error("Current project has no specified locales");
|
|
10
|
+
process.exit(-1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
console.log("Extracting react-intl messages for", locales.join(", "));
|
|
14
|
+
console.log("Default locale is", locales[0]);
|
|
15
|
+
|
|
16
|
+
const baseDir = path.resolve(process.cwd(), "src");
|
|
17
|
+
const input = path.join(baseDir, "**", "!(*.test).js");
|
|
18
|
+
const buildDir = path.resolve(baseDir, "translations");
|
|
19
|
+
|
|
20
|
+
extractReactIntlMessages(locales, input, buildDir, {
|
|
21
|
+
defaultLocale: locales[0],
|
|
22
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const https = require("https");
|
|
3
|
+
const lodash = require("lodash");
|
|
4
|
+
|
|
5
|
+
const occUrl = process.env.OccUrl;
|
|
6
|
+
const occToken = process.env.OccToken;
|
|
7
|
+
let outputFile = "";
|
|
8
|
+
|
|
9
|
+
if (process.argv.includes("--outputFile")) {
|
|
10
|
+
outputFile = process.argv[process.argv.indexOf("--outputFile") + 1];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (!outputFile) {
|
|
14
|
+
throw new Error("Missing --outputFile 'file' argument.");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!occToken) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"Missing OccToken environment variable. This environment variable needs to contains the authentication token used to access the OCC platform specified in OccUrl.",
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!occUrl) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
"Missing OccUrl environment variable. This environment variable needs to contains the URL of the OCC platform which contains the OpenAPI metadata.",
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function uncapitalizeFirstLetter(s) {
|
|
30
|
+
return s.charAt(0).toLowerCase() + s.slice(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function extractRequestNameFromOperation(operation) {
|
|
34
|
+
const rx = /.*{(?<name>[^{}]*)}$/;
|
|
35
|
+
return uncapitalizeFirstLetter(operation.summary.match(rx).groups["name"]);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function isVerbAllowed(verb) {
|
|
39
|
+
const lowerCaseVerb = verb.toLowerCase();
|
|
40
|
+
return lowerCaseVerb === "get" || lowerCaseVerb === "post" || lowerCaseVerb === "put" || lowerCaseVerb === "delete";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function generateOperationsFromPath(url, pathData) {
|
|
44
|
+
const operations = [];
|
|
45
|
+
|
|
46
|
+
for (const verb of Object.getOwnPropertyNames(pathData)) {
|
|
47
|
+
if (!isVerbAllowed(verb)) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const operation = pathData[verb];
|
|
52
|
+
|
|
53
|
+
operations.push({
|
|
54
|
+
name: extractRequestNameFromOperation(operation),
|
|
55
|
+
url: url,
|
|
56
|
+
verb: verb.toUpperCase(),
|
|
57
|
+
hasQueryString: operation.parameters.filter(p => p.in === "query").length > 0,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return operations;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function generateOperation(operation) {
|
|
65
|
+
// trim '/' from start/end and split on the '/' character. We do this to avoid having an empty element in the array
|
|
66
|
+
const urlSegments = lodash.trim(operation.url, "/").split("/");
|
|
67
|
+
const parameters = [];
|
|
68
|
+
const buildUrlParams = [];
|
|
69
|
+
|
|
70
|
+
// An OCC URL has the following format: /customers/{ScopeId}/{CustomerId}/orders
|
|
71
|
+
// The code below extract the tokens between curly braces and generates the parameters for the buildUrl method
|
|
72
|
+
|
|
73
|
+
for (const segment of urlSegments) {
|
|
74
|
+
if (segment.startsWith("{")) {
|
|
75
|
+
const cleanName = uncapitalizeFirstLetter(segment.match(/{(?<name>[^{}]*)}/).groups["name"]);
|
|
76
|
+
parameters.push(cleanName);
|
|
77
|
+
buildUrlParams.push(cleanName);
|
|
78
|
+
} else {
|
|
79
|
+
buildUrlParams.push(`"${segment}"`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let buildUrlParamsStr = `[${buildUrlParams.join(", ")}]`;
|
|
84
|
+
|
|
85
|
+
if (operation.hasQueryString) {
|
|
86
|
+
parameters.push("queryParams");
|
|
87
|
+
buildUrlParamsStr += ", queryParams";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return `export const ${operation.name} = {
|
|
91
|
+
\tname: '${operation.name}',
|
|
92
|
+
\tbuildUrl: (${parameters.join(", ")}) => buildUrl(${buildUrlParamsStr}),
|
|
93
|
+
\tverb: '${operation.verb}'
|
|
94
|
+
}\n\n`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function generateImports() {
|
|
98
|
+
if (fs.existsSync("node_modules/orc-shared")) {
|
|
99
|
+
return 'import { buildUrl } from "orc-shared/src/utils/buildUrl";\n\n';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return 'import { buildUrl } from "../utils/buildUrl";\n\n';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
https
|
|
106
|
+
.get(occUrl, { headers: { "X-AUTH": occToken } }, resp => {
|
|
107
|
+
let data = "";
|
|
108
|
+
let error = "";
|
|
109
|
+
|
|
110
|
+
if (resp.statusCode !== 200) {
|
|
111
|
+
error = new Error(`Request Failed. Status Code: ${resp.statusCode}`);
|
|
112
|
+
}
|
|
113
|
+
if (error) {
|
|
114
|
+
console.error(error.message);
|
|
115
|
+
// Consume response data to free up memory
|
|
116
|
+
resp.resume();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// A chunk of data has been received.
|
|
121
|
+
resp.on("data", chunk => {
|
|
122
|
+
data += chunk;
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// The whole response has been received. Print out the result.
|
|
126
|
+
resp.on("end", () => {
|
|
127
|
+
const swaggerMetaData = JSON.parse(data);
|
|
128
|
+
const paths = swaggerMetaData.paths;
|
|
129
|
+
let operations = [];
|
|
130
|
+
|
|
131
|
+
for (const url of Object.getOwnPropertyNames(paths)) {
|
|
132
|
+
operations = operations.concat(generateOperationsFromPath(url, paths[url]));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let helperData = "/* istanbul ignore file */\n\n";
|
|
136
|
+
helperData += generateImports();
|
|
137
|
+
|
|
138
|
+
for (const op of lodash.sortBy(operations, [o => o.name])) {
|
|
139
|
+
helperData += generateOperation(op);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
fs.writeFile(outputFile, helperData, function (err) {
|
|
143
|
+
if (err) {
|
|
144
|
+
return console.error(err);
|
|
145
|
+
}
|
|
146
|
+
console.log(`File '${outputFile}' has been created`);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
})
|
|
150
|
+
.on("error", err => {
|
|
151
|
+
console.log("Error: " + err.message);
|
|
152
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const readPkgUp = require("read-pkg-up");
|
|
2
|
+
const { prerelease } = require("semver");
|
|
3
|
+
|
|
4
|
+
const { packageJson } = readPkgUp.sync({ normalize: false }) || {};
|
|
5
|
+
const currentVersion = packageJson.version;
|
|
6
|
+
const pre = prerelease(currentVersion);
|
|
7
|
+
|
|
8
|
+
if (pre && pre[0] === "pre") {
|
|
9
|
+
console.log("beta");
|
|
10
|
+
} else if (pre && pre[0] === "dev") {
|
|
11
|
+
console.log("dev");
|
|
12
|
+
} else if (currentVersion.endsWith("+legacy")) {
|
|
13
|
+
console.log("previous");
|
|
14
|
+
} else if (/^\d+\.\d+\.\d+$/.test(currentVersion)) {
|
|
15
|
+
console.log("latest");
|
|
16
|
+
} else {
|
|
17
|
+
// This is not right?
|
|
18
|
+
console.log("trash");
|
|
19
|
+
console.error("Version number ", currentVersion, "does not comply with expectations");
|
|
20
|
+
}
|