Skip to content

Commit

Permalink
feat: Add generate command
Browse files Browse the repository at this point in the history
Updating global json configuration ready
  • Loading branch information
wnvko committed Feb 16, 2018
1 parent 34591a9 commit 127c3f1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 32 deletions.
20 changes: 19 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,33 @@
{
"type": "node",
"request": "launch",
"name": "Launch Generate Template with aliases no name",
"name": "Launch Generate Template with aliases g t -g",
"cwd": "${workspaceRoot}/output",
"program": "${workspaceRoot}/bin/execute.js",
"console": "externalTerminal",
"preLaunchTask": "build",
"args": [
"g",
"t",
"-g"
],
},
{
"type": "node",
"request": "launch",
"name": "Launch Generate Template with all aliases",
"cwd": "${workspaceRoot}/output",
"program": "${workspaceRoot}/bin/execute.js",
"console": "externalTerminal",
"preLaunchTask": "build",
"args": [
"g",
"t",
"-n=alianato",
"-f=angular",
"-t=igx-ts",
"-s=false",
]
}
]
}
1 change: 0 additions & 1 deletion lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export async function run(args = null) {
newCommand.template = templateManager;
newCommand.builder.framework.choices = templateManager.getFrameworkIds();
add.templateManager = templateManager;
generate.templateManager = templateManager;

const yargsModule = args ? yargs(args) : yargs;

Expand Down
62 changes: 32 additions & 30 deletions lib/commands/generate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as path from "path";
import { Util } from "../Util";
import { ProjectConfig } from "./../ProjectConfig";
import { TemplateManager } from "../TemplateManager";
import { utimes } from "fs-extra";
import { default as config } from "./config";

const command = {
// tslint:disable:object-literal-sort-keys
Expand All @@ -16,31 +16,32 @@ const command = {
command: "template [name] [framework] [type] [skip-config]",
aliases: ["t"],
desc: "Generates custom template",
builder: (yargs) => yargs
.options({
name: {
describe: "Template name.",
aliases: ["n"],
default: "custom-template",
type: "string"
},
framework: {
describe: "Framework name.",
aliases: ["f"],
default: "jquery",
type: "string"
},
type: {
describe: "Framework type.",
aliases: ["t"],
default: "js",
type: "string"
},
"skip-config": {
describe: "Skips adding to the config.",
type: "boolean"
}
}),
builder: {
name: {
describe: "Template name.",
alias: "n",
default: "custom-template",
type: "string"
},
framework: {
describe: "Framework name.",
alias: "f",
default: "jquery",
type: "string"
},
type: {
describe: "Framework type.",
alias: "t",
default: "js",
type: "string"
},
"skip-config": {
describe: "Skips adding to the config.",
alias: "s",
default: false,
type: "boolean"
}
},
handler: command.template
})
// at least one command is required
Expand Down Expand Up @@ -82,11 +83,12 @@ const command = {
Util.log(`Project Name: ${argv.name}, framework ${argv.framework}, type ${argv.type}`);
const promise = Util.processTemplates(templatesFolder, outDir, { "$(name)": argv.name, "$(framework)": argv.framework, "$(type)": argv.type, __name__: argv.name }, null);
promise.then((res) => {
if(res){
if (ProjectConfig.hasLocalConfig())
return Util.error("There is already an existing project.", "red");
if (res) {
if (argv.skipConfig == false) {
config.addHandler({ property: "customTemplates", value: "parth:" + outDir, global: true });
}
}
else{
else {
return Util.log("Project creation failed!");
}
}).catch((err) => {
Expand Down

0 comments on commit 127c3f1

Please sign in to comment.