Skip to content

Commit

Permalink
tag array
Browse files Browse the repository at this point in the history
  • Loading branch information
zuiwuchang committed Jan 25, 2021
1 parent 20352e9 commit aa6958c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 21 deletions.
17 changes: 10 additions & 7 deletions dist/command/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,21 @@ function initCommand(parent, path) {
ts.forEach(function (t) {
cmd.command(t.filename)
.description(t.description)
.option("-n, --name []", "project name").option("-p, --package []", "package name").option("-t, --tag []", "code generate tag").option("--list-tag", "list supported tag").action(function () {
.option("-n, --name []", "project name").option("-p, --package []", "package name").option("-t, --tag [tags...]", "code generate tag").option("--list-tag", "list supported tag").action(function () {
var opts = this.opts();
if (opts["listTag"]) {
console.log(t.tag);
return;
}
var tag = opts["tag"];
if (typeof tag === "string") {
tag = tag.trim();
}
else {
tag = "";
var tag = new Array();
var tags = opts["tag"];
if (Array.isArray(tags)) {
for (var i = 0; i < tags.length; i++) {
var element = tags[i];
if (typeof element === "string") {
tag.push(element);
}
}
}
var context = new context_1.Context(opts["package"], opts["name"], tag, path_2.join(t.dirname, t.filename), process.cwd());
t.generate(context);
Expand Down
6 changes: 3 additions & 3 deletions dist/utils/context.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/// <reference types="node" />
import { Stats } from "fs";
export declare class Context {
readonly tag: string;
readonly tag: Array<string>;
readonly root: string;
readonly output: string;
readonly data: Map<string, any>;
readonly version = "1.0.2";
readonly version = "1.0.3";
private pkg_;
private name_;
get pkg(): string;
get name(): string;
constructor(pkg: string, name: string, tag: string, root: string, output: string);
constructor(pkg: string, name: string, tag: Array<string>, root: string, output: string);
serve(renderFile: (name: string, src: string, stat: Stats) => void | Promise<undefined>, renderDir: (name: string, src: string, stat: Stats) => void | Promise<undefined>): Promise<void>;
private _name;
private _serve;
Expand Down
2 changes: 1 addition & 1 deletion dist/version.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export declare const Version = "1.0.2";
export declare const Version = "1.0.3";
2 changes: 1 addition & 1 deletion dist/version.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Version = void 0;
exports.Version = '1.0.2';
exports.Version = '1.0.3';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@king011/jsgenerate",
"version": "1.0.2",
"version": "1.0.3",
"description": "generate code by js and art-template",
"bin": "dist/main.js",
"scripts": {
Expand Down
17 changes: 11 additions & 6 deletions src/command/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Command } from "commander";
import { listTemplates } from "../utils/path";
import { Context } from "../utils/context";
import { join } from "path";
import { isArray } from "util";

export async function initCommand(parent: Command, path: string) {
const cmd = parent.command(`init`)
Expand Down Expand Up @@ -33,7 +34,7 @@ export async function initCommand(parent: Command, path: string) {
`project name`,
).option(`-p, --package []`,
`package name`,
).option(`-t, --tag []`,
).option(`-t, --tag [tags...]`,
`code generate tag`,
).option(`--list-tag`,
`list supported tag`,
Expand All @@ -43,11 +44,15 @@ export async function initCommand(parent: Command, path: string) {
console.log(t.tag)
return
}
let tag = opts["tag"]
if (typeof tag === "string") {
tag = tag.trim()
} else {
tag = ""
const tag = new Array<string>()
let tags = opts["tag"]
if (Array.isArray(tags)) {
for (let i = 0; i < tags.length; i++) {
const element = tags[i]
if (typeof element === "string") {
tag.push(element)
}
}
}
const context = new Context(
opts["package"], opts["name"],
Expand Down
2 changes: 1 addition & 1 deletion src/utils/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Context {
}
constructor(pkg: string,
name: string,
public readonly tag: string,
public readonly tag: Array<string>,
public readonly root: string,
public readonly output: string,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const Version = '1.0.2'
export const Version = '1.0.3'

0 comments on commit aa6958c

Please sign in to comment.