Resolve paths and add check for yarn/npx
This commit is contained in:
19
config/paths.js
Normal file
19
config/paths.js
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
const appDirectory = fs.realpathSync(process.cwd());
|
||||
const resolveApp = (relativePath = "") =>
|
||||
path.resolve(appDirectory, relativePath);
|
||||
const templateDirectory = fs.realpathSync(__dirname);
|
||||
const resolveTemplate = (relativePath = "") =>
|
||||
path.resolve(templateDirectory, "..", relativePath);
|
||||
|
||||
module.exports = {
|
||||
template: resolveTemplate(),
|
||||
templateBuild: resolveTemplate("build"),
|
||||
appRdJson: resolveApp("build/rd.json"),
|
||||
appBuild: resolveApp("build"),
|
||||
appYarnLock: resolveApp("yarn.lock"),
|
||||
};
|
||||
@@ -14,13 +14,13 @@
|
||||
"buildRadar": "scripts/buildRadar.js"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "husky install && yarn build:tasks && yarn build",
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"build:tasks": "tsc --project tsconfig.tasks.json",
|
||||
"test": "react-scripts test",
|
||||
"ts:check": "tsc --noEmit",
|
||||
"lint": "yarn ts:check",
|
||||
"prepare": "husky install",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -14,6 +14,7 @@ process.on("unhandledRejection", (err) => {
|
||||
});
|
||||
|
||||
const fs = require("fs-extra");
|
||||
const paths = require("../config/paths");
|
||||
|
||||
const runCommand = (command, args) => {
|
||||
const cp = require("child_process");
|
||||
@@ -37,17 +38,28 @@ const runCommand = (command, args) => {
|
||||
});
|
||||
};
|
||||
|
||||
// TODO: Check if rd.json was created
|
||||
// TODO: Check how to empty folders without interfere with generateJson job
|
||||
// TODO: add dist folder for precompiled builder
|
||||
const buildTemplate = () => {
|
||||
const packageManager = fs.existsSync(paths.appYarnLock) ? "yarn" : "npx";
|
||||
|
||||
process.chdir("node_modules/aoe_technology_radar");
|
||||
fs.emptyDirSync("build");
|
||||
runCommand("yarn build")
|
||||
.then(() => {
|
||||
fs.copySync("build", "../../build");
|
||||
})
|
||||
.catch((error) => {
|
||||
fs.emptyDirSync(paths.templateBuild);
|
||||
process.chdir(paths.template);
|
||||
return runCommand(`${packageManager} build`).catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
};
|
||||
|
||||
// TODO: Use other output folder than bin for compiled tasks, because bin is misleading with node bin folder
|
||||
// TODO: add dist folder for precompiled builder
|
||||
|
||||
if (fs.existsSync(paths.appRdJson)) {
|
||||
buildTemplate().then(() => {
|
||||
fs.copySync(paths.templateBuild, paths.appBuild);
|
||||
console.log(`${paths.appBuild} was created and can be deployed.`);
|
||||
});
|
||||
} else {
|
||||
console.error(
|
||||
`${paths.appRdJson} does not exist. You have to generate it first.`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@ process.on("unhandledRejection", (err) => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
// TODO: execute yarn build:tasks to create bin folder with compiled radarJsonGenerator
|
||||
|
||||
require("../bin/tasks/radarjson")
|
||||
.radarJsonGenerator()
|
||||
.then(() => {
|
||||
|
||||
Reference in New Issue
Block a user