init project
commit
246305501d
|
@ -0,0 +1,106 @@
|
|||
import fs from "fs-extra";
|
||||
import config from "./config.js";
|
||||
import util from "util";
|
||||
import { exec } from "child_process";
|
||||
|
||||
const execPromise = util.promisify(exec);
|
||||
|
||||
function readConfig(name) {
|
||||
const config = fs.readJsonSync(name);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
function createTmpDir() {
|
||||
// check if tmp dir exists
|
||||
// if not, create it
|
||||
|
||||
if (!fs.existsSync(config.tmpFolder)) {
|
||||
fs.mkdirSync(config.tmpFolder);
|
||||
console.log("tmp folder created");
|
||||
}
|
||||
}
|
||||
|
||||
function copyTemplateWebsite() {
|
||||
console.log("copy template website");
|
||||
fs.copySync(config.templateWebsiteFolder, `${config.tmpFolder}/template`);
|
||||
|
||||
console.log("copy template website success");
|
||||
|
||||
// delete config.json file in template folder
|
||||
fs.removeSync(`${config.tmpFolder}/template/src/config.json`);
|
||||
}
|
||||
|
||||
function deleteTmpDir() {
|
||||
console.log("delete tmp folder");
|
||||
fs.removeSync(config.tmpFolder);
|
||||
}
|
||||
|
||||
async function buildCustomerWebsite(pageId, pageConfig) {
|
||||
console.log(`Start building customer website ${pageId}`);
|
||||
|
||||
// create config.json file in template folder
|
||||
fs.writeJsonSync(`${config.tmpFolder}/template/src/config.json`, pageConfig);
|
||||
|
||||
// delete public folder in tmp folder and recopy it from website template folder
|
||||
fs.removeSync(`${config.tmpFolder}/template/public`);
|
||||
|
||||
fs.copySync(
|
||||
`${config.templateWebsiteFolder}/public`,
|
||||
`${config.tmpFolder}/template/public`
|
||||
);
|
||||
|
||||
// copy all assets from customer data to public folder
|
||||
|
||||
fs.copySync(
|
||||
`${config.customerWebsiteDataFolder}/${pageId}/`,
|
||||
`${config.tmpFolder}/template/public/`
|
||||
);
|
||||
|
||||
// run npm run build in template folder
|
||||
try {
|
||||
const { stdout } = await execPromise("npm run build", {
|
||||
cwd: `${config.tmpFolder}/template`,
|
||||
});
|
||||
|
||||
console.log(stdout);
|
||||
} catch (err) {
|
||||
console.error(`Failed to build customer website ${pageId} ${err}`);
|
||||
} finally {
|
||||
console.log(`Build customer website ${pageId} success`);
|
||||
|
||||
// copy build folder to customer websites folder
|
||||
|
||||
fs.copySync(
|
||||
`${config.tmpFolder}/template/build`,
|
||||
`${config.customerWebsiteFolder}/${pageId}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function runBuilder() {
|
||||
deleteTmpDir();
|
||||
|
||||
createTmpDir();
|
||||
|
||||
copyTemplateWebsite();
|
||||
|
||||
(async () => {
|
||||
await buildCustomerWebsite(
|
||||
"test1",
|
||||
readConfig("../dev-only/test-config.json")
|
||||
);
|
||||
await buildCustomerWebsite(
|
||||
"test2",
|
||||
readConfig("../dev-only/test-config2.json")
|
||||
);
|
||||
|
||||
console.log("build all customer websites success");
|
||||
console.log("DONT FORGET TO COPY THE FOLDERS TO NGINX");
|
||||
})();
|
||||
|
||||
//buildCustomerWebsite("test1", readConfig("./test-config.json"));
|
||||
//buildCustomerWebsite("test2", readConfig("./test-config2.json"));
|
||||
}
|
||||
|
||||
runBuilder();
|
|
@ -0,0 +1,8 @@
|
|||
const config = {
|
||||
tmpFolder: "./tmp",
|
||||
templateWebsiteFolder: "../locofy-hairdresser",
|
||||
customerWebsiteFolder: "../customer-websites",
|
||||
customerWebsiteDataFolder: "../customer-websites-data",
|
||||
};
|
||||
|
||||
export default config;
|
|
@ -0,0 +1,53 @@
|
|||
{
|
||||
"name": "builder",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "builder",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"fs-extra": "^11.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/fs-extra": {
|
||||
"version": "11.2.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz",
|
||||
"integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==",
|
||||
"dependencies": {
|
||||
"graceful-fs": "^4.2.0",
|
||||
"jsonfile": "^6.0.1",
|
||||
"universalify": "^2.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.14"
|
||||
}
|
||||
},
|
||||
"node_modules/graceful-fs": {
|
||||
"version": "4.2.11",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
||||
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ=="
|
||||
},
|
||||
"node_modules/jsonfile": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
|
||||
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
|
||||
"dependencies": {
|
||||
"universalify": "^2.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"graceful-fs": "^4.1.6"
|
||||
}
|
||||
},
|
||||
"node_modules/universalify": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
|
||||
"integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==",
|
||||
"engines": {
|
||||
"node": ">= 10.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "builder",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "KK-Innovation",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"fs-extra": "^11.2.0"
|
||||
}
|
||||
}
|
Reference in New Issue