Skip to content

Commit

Permalink
fix: refactor scripts import in the create-bison-app script into util…
Browse files Browse the repository at this point in the history
… file
  • Loading branch information
kgajera committed Jul 16, 2021
1 parent 516e69b commit e3d87b0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
7 changes: 2 additions & 5 deletions packages/create-bison-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const Listr = require("listr");
const nodegit = require("nodegit");
const ejs = require("ejs");
const color = require("chalk");
const { BISON_DEV_APP_VARIABLES_FILE } = require("./scripts/createDevAppAndStartServer");
const { copyFiles } = require("./tasks/copyFiles");
const { saveDevAppVariables } = require("./utils/devAppVariables");
const { version: bisonVersion } = require("./package.json");

module.exports = async ({ name, ...answers }) => {
Expand Down Expand Up @@ -144,10 +144,7 @@ module.exports = async ({ name, ...answers }) => {
task: async () => {
// Save variables to file so template directory can be watched
// and render templates again using same variables
await fs.promises.writeFile(
path.join(targetFolder, BISON_DEV_APP_VARIABLES_FILE),
JSON.stringify(variables, null, 2)
);
await saveDevAppVariables(targetFolder, variables);
},
},
]);
Expand Down
11 changes: 2 additions & 9 deletions packages/create-bison-app/scripts/createDevAppAndStartServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const { startServer } = require("../scripts/startServer");
const { templateFolder } = require("../tasks/copyFiles");
const { cleanTemplateDestPath } = require("../utils/copyDirectoryWithTemplate");
const { copyWithTemplate } = require("../utils/copyWithTemplate");
const { getDevAppVariables } = require("../utils/devAppVariables");

const BISON_DEV_APP_NAME = "bison-dev-app";
const BISON_DEV_APP_VARIABLES_FILE = "bison.json";

async function init() {
const distPath = path.join(__dirname, "..", "dist");
Expand Down Expand Up @@ -40,10 +40,7 @@ async function init() {
await createTemplateSymlinks(devAppPath);
}

const templateVariables = require(path.join(
devAppPath,
BISON_DEV_APP_VARIABLES_FILE
));
const templateVariables = getDevAppVariables(devAppPath);

const copyFile = async (src) => {
const relativeSrc = src.replace(templateFolder, "");
Expand Down Expand Up @@ -111,7 +108,3 @@ async function removeTemplateSymlinks() {
if (require.main === module) {
init();
}

module.exports = {
BISON_DEV_APP_VARIABLES_FILE,
};
23 changes: 23 additions & 0 deletions packages/create-bison-app/utils/devAppVariables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const fs = require("fs");
const path = require("path");

const BISON_DEV_APP_VARIABLES_FILE = "bison.json";

function getDevAppVariables(appPath) {
return require(path.join(
appPath,
BISON_DEV_APP_VARIABLES_FILE
));
}

async function saveDevAppVariables(appPath, variables) {
await fs.promises.writeFile(
path.join(appPath, BISON_DEV_APP_VARIABLES_FILE),
JSON.stringify(variables, null, 2)
);
}

module.exports = {
getDevAppVariables,
saveDevAppVariables
};

0 comments on commit e3d87b0

Please sign in to comment.