Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create-app: take app directory as argument #1674

Merged
merged 3 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/xarc-create-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@babel/core": "^7.6.2",
"@babel/preset-env": "^7.6.2",
"babel-loader": "^8.0.6",
"chalker": "^1.2.0",
"lodash": "^4.17.15",
"opfs": "^1.1.1",
"prompts": "^2.3.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/xarc-create-app/src/check-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
const Fs = require("opfs");
const prompts = require("prompts");

async function checkDir() {
async function checkDir(dirName) {
const existDirFiles = await Fs.readdir(process.cwd());
if (existDirFiles.length > 0) {
const response = await prompts({
type: "confirm",
name: "overwrite",
message: "Your directory is not empty, write to it?"
message: `Your directory '${dirName}' is not empty, write to it?`
});

return response.overwrite;
Expand Down
19 changes: 16 additions & 3 deletions packages/xarc-create-app/src/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ const sortDeps = require("./sort-obj-keys");
const checkDir = require("./check-dir");
const makePkg = require("../template/_package");
const _ = require("lodash");
const prepareAppDir = require("./prep-app-dir");
const ck = require("chalker");

async function create() {
const dirOk = await checkDir();
const appDir = await prepareAppDir();
const dirOk = await checkDir(appDir);

if (!dirOk) {
console.log("bye");
console.log(`Not able to write to directory '${appDir}'. bye.`);
return;
}

Expand All @@ -28,7 +32,16 @@ async function create() {
shcmd.cp("-R", Path.join(srcDir, "_gitignore"), Path.resolve(".gitignore"));
shcmd.cp("-R", Path.join(srcDir, "README.md"), Path.resolve("README.md"));

console.log("created react/node webapp - please check README.md for info.");
console.log(ck`
Created react/node webapp in directory '${appDir}'. To start development, please run:

<cyan>cd ${appDir}
npm install
npm run dev</>

For more info, please check the README.md file.

`);
}

module.exports = create;
37 changes: 37 additions & 0 deletions packages/xarc-create-app/src/prep-app-dir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use strict";

const Fs = require("opfs");
const Path = require("path");

async function prepareAppDir() {
const appDirName = process.argv[2];
if (!appDirName) {
console.log(`
Usage: @xarc/create-app <app-directory>

- pass '.' to use current directory
`);
process.exit(1);
}

if (appDirName === ".") {
const dirName = Path.basename(process.cwd());
console.log(`Using current directory '${dirName}' to create @xarc/app`);
return dirName;
}

try {
await Fs.mkdir(appDirName);
} catch (err) {
if (err.code !== "EEXIST") {
console.log(`Failed to create app directory '${appDirName}'`);
process.exit(1);
}
}

process.chdir(appDirName);

return appDirName;
}

module.exports = prepareAppDir;
14 changes: 7 additions & 7 deletions packages/xarc-create-app/template/_package.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ module.exports = (base, merge) => {
npm: ">= 6"
},
dependencies: {
"@xarc/app": "^8.1.1",
"@xarc/app": "^8.1.5",
"@xarc/fastify-server": "^1.1.0",
react: "^16.13.1",
"react-dom": "^16.13.1",
"react-redux": "^7.2.0",
redux: "^4.0.5",
"subapp-react": "~0.0.18",
"subapp-redux": "^1.0.27",
"subapp-server": "^1.2.1"
"subapp-react": "~0.0.19",
"subapp-redux": "^1.0.28",
"subapp-server": "^1.2.2",
react: "^16.13.1",
redux: "^4.0.5"
},
devDependencies: {
"@xarc/app-dev": "^8.1.1"
"@xarc/app-dev": "^8.1.5"
}
};

Expand Down