Skip to content
Commits on Source (10)
{
"name": "cyanprint",
"version": "0.13.11",
"version": "0.13.12",
"description": "CyanPrint is a scaffolding CLI for people to create templates or blueprints to scaffold commonly used ",
"main": "dist/cyan.js",
"license": "MIT",
......@@ -31,10 +31,12 @@
"dependencies": {
"@kirinnee/core": "^0.7.0",
"@kirinnee/objex": "^0.0.3",
"@types/delete-empty": "^2.0.0",
"@types/node-fetch": "^2.3.2",
"chalk": "^2.4.1",
"cli-progress": "^2.1.0",
"commander": "^2.19.0",
"delete-empty": "^3.0.0",
"fs-extra": "^7.0.1",
"glob": "^7.1.3",
"graceful-fs": "^4.1.11",
......@@ -57,7 +59,7 @@
"@types/rimraf": "^2.0.2",
"@types/webpack": "^4.4.17",
"chai": "^4.2.0",
"mocha": "^5.2.0",
"mocha": "^7.1.1",
"mocha-junit-reporter": "^1.23.1",
"nyc": "^14.1.1",
"terser-webpack-plugin": "^1.1.0",
......
......@@ -50,8 +50,8 @@ module.exports = async function (name, chalk, inquirer, autoInquirer, autoMap, e
{cmd: ["echo", "hey you 2!"]},
{cmd: ["echo", "hey you 3!"]},
],
globs: {root: ".", pattern: "**/*.*", ignore: ""},
npm: name,
globs: {root: ".", pattern: "**/*.*", ignore: "**/Ignored folder/**/*.*"},
npm: false,
docs: {
data: {
author: "kirinnee",
......
......@@ -2,60 +2,66 @@ import {Cyan, CyanSafe} from "../TargetUtil/CyanResponse";
import {Core} from "@kirinnee/core";
class CyanParser {
private readonly core;
constructor(core: Core) {
this.core = core;
}
Save(cyan: Cyan): CyanSafe {
let def: CyanSafe = {
docs: {
data: {},
usage: {license: false, git: false, readme: false, contributing: false, semVer: false}
},
npm: null,
globs: [],
variable: {},
flags: {},
guid: [],
commands: [],
};
if (cyan.docs != null) def.docs = cyan.docs;
if (cyan.npm != null) {
if (typeof cyan.npm === "string") {
def.npm = cyan.npm;
} else {
def.npm = "./";
}
}
if (cyan.globs != null) {
if (Array.isArray(cyan.globs)) {
def.globs = cyan.globs;
} else {
def.globs = [cyan.globs];
}
}
if (cyan.variable != null) def.variable = cyan.variable;
if (cyan.flags != null) def.flags = cyan.flags;
if (cyan.comments != null) {
if (Array.isArray(cyan.comments)) {
def.comments = cyan.comments
} else {
def.comments = [cyan.comments]
}
}
if (cyan.guid != null) {
def.guid = cyan.guid;
}
if (cyan.commands != null) {
def.commands = this.core.WrapArray(cyan.commands);
}
return def;
}
private readonly core;
constructor(core: Core) {
this.core = core;
}
Save(cyan: Cyan): CyanSafe {
let def: CyanSafe = {
docs: {
data: {},
usage: {license: false, git: false, readme: false, contributing: false, semVer: false}
},
npm: null,
globs: [],
variable: {},
flags: {},
guid: [],
commands: [],
};
if (cyan.docs != null) def.docs = cyan.docs;
if (cyan.npm !== null) {
if (typeof cyan.npm === "string") {
def.npm = cyan.npm;
} else if (cyan.npm === true) {
def.npm = "./";
}
}
if (cyan.globs != null) {
if (!Array.isArray(cyan.globs)) {
cyan.globs = [cyan.globs];
}
def.globs = cyan.globs
.Map(({root, pattern, ignore}) =>
Array.isArray(pattern) ?
pattern.Map(x => {
return {root, ignore, pattern: x}
}) :
[{root, pattern, ignore}]
).Flatten();
}
if (cyan.variable != null) def.variable = cyan.variable;
if (cyan.flags != null) def.flags = cyan.flags;
if (cyan.comments != null) {
if (Array.isArray(cyan.comments)) {
def.comments = cyan.comments
} else {
def.comments = [cyan.comments]
}
}
if (cyan.guid != null) {
def.guid = cyan.guid;
}
if (cyan.commands != null) {
def.commands = this.core.WrapArray(cyan.commands);
}
return def;
}
}
export {CyanParser};
interface IAutoMapper {
/**
* Overwrite the to object's value with the from object's value
* @param from - the from object
* @param to - the to object
* @constructor
*/
Overwrite(from: object, to: object): object
/**
* Join multiple object into a single object
* @param b - any amount of objects
* @constructor
*/
JoinObjects(...b: object[]): object;
/**
* Finds the first flag that is true in the flag object, and using that flag key, find the value in the map object
* @param map - the map of string to string
* @param flags - the flag map of string top boolean
* @constructor
*/
ReverseLoopUp(map: object, flags: object): string;
/**
* Overwrite the to object's value with the from object's value
* @param from - the from object
* @param to - the to object
* @constructor
*/
Overwrite(from: object, to: object): object
/**
* Join multiple object into a single object
* @param b - any amount of objects
* @constructor
*/
JoinObjects(...b: object[]): object;
/**
* Finds the first flag that is true in the flag object, and using that flag key, find the value in the map object
* @param map - the map of string to string
* @param flags - the flag map of string top boolean
* @constructor
*/
ReverseLoopUp(map: object, flags: object): string;
}
interface IAutoInquire {
/**
* Ask a yes-no question, returns a boolean after user answers.
* @param question the question to ask
* @param yes The Yes answer, if not filled, will default to "Yes"
* @param no the No answer, if not filled will default to "No"
* @constructor
*/
InquirePredicate(question: string, yes?: string, no?: string): Promise<boolean>;
/**
* Choose to inquire which documents the user need
* @param docList - the documents they need
* @constructor
*/
InquireDocument(docList: DocQuestions): Promise<Documentation>;
/**
* To ask for license, return a license object
* @param inquireAuthor whether to as for author for license
* @param inquireYear whether to ask for year for license
* @constructor
*/
InquireLicense(inquireAuthor?: boolean, inquireYear?: boolean): Promise<License>;
/**
* Converts a object of key -> string or [string,string] mapping into a series of questions,
* using the key as the question (unless the value is an array of two strings, in that case,
* it will use the 2nd value of the array) and the value (first value of array) as the default
* value, and return an object with answers from the user
* @param object the key -> string object
* @constructor
*/
InquireInput(object: object): Promise<object>;
/**
* Converts a object with string -> string into a checkbox question. The options which are
* checked will become true, while the rest will be false.
* @param flags - the string->string object to be converted to string->boolean object after the prompt
* @param question - the question to ask the user
* @constructor
*/
InquireAsCheckBox(flags: object, question: string): Promise<object>;
/**
* Converts object with string -> string into a MCQ. The only option selected will become have value of
* true, while every other field will have a false value.
* @param flags - the string->string object to be converted to string->boolean object after the prompt
* @param question - the question to ask the user
* @constructor
*/
InquireAsList(flags: object, question: string): Promise<object>;
/**
* Uses each flag value in the flag object as a yes or no question, and convert the value to true
* if user answers yes, and false if no
* @param flags - the string->string object to be converted to string->boolean object after the prompt
* @constructor
*/
InquireAsPredicate(flags: object): Promise<object>;
/**
* Ask a yes-no question, returns a boolean after user answers.
* @param question the question to ask
* @param yes The Yes answer, if not filled, will default to "Yes"
* @param no the No answer, if not filled will default to "No"
* @constructor
*/
InquirePredicate(question: string, yes?: string, no?: string): Promise<boolean>;
/**
* Choose to inquire which documents the user need
* @param docList - the documents they need
* @constructor
*/
InquireDocument(docList: DocQuestions): Promise<Documentation>;
/**
* To ask for license, return a license object
* @param inquireAuthor whether to as for author for license
* @param inquireYear whether to ask for year for license
* @constructor
*/
InquireLicense(inquireAuthor?: boolean, inquireYear?: boolean): Promise<License>;
/**
* Converts a object of key -> string or [string,string] mapping into a series of questions,
* using the key as the question (unless the value is an array of two strings, in that case,
* it will use the 2nd value of the array) and the value (first value of array) as the default
* value, and return an object with answers from the user
* @param object the key -> string object
* @constructor
*/
InquireInput(object: object): Promise<object>;
/**
* Converts a object with string -> string into a checkbox question. The options which are
* checked will become true, while the rest will be false.
* @param flags - the string->string object to be converted to string->boolean object after the prompt
* @param question - the question to ask the user
* @constructor
*/
InquireAsCheckBox(flags: object, question: string): Promise<object>;
/**
* Converts object with string -> string into a MCQ. The only option selected will become have value of
* true, while every other field will have a false value.
* @param flags - the string->string object to be converted to string->boolean object after the prompt
* @param question - the question to ask the user
* @constructor
*/
InquireAsList(flags: object, question: string): Promise<object>;
/**
* Uses each flag value in the flag object as a yes or no question, and convert the value to true
* if user answers yes, and false if no
* @param flags - the string->string object to be converted to string->boolean object after the prompt
* @constructor
*/
InquireAsPredicate(flags: object): Promise<object>;
}
interface Command {
cmd: string[];
dir?: string;
cmd: string[];
dir?: string;
}
interface Cyan {
globs: Glob[] | Glob,
variable?: object,
flags?: object,
guid?: string[],
npm?: boolean | string;
docs?: Documentation;
comments?: string[] | string;
commands?: Command[] | Command;
globs: Glob[] | Glob,
variable?: object,
flags?: object,
guid?: string[],
npm?: boolean | string;
docs?: Documentation;
comments?: string[] | string;
commands?: Command[] | Command;
}
interface CyanSafe {
globs: Glob[];
variable: object;
flags: object;
guid: string[];
npm: string | null;
docs: Documentation;
commands: Command[];
comments?: string[];
globs: Glob[];
variable: object;
flags: object;
guid: string[];
npm: string | null;
docs: Documentation;
commands: Command[];
comments?: string[];
}
interface DocData {
author?: string;
email?: string;
gitURL?: string;
licenseType?: string;
years?: string;
projectName?: string;
description?: string;
author?: string;
email?: string;
gitURL?: string;
licenseType?: string;
years?: string;
projectName?: string;
description?: string;
}
interface DocUsage {
semVer: boolean;
contributing: boolean;
readme: boolean;
git: boolean;
license: boolean;
semVer: boolean;
contributing: boolean;
readme: boolean;
git: boolean;
license: boolean;
}
interface DocQuestions {
semVer?: boolean;
contributing?: boolean;
readme?: boolean;
git?: boolean;
license?: boolean;
semVer?: boolean;
contributing?: boolean;
readme?: boolean;
git?: boolean;
license?: boolean;
}
interface Documentation {
data: DocData;
usage: DocUsage;
data: DocData;
usage: DocUsage;
}
interface Git {
username: string;
email: string;
remote: string;
username: string;
email: string;
remote: string;
}
interface Glob {
root: string,
pattern: string,
ignore: string | string[]
root: string,
pattern: string[] | string,
ignore: string | string[]
}
interface Contributing {
author: string;
email: string;
author: string;
email: string;
}
interface License {
type: "GPL-3.0" | "MIT" | "ISC" | "Apache-2.0",
author: string;
year: string;
type: "GPL-3.0" | "MIT" | "ISC" | "Apache-2.0",
author: string;
year: string;
}
interface IExecute {
/**
* Call another file that exports a cyan.config function,
* @param p the path to the file, relative to this file
*/
call(p: string): Promise<Cyan>;
/**
* Execute a shell command
* @param p Executes a shell command
*/
run(p: string): Promise<void>;
/**
* Call another file that exports a cyan.config function,
* @param p the path to the file, relative to this file
*/
call(p: string): Promise<Cyan>;
/**
* Execute a shell command
* @param p Executes a shell command
*/
run(p: string): Promise<void>;
}
export {
Git,
Glob,
Cyan,
DocUsage,
DocData,
DocQuestions,
Documentation,
Contributing,
CyanSafe,
License,
IAutoInquire,
IAutoMapper,
IExecute
Git,
Glob,
Cyan,
DocUsage,
DocData,
DocQuestions,
Documentation,
Contributing,
CyanSafe,
License,
IAutoInquire,
IAutoMapper,
IExecute
};
......@@ -35,6 +35,7 @@ import inquirer, {Inquirer} from "inquirer";
import {spawn} from "child_process";
import {Dependency} from "./Depedency";
import {GuidGenerator} from "./classLibrary/GuidGenerator";
import deleteEmpty from "delete-empty";
export async function GenerateTemplate(dep: Dependency, templatePath: string, folderName: string, settings: CyanSafe, copyNode: boolean): Promise<string> {
......@@ -61,7 +62,6 @@ export async function GenerateTemplate(dep: Dependency, templatePath: string, fo
let globFactory: GlobFactory = new GlobFactory(dep.util, fileFactory);
//Create all relevant parsing strategy
let strategies: ParsingStrategy[] = [
new GuidResolver(dep.core, new GuidGenerator(dep.core)),
......@@ -85,7 +85,7 @@ export async function GenerateTemplate(dep: Dependency, templatePath: string, fo
//Obtain all globs
let files: FileSystemInstance[] = settings.globs.Map((g: Glob) => globFactory.GenerateFiles(g.root, g.pattern, g.ignore)).Flatten();
let files: FileSystemInstance[] = settings.globs.Map((g: Glob) => globFactory.GenerateFiles(g.root, g.pattern as string, g.ignore)).Flatten();
if (!copyNode) files = files.Where((f: FileSystemInstance) => !f.sourceAbsolutePath.includes("node_modules"));
//remove package.lock
......@@ -180,6 +180,13 @@ export async function GenerateTemplate(dep: Dependency, templatePath: string, fo
}
}
}
console.log(chalk.cyanBright("Clearing residue directories..."));
const deleted = await deleteEmpty(folderName);
if (deleted)
console.log(chalk.greenBright(`Deleted ${deleted.join(", ")}`));
else
console.log(chalk.greenBright("No residue directories found!"));
return chalk.greenBright("Complete~!!");
}
......@@ -196,6 +203,7 @@ export async function Interrogate(dep: Dependency, autoInquirer: IAutoInquire, t
let Template: (nameFolder: string, c: Chalk, inq: Inquirer, autoInquire: IAutoInquire, autoMap: IAutoMapper, execute: Execute) => Promise<Cyan>
= eval(`require("${relConfigPath.ReplaceAll("\\\\", "/")}")`);
let rawSettings: Cyan = await Template(folderName.ReplaceAll("\\\\", "/").split('/').Last()!, chalk, inquirer, autoInquirer, dep.autoMapper, execute);
// Escape and normalize raw settings to "safe"
return cyanSafe.Save(rawSettings);
}
......
interface IAutoMapper {
/**
* Overwrite the to object's value with the from object's value
* @param from - the from object
* @param to - the to object
* @constructor
*/
Overwrite(from: object, to: object): object
/**
* Join multiple object into a single object
* @param b - any amount of objects
* @constructor
*/
JoinObjects(...b: object[]): object;
/**
* Finds the first flag that is true in the flag object, and using that flag key, find the value in the map object
* @param map - the map of string to string
* @param flags - the flag map of string top boolean
* @constructor
*/
ReverseLoopUp(map: object, flags: object): string;
/**
* Overwrite the to object's value with the from object's value
* @param from - the from object
* @param to - the to object
* @constructor
*/
Overwrite(from: object, to: object): object
/**
* Join multiple object into a single object
* @param b - any amount of objects
* @constructor
*/
JoinObjects(...b: object[]): object;
/**
* Finds the first flag that is true in the flag object, and using that flag key, find the value in the map object
* @param map - the map of string to string
* @param flags - the flag map of string top boolean
* @constructor
*/
ReverseLoopUp(map: object, flags: object): string;
}
interface IAutoInquire {
/**
* Ask a yes-no question, returns a boolean after user answers.
* @param question the question to ask
* @param yes The Yes answer, if not filled, will default to "Yes"
* @param no the No answer, if not filled will default to "No"
* @constructor
*/
InquirePredicate(question: string, yes?: string, no?: string): Promise<boolean>;
/**
* Choose to inquire which documents the user need
* @param docList - the documents they need
* @constructor
*/
InquireDocument(docList: DocQuestions): Promise<Documentation>;
/**
* To ask for license, return a license object
* @param inquireAuthor whether to as for author for license
* @param inquireYear whether to ask for year for license
* @constructor
*/
InquireLicense(inquireAuthor?: boolean, inquireYear?: boolean): Promise<License>;
/**
* Converts a object of key -> string or [string,string] mapping into a series of questions,
* using the key as the question (unless the value is an array of two strings, in that case,
* it will use the 2nd value of the array) and the value (first value of array) as the default
* value, and return an object with answers from the user
* @param object the key -> string object
* @constructor
*/
InquireInput(object: object): Promise<object>;
/**
* Converts a object with string -> string into a checkbox question. The options which are
* checked will become true, while the rest will be false.
* @param flags - the string->string object to be converted to string->boolean object after the prompt
* @param question - the question to ask the user
* @constructor
*/
InquireAsCheckBox(flags: object, question: string): Promise<object>;
/**
* Converts object with string -> string into a MCQ. The only option selected will become have value of
* true, while every other field will have a false value.
* @param flags - the string->string object to be converted to string->boolean object after the prompt
* @param question - the question to ask the user
* @constructor
*/
InquireAsList(flags: object, question: string): Promise<object>;
/**
* Uses each flag value in the flag object as a yes or no question, and convert the value to true
* if user answers yes, and false if no
* @param flags - the string->string object to be converted to string->boolean object after the prompt
* @constructor
*/
InquireAsPredicate(flags: object): Promise<object>;
/**
* Ask a yes-no question, returns a boolean after user answers.
* @param question the question to ask
* @param yes The Yes answer, if not filled, will default to "Yes"
* @param no the No answer, if not filled will default to "No"
* @constructor
*/
InquirePredicate(question: string, yes?: string, no?: string): Promise<boolean>;
/**
* Choose to inquire which documents the user need
* @param docList - the documents they need
* @constructor
*/
InquireDocument(docList: DocQuestions): Promise<Documentation>;
/**
* To ask for license, return a license object
* @param inquireAuthor whether to as for author for license
* @param inquireYear whether to ask for year for license
* @constructor
*/
InquireLicense(inquireAuthor?: boolean, inquireYear?: boolean): Promise<License>;
/**
* Converts a object of key -> string or [string,string] mapping into a series of questions,
* using the key as the question (unless the value is an array of two strings, in that case,
* it will use the 2nd value of the array) and the value (first value of array) as the default
* value, and return an object with answers from the user
* @param object the key -> string object
* @constructor
*/
InquireInput(object: object): Promise<object>;
/**
* Converts a object with string -> string into a checkbox question. The options which are
* checked will become true, while the rest will be false.
* @param flags - the string->string object to be converted to string->boolean object after the prompt
* @param question - the question to ask the user
* @constructor
*/
InquireAsCheckBox(flags: object, question: string): Promise<object>;
/**
* Converts object with string -> string into a MCQ. The only option selected will become have value of
* true, while every other field will have a false value.
* @param flags - the string->string object to be converted to string->boolean object after the prompt
* @param question - the question to ask the user
* @constructor
*/
InquireAsList(flags: object, question: string): Promise<object>;
/**
* Uses each flag value in the flag object as a yes or no question, and convert the value to true
* if user answers yes, and false if no
* @param flags - the string->string object to be converted to string->boolean object after the prompt
* @constructor
*/
InquireAsPredicate(flags: object): Promise<object>;
}
interface Cyan {
globs: Glob[] | Glob,
variable?: object,
flags?: object,
guid?: string[],
npm?: boolean | string;
docs?: Documentation;
comments?: string[] | string;
globs: Glob[] | Glob,
variable?: object,
flags?: object,
guid?: string[],
npm?: boolean | string;
docs?: Documentation;
comments?: string[] | string;
}
interface CyanSafe {
globs: Glob[],
variable: object;
flags: object;
guid: string[],
npm: string | null;
docs: Documentation,
comments?: string[]
globs: Glob[],
variable: object;
flags: object;
guid: string[],
npm: string | null;
docs: Documentation,
comments?: string[]
}
interface DocData {
author?: string;
email?: string;
gitURL?: string;
licenseType?: string;
years?: string;
projectName?: string;
description?: string;
author?: string;
email?: string;
gitURL?: string;
licenseType?: string;
years?: string;
projectName?: string;
description?: string;
}
interface DocUsage {
semVer: boolean;
contributing: boolean;
readme: boolean;
git: boolean;
license: boolean;
semVer: boolean;
contributing: boolean;
readme: boolean;
git: boolean;
license: boolean;
}
interface DocQuestions {
semVer?: boolean;
contributing?: boolean;
readme?: boolean;
git?: boolean;
license?: boolean;
semVer?: boolean;
contributing?: boolean;
readme?: boolean;
git?: boolean;
license?: boolean;
}
interface Documentation {
data: DocData;
usage: DocUsage;
data: DocData;
usage: DocUsage;
}
interface Git {
username: string;
email: string;
remote: string;
username: string;
email: string;
remote: string;
}
interface Glob {
root: string,
pattern: string,
ignore: string | string[]
root: string,
pattern: string[] | string,
ignore: string | string[]
}
interface Contributing {
author: string;
email: string;
author: string;
email: string;
}
interface License {
type: "GPL-3.0" | "MIT" | "ISC" | "Apache-2.0",
author: string;
year: string;
type: "GPL-3.0" | "MIT" | "ISC" | "Apache-2.0",
author: string;
year: string;
}
interface IExecute {
/**
* Call another file that exports a cyan.config function,
* @param p the path to the file, relative to this file
*/
call(p: string): Promise<Cyan>;
/**
* Execute a shell command
* @param p Executes a shell command
*/
run(p: string): Promise<void>;
/**
* Call another file that exports a cyan.config function,
* @param p the path to the file, relative to this file
*/
call(p: string): Promise<Cyan>;
/**
* Execute a shell command
* @param p Executes a shell command
*/
run(p: string): Promise<void>;
}
export {
Git,
Glob,
Cyan,
DocUsage,
DocData,
DocQuestions,
Documentation,
Contributing,
CyanSafe,
License,
IAutoInquire,
IAutoMapper,
IExecute
Git,
Glob,
Cyan,
DocUsage,
DocData,
DocQuestions,
Documentation,
Contributing,
CyanSafe,
License,
IAutoInquire,
IAutoMapper,
IExecute
};
This diff is collapsed.