Resolve paths and add check for yarn/npx

This commit is contained in:
dennis.ludwig
2021-06-10 14:27:44 +02:00
parent 81923be958
commit 4afe9b3c4e
4 changed files with 42 additions and 13 deletions

19
config/paths.js Normal file
View 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"),
};

View File

@@ -14,13 +14,13 @@
"buildRadar": "scripts/buildRadar.js" "buildRadar": "scripts/buildRadar.js"
}, },
"scripts": { "scripts": {
"prepare": "husky install && yarn build:tasks && yarn build",
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"build:tasks": "tsc --project tsconfig.tasks.json", "build:tasks": "tsc --project tsconfig.tasks.json",
"test": "react-scripts test", "test": "react-scripts test",
"ts:check": "tsc --noEmit", "ts:check": "tsc --noEmit",
"lint": "yarn ts:check", "lint": "yarn ts:check",
"prepare": "husky install",
"eject": "react-scripts eject" "eject": "react-scripts eject"
}, },
"dependencies": { "dependencies": {

View File

@@ -14,6 +14,7 @@ process.on("unhandledRejection", (err) => {
}); });
const fs = require("fs-extra"); const fs = require("fs-extra");
const paths = require("../config/paths");
const runCommand = (command, args) => { const runCommand = (command, args) => {
const cp = require("child_process"); const cp = require("child_process");
@@ -37,17 +38,28 @@ const runCommand = (command, args) => {
}); });
}; };
// TODO: Check if rd.json was created const buildTemplate = () => {
// TODO: Check how to empty folders without interfere with generateJson job const packageManager = fs.existsSync(paths.appYarnLock) ? "yarn" : "npx";
// TODO: add dist folder for precompiled builder
process.chdir("node_modules/aoe_technology_radar"); fs.emptyDirSync(paths.templateBuild);
fs.emptyDirSync("build"); process.chdir(paths.template);
runCommand("yarn build") return runCommand(`${packageManager} build`).catch((error) => {
.then(() => {
fs.copySync("build", "../../build");
})
.catch((error) => {
console.error(error); console.error(error);
process.exit(1); 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);
}

View File

@@ -13,8 +13,6 @@ process.on("unhandledRejection", (err) => {
throw err; throw err;
}); });
// TODO: execute yarn build:tasks to create bin folder with compiled radarJsonGenerator
require("../bin/tasks/radarjson") require("../bin/tasks/radarjson")
.radarJsonGenerator() .radarJsonGenerator()
.then(() => { .then(() => {