-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add CRA Generator #4
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
YARN: "yarn", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use single quotes in JavaScript files. |
||
NPM: "npm", | ||
NPX: "npx", | ||
ADD: "add", | ||
INSTALL: "install", | ||
CREATE_REACT_APP: "create-react-app", | ||
REDUX: "redux", | ||
REACT_REDUX: "react-redux", | ||
MOBX: "mobx", | ||
STYLED_COMPONENTS: "styled-components", | ||
SCSS: "node-sass", | ||
LESS: "less", | ||
ROUTER: "react-router-dom", | ||
ENZYME: "enzyme", | ||
JEST: "jest" | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const spawn = require("../spawn"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use single quotes in JavaScript files. I think all of the uses in here should be single quotes. |
||
const path = require("path"); | ||
const { prompt } = require("enquirer"); | ||
const { NPX, CREATE_REACT_APP } = require("../constants.js"); | ||
|
||
module.exports = app => { | ||
app.task("create-react-app", async () => { | ||
let dest = app.options.name; | ||
if (!dest) { | ||
const answers = await prompt({ | ||
type: "text", | ||
name: "appName", | ||
message: "What would you like the app name to be?" | ||
}); | ||
dest = answers.appName; | ||
} | ||
await spawn(NPX, [CREATE_REACT_APP, dest]); | ||
}); | ||
|
||
app.task("create-react-app-templates", async () => { | ||
const dest = path.join(app.cwd, app.options.name); | ||
const answers = await prompt([ | ||
{ | ||
type: "text", | ||
name: "description", | ||
message: "What description would you like to use for your website?" | ||
}, | ||
{ | ||
type: "text", | ||
name: "title", | ||
message: "What title would you like to use for your website?" | ||
} | ||
]); | ||
|
||
return app | ||
.src("create-react-app/public/*.*", { | ||
cwd: path.join(__dirname, "../../templates") | ||
}) | ||
.pipe(app.renderFile("*", answers).on("error", console.error)) | ||
.pipe(app.conflicts(dest)) | ||
.pipe(app.dest(dest)); | ||
}); | ||
|
||
app.task("default", ["create-react-app", "create-react-app-templates"]); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use strict"; | ||
|
||
const spawn = require("child_process").spawn; | ||
|
||
const defaults = { | ||
stdio: "inherit", | ||
cwd: process.cwd() | ||
}; | ||
|
||
// simple wrapper around cli commands | ||
module.exports = async (cmd, args, options) => { | ||
return new Promise((resolve, reject) => { | ||
const cp = spawn(cmd, args, { ...defaults, ...options }); | ||
cp.on("error", reject); | ||
cp.on("close", code => { | ||
if (code > 0) { | ||
return reject(code); | ||
} | ||
resolve(code); | ||
}); | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,10 @@ | |
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"is-valid-app": "^0.3.0" | ||
"is-valid-app": "^0.3.0", | ||
"enquirer": "^2.3.2", | ||
"generate": "^0.14.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that |
||
"generate-project": "^1.0.0" | ||
}, | ||
"keywords": [ | ||
"generate", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta | ||
name="description" | ||
content="<%= description %>" | ||
/> | ||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
<title><%= title %></title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep arguments on the same line when calling functions like this.