Skip to content

Commit

Permalink
Fix build error
Browse files Browse the repository at this point in the history
  • Loading branch information
double-beep authored Dec 11, 2023
1 parent 7aa5a4f commit b5e64b9
Show file tree
Hide file tree
Showing 16 changed files with 366 additions and 573 deletions.
88 changes: 44 additions & 44 deletions dist/cli.d.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
import { PackageInfo } from ".";
declare type AnyFunc = (...args: any[]) => any;
declare type BaseArg<A extends AnyFunc | undefined> = {
short: string;
long: string;
description: string;
action?: A;
passed: boolean;
};
declare class Arg<A extends AnyFunc | undefined> implements BaseArg<A> {
short: string;
long: string;
description: string;
action?: A;
passed: boolean;
constructor(options: BaseArg<A>);
run(...args: Parameters<Exclude<A, undefined>>): any;
}
declare class SimpleArg<A extends AnyFunc | undefined> extends Arg<A> {
hasValue: false;
constructor(options: BaseArg<A>);
}
declare class ValueArg<A extends AnyFunc | undefined> extends Arg<A> {
hasValue: true;
defaultValue?: string;
value?: string;
constructor(options: BaseArg<A> & {
defaultValue?: string;
value?: string;
});
}
declare type ArgOptions = {
hasValue?: boolean;
defaultValue?: string;
action?: AnyFunc;
};
export declare type ArgsHash<A extends AnyFunc | undefined = AnyFunc> = {
[x: string]: SimpleArg<A> | ValueArg<A>;
};
export declare const showHelp: ({ description, name }: PackageInfo) => void;
export declare const addArg: (long: string, short: string, description: string, { hasValue, defaultValue, action }?: ArgOptions) => void;
export declare const parseArgs: (cliArgs: string[]) => ArgsHash;
export declare const getValueArg: <A extends AnyFunc | undefined = AnyFunc>(args: ArgsHash<A>, key: string) => ValueArg<A> | null;
export {};
import { PackageInfo } from ".";
type AnyFunc = (...args: any[]) => any;
type BaseArg<A extends AnyFunc | undefined> = {
short: string;
long: string;
description: string;
action?: A;
passed: boolean;
};
declare class Arg<A extends AnyFunc | undefined> implements BaseArg<A> {
short: string;
long: string;
description: string;
action?: A;
passed: boolean;
constructor(options: BaseArg<A>);
run(...args: Parameters<Exclude<A, undefined>>): any;
}
declare class SimpleArg<A extends AnyFunc | undefined> extends Arg<A> {
hasValue: false;
constructor(options: BaseArg<A>);
}
declare class ValueArg<A extends AnyFunc | undefined> extends Arg<A> {
hasValue: true;
defaultValue?: string;
value?: string;
constructor(options: BaseArg<A> & {
defaultValue?: string;
value?: string;
});
}
type ArgOptions = {
hasValue?: boolean;
defaultValue?: string;
action?: AnyFunc;
};
export type ArgsHash<A extends AnyFunc | undefined = AnyFunc> = {
[x: string]: SimpleArg<A> | ValueArg<A>;
};
export declare const showHelp: ({ description, name }: PackageInfo) => void;
export declare const addArg: (long: string, short: string, description: string, { hasValue, defaultValue, action }?: ArgOptions) => void;
export declare const parseArgs: (cliArgs: string[]) => ArgsHash;
export declare const getValueArg: <A extends AnyFunc | undefined = AnyFunc>(args: ArgsHash<A>, key: string) => ValueArg<A> | null;
export {};
144 changes: 72 additions & 72 deletions dist/cli.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getValueArg = exports.parseArgs = exports.addArg = exports.showHelp = void 0;
const utils_1 = require("./utils");
class Arg {
constructor(options) {
Object.assign(this, options);
}
run(...args) {
const { action } = this;
return action === null || action === void 0 ? void 0 : action.apply(this, args);
}
}
class SimpleArg extends Arg {
constructor(options) {
super(options);
this.hasValue = false;
}
}
class ValueArg extends Arg {
constructor(options) {
super(options);
this.hasValue = true;
Object.assign(this, options);
}
}
const args = [];
const showHelp = ({ description, name }) => {
const { packageName } = (0, utils_1.parseName)(name);
const describedArgs = args.reduce((acc, { description, long, short }) => `${acc}-${short}, --${long}\t\t${description}\n`, "");
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getValueArg = exports.parseArgs = exports.addArg = exports.showHelp = void 0;
const utils_1 = require("./utils");
class Arg {
constructor(options) {
Object.assign(this, options);
}
run(...args) {
const { action } = this;
return action === null || action === void 0 ? void 0 : action.apply(this, args);
}
}
class SimpleArg extends Arg {
constructor(options) {
super(options);
this.hasValue = false;
}
}
class ValueArg extends Arg {
constructor(options) {
super(options);
this.hasValue = true;
Object.assign(this, options);
}
}
const args = [];
const showHelp = ({ description, name }) => {
const { packageName } = (0, utils_1.parseName)(name);
const describedArgs = args.reduce((acc, { description, long, short }) => `${acc}-${short}, --${long}\t\t${description}\n`, "");
console.log(`
${description}
Usage: ${packageName} [options]
All Options:
${describedArgs}`);
};
exports.showHelp = showHelp;
args.push(new SimpleArg({
short: "h",
long: "help",
description: "show command help",
action: exports.showHelp,
passed: false,
}));
const addArg = (long, short, description, { hasValue, defaultValue, action } = {}) => {
const base = new Arg({
long,
short,
description,
action,
passed: false,
});
args.push(hasValue
? new ValueArg(Object.assign(Object.assign({}, base), { defaultValue, value: defaultValue }))
: new SimpleArg(base));
};
exports.addArg = addArg;
const parseArgs = (cliArgs) => {
const mappedToArgs = args.map((arg) => {
const { long, short } = arg;
const cliArgIdx = cliArgs.findIndex((cliArg) => cliArg === `--${long}` || cliArg === `-${short}`);
const passed = cliArgIdx !== -1;
const value = passed ? cliArgs[cliArgIdx + 1] : void 0;
const argVal = arg.hasValue
? new ValueArg(Object.assign(Object.assign({}, arg), { passed, value: value || arg.defaultValue || "" }))
: new SimpleArg(arg);
return [long, argVal];
});
return Object.fromEntries(mappedToArgs);
};
exports.parseArgs = parseArgs;
const getValueArg = (args, key) => {
const arg = args[key];
return arg.hasValue ? arg : null;
};
exports.getValueArg = getValueArg;
${describedArgs}`);
};
exports.showHelp = showHelp;
args.push(new SimpleArg({
short: "h",
long: "help",
description: "show command help",
action: exports.showHelp,
passed: false,
}));
const addArg = (long, short, description, { hasValue, defaultValue, action } = {}) => {
const base = new Arg({
long,
short,
description,
action,
passed: false,
});
args.push(hasValue
? new ValueArg(Object.assign(Object.assign({}, base), { defaultValue, value: defaultValue }))
: new SimpleArg(base));
};
exports.addArg = addArg;
const parseArgs = (cliArgs) => {
const mappedToArgs = args.map((arg) => {
const { long, short } = arg;
const cliArgIdx = cliArgs.findIndex((cliArg) => cliArg === `--${long}` || cliArg === `-${short}`);
const passed = cliArgIdx !== -1;
const value = passed ? cliArgs[cliArgIdx + 1] : void 0;
const argVal = arg.hasValue
? new ValueArg(Object.assign(Object.assign({}, arg), { passed, value: value || arg.defaultValue || "" }))
: new SimpleArg(arg);
return [long, argVal];
});
return Object.fromEntries(mappedToArgs);
};
exports.parseArgs = parseArgs;
const getValueArg = (args, key) => {
const arg = args[key];
return arg.hasValue ? arg : null;
};
exports.getValueArg = getValueArg;
4 changes: 2 additions & 2 deletions dist/contributors.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { PackagePerson } from ".";
export declare const formatContributors: (contributors: PackagePerson[]) => string;
import { PackagePerson } from ".";
export declare const formatContributors: (contributors: PackagePerson[]) => string;
28 changes: 14 additions & 14 deletions dist/contributors.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatContributors = void 0;
const formatters_1 = require("./formatters");
const utils_1 = require("./utils");
const formatContributors = (contributors) => {
return contributors
.map((c) => {
const { name, email, url } = (0, utils_1.parseAuthor)(c);
return `${name}${(0, formatters_1.formatEmail)(email)}${(0, formatters_1.formatUrl)(url)}`;
})
.join("<br>");
};
exports.formatContributors = formatContributors;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatContributors = void 0;
const formatters_1 = require("./formatters");
const utils_1 = require("./utils");
const formatContributors = (contributors) => {
return contributors
.map((c) => {
const { name, email, url } = (0, utils_1.parseAuthor)(c);
return `${name}${(0, formatters_1.formatEmail)(email)}${(0, formatters_1.formatUrl)(url)}`;
})
.join("<br>");
};
exports.formatContributors = formatContributors;
8 changes: 4 additions & 4 deletions dist/formatters.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export declare const formatEmail: (email?: string | undefined) => string;
export declare const formatUrl: (url?: string | undefined) => string;
export declare const formatMdRow: (title: string, value: string) => string;
export declare const formatImage: (url: string, alt?: string) => string;
export declare const formatEmail: (email?: string) => string;
export declare const formatUrl: (url?: string) => string;
export declare const formatMdRow: (title: string, value: string) => string;
export declare const formatImage: (url: string, alt?: string) => string;
24 changes: 12 additions & 12 deletions dist/formatters.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatImage = exports.formatMdRow = exports.formatUrl = exports.formatEmail = void 0;
const utils_1 = require("./utils");
const formatEmail = (email) => email ? `<br>${(0, utils_1.mdLink)(email, `mailto:${email}`)}` : "";
exports.formatEmail = formatEmail;
const formatUrl = (url) => url ? `<br>${(0, utils_1.mdLink)(url, url)}` : "";
exports.formatUrl = formatUrl;
const formatMdRow = (title, value) => `| ${(0, utils_1.scase)(title)} | ${value} |`;
exports.formatMdRow = formatMdRow;
const formatImage = (url, alt = url) => `!${(0, utils_1.mdLink)(alt, alt)}`;
exports.formatImage = formatImage;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatImage = exports.formatMdRow = exports.formatUrl = exports.formatEmail = void 0;
const utils_1 = require("./utils");
const formatEmail = (email) => email ? `<br>${(0, utils_1.mdLink)(email, `mailto:${email}`)}` : "";
exports.formatEmail = formatEmail;
const formatUrl = (url) => url ? `<br>${(0, utils_1.mdLink)(url, url)}` : "";
exports.formatUrl = formatUrl;
const formatMdRow = (title, value) => `| ${(0, utils_1.scase)(title)} | ${value} |`;
exports.formatMdRow = formatMdRow;
const formatImage = (url, alt = url) => `!${(0, utils_1.mdLink)(alt, alt)}`;
exports.formatImage = formatImage;
60 changes: 30 additions & 30 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
export declare type PackagePerson = string | {
name: string;
email?: string;
url?: string;
};
export declare type PackageInfo = {
author: PackagePerson;
contributors?: PackagePerson[];
license?: string;
homepage: string;
name: string;
version: `${number}.${number}.${number}`;
description: string;
bugs: {
url: string;
};
repository: {
type: "git" | "https";
url: string;
};
};
declare type GeneratorOptions = {
about?: string;
direct?: boolean;
output?: string;
package?: string;
screenshot?: string;
};
declare const generate: ({ direct, output, package: pkg, about, screenshot }: GeneratorOptions) => Promise<string>;
export { generate };
export type PackagePerson = string | {
name: string;
email?: string;
url?: string;
};
export type PackageInfo = {
author: PackagePerson;
contributors?: PackagePerson[];
license?: string;
homepage: string;
name: string;
version: `${number}.${number}.${number}`;
description: string;
bugs: {
url: string;
};
repository: {
type: "git" | "https";
url: string;
};
};
type GeneratorOptions = {
about?: string;
direct?: boolean;
output?: string;
package?: string;
screenshot?: string;
};
declare const generate: ({ direct, output, package: pkg, about, screenshot }: GeneratorOptions) => Promise<string>;
export { generate };
2 changes: 1 addition & 1 deletion dist/license.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export declare const formatLicense: (license?: string | undefined) => string;
export declare const formatLicense: (license?: string) => string;
20 changes: 10 additions & 10 deletions dist/license.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatLicense = void 0;
const utils_1 = require("./utils");
const formatLicense = (license) => {
return license
? (0, utils_1.mdLink)(license, `https://spdx.org/licenses/${license}`)
: `Not adopted (see ${(0, utils_1.mdLink)("GitHub default grant", "https://docs.github.com/en/github/site-policy/github-terms-of-service#5-license-grant-to-other-users")})`;
};
exports.formatLicense = formatLicense;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatLicense = void 0;
const utils_1 = require("./utils");
const formatLicense = (license) => {
return license
? (0, utils_1.mdLink)(license, `https://spdx.org/licenses/${license}`)
: `Not adopted (see ${(0, utils_1.mdLink)("GitHub default grant", "https://docs.github.com/en/github/site-policy/github-terms-of-service#5-license-grant-to-other-users")})`;
};
exports.formatLicense = formatLicense;
Loading

0 comments on commit b5e64b9

Please sign in to comment.