Skip to content

Commit

Permalink
create --no_react and --noREact to use
Browse files Browse the repository at this point in the history
  • Loading branch information
icerove committed Oct 29, 2019
1 parent e358616 commit 79632a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 54 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ create-near-app path/to/your/new-awesome-app
```
Plain app:
```bash
create-near-app plain path/to/your/new-awesome-app
create-near-app --noReact(--no_react) path/to/your/new-awesome-app
```

If yarn is installed:
Expand All @@ -31,7 +31,7 @@ yarn create near-app path/to/your/new-awesome-app
```
Plain app:
```bash
yarn create near-app plain path/to/your/new-awesome-app
yarn create near-app --noReact(--no_react) path/to/your/new-awesome-app
```

## Caveats
Expand Down
70 changes: 18 additions & 52 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,25 @@ const exitOnError = async function(promise) {
}
}

const reactProject = {
command: '$0 [projectDir]',
const createProject = {
command: '$0 <projectDir>',
desc: 'create a new blank react project',
builder: (yargs) => yargs
builder: (yargs) => yargs
.option('projectDir', {
desc: 'project directory',
type: 'string',
required: true
}),
handler: (argv) => exitOnError(react_Project(argv))
handler: (argv) => exitOnError(create_Project(argv))
};

const newProject = {
command: 'plain [projectDir]',
desc: 'create a new blank project',
builder: (yargs) => yargs
.option('projectDir', {
desc: 'project directory',
type: 'string',
required:true
}),
handler: (argv) => exitOnError(new_Project(argv))
};

const react_Project = async function(options) {
const create_Project = async function(options) {
// Need to wait for the copy to finish, otherwise next tasks do not find files.
const projectDir = options.projectDir;
const sourceDir = __dirname + "/blank_react_project";
let sourceDir = __dirname + "/blank_react_project";
if(options.noReact){
sourceDir = __dirname + '/blank_project';
}
console.log(`Copying files to new project directory (${projectDir}) from template source (${sourceDir}).`);
const copyDirFn = () => {
return new Promise(resolve => {
Expand Down Expand Up @@ -69,40 +60,15 @@ const react_Project = async function(options) {
console.log('Copying project files complete.');
};

const new_Project = async function(options) {
// Need to wait for the copy to finish, otherwise next tasks do not find files.
const projectDir = options.projectDir;
const sourceDir = __dirname + '/blank_project';
console.log(`Copying files to new project directory (${projectDir}) from template source (${sourceDir}).`);
const copyDirFn = () => {
return new Promise(resolve => {
ncp (sourceDir, options.projectDir, response => resolve(response));
});};
await copyDirFn();
let path = projectDir + "/package.json";
let index = projectDir.lastIndexOf("/");
let name = index > 0
? projectDir.slice(index+1, )
: projectDir
fs.readFile(path,function(err, data){
if (err) {
throw 'could not read file: ' + err;
}
let json = JSON.parse(data)
json["name"] = name
fs.writeFile(path,JSON.stringify(json, null, 4),function(err) {
if (err) {
throw "error writing file: " + err;
}else {
console.log("wrote successfully!");
}
})
})
console.log('Copying project files complete.');
};

yargs
.command(newProject)
.command(reactProject)
.option('noReact',{
desc: 'create blank plain JS project',
type: 'boolean',
default: false
})
.alias({
'noReact': ['no_react']
})
.command(createProject)
.help()
.argv;

0 comments on commit 79632a9

Please sign in to comment.