simple-scaffold 1.6.0 → 1.7.0-develop.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -8
- package/cmd.js +3 -3
- package/cmd.js.map +1 -1
- package/config.d.ts +8 -0
- package/config.js +153 -0
- package/config.js.map +1 -0
- package/file.d.ts +38 -0
- package/file.js +161 -0
- package/file.js.map +1 -0
- package/logger.d.ts +13 -0
- package/logger.js +52 -0
- package/logger.js.map +1 -0
- package/package.json +2 -2
- package/parser.d.ts +14 -0
- package/parser.js +83 -0
- package/parser.js.map +1 -0
- package/scaffold.d.ts +2 -2
- package/scaffold.js +26 -37
- package/scaffold.js.map +1 -1
- package/types.d.ts +19 -2
- package/utils.d.ts +2 -68
- package/utils.js +4 -386
- package/utils.js.map +1 -1
package/parser.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.handlebarsParse = exports.registerHelpers = exports.pascalCase = exports.dateHelper = exports.nowHelper = exports._dateHelper = exports.defaultHelpers = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const types_1 = require("./types");
|
|
9
|
+
const camelCase_1 = __importDefault(require("lodash/camelCase"));
|
|
10
|
+
const snakeCase_1 = __importDefault(require("lodash/snakeCase"));
|
|
11
|
+
const kebabCase_1 = __importDefault(require("lodash/kebabCase"));
|
|
12
|
+
const startCase_1 = __importDefault(require("lodash/startCase"));
|
|
13
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
14
|
+
const add_1 = __importDefault(require("date-fns/add"));
|
|
15
|
+
const format_1 = __importDefault(require("date-fns/format"));
|
|
16
|
+
const parseISO_1 = __importDefault(require("date-fns/parseISO"));
|
|
17
|
+
const logger_1 = require("./logger");
|
|
18
|
+
const dateFns = {
|
|
19
|
+
add: add_1.default,
|
|
20
|
+
format: format_1.default,
|
|
21
|
+
parseISO: parseISO_1.default,
|
|
22
|
+
};
|
|
23
|
+
exports.defaultHelpers = {
|
|
24
|
+
camelCase: camelCase_1.default,
|
|
25
|
+
snakeCase: snakeCase_1.default,
|
|
26
|
+
startCase: startCase_1.default,
|
|
27
|
+
kebabCase: kebabCase_1.default,
|
|
28
|
+
hyphenCase: kebabCase_1.default,
|
|
29
|
+
pascalCase,
|
|
30
|
+
lowerCase: (text) => text.toLowerCase(),
|
|
31
|
+
upperCase: (text) => text.toUpperCase(),
|
|
32
|
+
now: nowHelper,
|
|
33
|
+
date: dateHelper,
|
|
34
|
+
};
|
|
35
|
+
function _dateHelper(date, formatString, durationDifference, durationType) {
|
|
36
|
+
if (durationType && durationDifference !== undefined) {
|
|
37
|
+
return dateFns.format(dateFns.add(date, { [durationType]: durationDifference }), formatString);
|
|
38
|
+
}
|
|
39
|
+
return dateFns.format(date, formatString);
|
|
40
|
+
}
|
|
41
|
+
exports._dateHelper = _dateHelper;
|
|
42
|
+
function nowHelper(formatString, durationDifference, durationType) {
|
|
43
|
+
return _dateHelper(new Date(), formatString, durationDifference, durationType);
|
|
44
|
+
}
|
|
45
|
+
exports.nowHelper = nowHelper;
|
|
46
|
+
function dateHelper(date, formatString, durationDifference, durationType) {
|
|
47
|
+
return _dateHelper(dateFns.parseISO(date), formatString, durationDifference, durationType);
|
|
48
|
+
}
|
|
49
|
+
exports.dateHelper = dateHelper;
|
|
50
|
+
function pascalCase(s) {
|
|
51
|
+
return (0, startCase_1.default)(s).replace(/\s+/g, "");
|
|
52
|
+
}
|
|
53
|
+
exports.pascalCase = pascalCase;
|
|
54
|
+
function registerHelpers(config) {
|
|
55
|
+
const _helpers = { ...exports.defaultHelpers, ...config.helpers };
|
|
56
|
+
for (const helperName in _helpers) {
|
|
57
|
+
(0, logger_1.log)(config, types_1.LogLevel.Debug, `Registering helper: ${helperName}`);
|
|
58
|
+
handlebars_1.default.registerHelper(helperName, _helpers[helperName]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.registerHelpers = registerHelpers;
|
|
62
|
+
function handlebarsParse(config, templateBuffer, { isPath = false } = {}) {
|
|
63
|
+
const { data } = config;
|
|
64
|
+
try {
|
|
65
|
+
let str = templateBuffer.toString();
|
|
66
|
+
if (isPath) {
|
|
67
|
+
str = str.replace(/\\/g, "/");
|
|
68
|
+
}
|
|
69
|
+
const parser = handlebars_1.default.compile(str, { noEscape: true });
|
|
70
|
+
let outputContents = parser(data);
|
|
71
|
+
if (isPath && path_1.default.sep !== "/") {
|
|
72
|
+
outputContents = outputContents.replace(/\//g, "\\");
|
|
73
|
+
}
|
|
74
|
+
return Buffer.from(outputContents);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
(0, logger_1.log)(config, types_1.LogLevel.Debug, e);
|
|
78
|
+
(0, logger_1.log)(config, types_1.LogLevel.Warning, "Couldn't parse file with handlebars, returning original content");
|
|
79
|
+
return Buffer.from(templateBuffer);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.handlebarsParse = handlebarsParse;
|
|
83
|
+
//# sourceMappingURL=parser.js.map
|
package/parser.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,mCAA0E;AAC1E,iEAAwC;AACxC,iEAAwC;AACxC,iEAAwC;AACxC,iEAAwC;AACxC,4DAAmC;AACnC,uDAAgC;AAChC,6DAAsC;AACtC,iEAA0C;AAC1C,qCAA8B;AAE9B,MAAM,OAAO,GAAG;IACd,GAAG,EAAE,aAAK;IACV,MAAM,EAAE,gBAAQ;IAChB,QAAQ,EAAE,kBAAU;CACrB,CAAA;AAEY,QAAA,cAAc,GAAmC;IAC5D,SAAS,EAAT,mBA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AAI,CAAC,cAAc,CAAC,CAAA;KACnC;AACH,CAAC;AAtBD,0CAsBC"}
|
package/scaffold.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ScaffoldCmdConfig, ScaffoldConfig } from "./types";
|
|
1
|
+
import { MinimalConfig, Resolver, ScaffoldCmdConfig, ScaffoldConfig } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Create a scaffold using given `options`.
|
|
4
4
|
*
|
|
@@ -33,6 +33,6 @@ import { ScaffoldCmdConfig, ScaffoldConfig } from "./types";
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function Scaffold(config: ScaffoldConfig): Promise<void>;
|
|
35
35
|
export declare namespace Scaffold {
|
|
36
|
-
var fromConfig: (pathOrUrl: string, config:
|
|
36
|
+
var fromConfig: (pathOrUrl: string, config: MinimalConfig, overrides?: Resolver<ScaffoldCmdConfig, Partial<Omit<ScaffoldConfig, "name">>> | undefined) => Promise<void>;
|
|
37
37
|
}
|
|
38
38
|
export default Scaffold;
|
package/scaffold.js
CHANGED
|
@@ -12,7 +12,11 @@ exports.Scaffold = void 0;
|
|
|
12
12
|
*/
|
|
13
13
|
const path_1 = __importDefault(require("path"));
|
|
14
14
|
const utils_1 = require("./utils");
|
|
15
|
+
const file_1 = require("./file");
|
|
15
16
|
const types_1 = require("./types");
|
|
17
|
+
const parser_1 = require("./parser");
|
|
18
|
+
const logger_1 = require("./logger");
|
|
19
|
+
const config_1 = require("./config");
|
|
16
20
|
/**
|
|
17
21
|
* Create a scaffold using given `options`.
|
|
18
22
|
*
|
|
@@ -46,23 +50,22 @@ const types_1 = require("./types");
|
|
|
46
50
|
* @category Main
|
|
47
51
|
*/
|
|
48
52
|
async function Scaffold(config) {
|
|
49
|
-
|
|
50
|
-
(
|
|
51
|
-
(0, utils_1.registerHelpers)(config);
|
|
53
|
+
config.output ??= process.cwd();
|
|
54
|
+
(0, parser_1.registerHelpers)(config);
|
|
52
55
|
try {
|
|
53
|
-
config.data = { name: config.name, Name: (0,
|
|
54
|
-
(0,
|
|
56
|
+
config.data = { name: config.name, Name: (0, parser_1.pascalCase)(config.name), ...config.data };
|
|
57
|
+
(0, logger_1.logInitStep)(config);
|
|
55
58
|
for (let _template of config.templates) {
|
|
56
59
|
try {
|
|
57
|
-
const { nonGlobTemplate, origTemplate, isDirOrGlob, isGlob, template } = await (0,
|
|
58
|
-
const files = await (0,
|
|
60
|
+
const { nonGlobTemplate, origTemplate, isDirOrGlob, isGlob, template } = await (0, file_1.getTemplateGlobInfo)(config, _template);
|
|
61
|
+
const files = await (0, file_1.getFileList)(config, template);
|
|
59
62
|
for (const inputFilePath of files) {
|
|
60
|
-
if (await (0,
|
|
63
|
+
if (await (0, file_1.isDir)(inputFilePath)) {
|
|
61
64
|
continue;
|
|
62
65
|
}
|
|
63
|
-
const relPath = (0,
|
|
64
|
-
const basePath = (0,
|
|
65
|
-
(0,
|
|
66
|
+
const relPath = (0, file_1.makeRelativePath)(path_1.default.dirname((0, file_1.removeGlob)(inputFilePath).replace(nonGlobTemplate, "")));
|
|
67
|
+
const basePath = (0, file_1.getBasePath)(relPath);
|
|
68
|
+
(0, logger_1.logInputFile)(config, {
|
|
66
69
|
origTemplate,
|
|
67
70
|
relPath,
|
|
68
71
|
template,
|
|
@@ -72,7 +75,7 @@ async function Scaffold(config) {
|
|
|
72
75
|
isDirOrGlob,
|
|
73
76
|
isGlob,
|
|
74
77
|
});
|
|
75
|
-
await handleTemplateFile(config, {
|
|
78
|
+
await (0, file_1.handleTemplateFile)(config, {
|
|
76
79
|
templatePath: inputFilePath,
|
|
77
80
|
basePath,
|
|
78
81
|
});
|
|
@@ -84,7 +87,7 @@ async function Scaffold(config) {
|
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
catch (e) {
|
|
87
|
-
(0,
|
|
90
|
+
(0, logger_1.log)(config, types_1.LogLevel.Error, e);
|
|
88
91
|
throw e;
|
|
89
92
|
}
|
|
90
93
|
}
|
|
@@ -100,7 +103,13 @@ exports.Scaffold = Scaffold;
|
|
|
100
103
|
* @category Main
|
|
101
104
|
* @return {Promise<void>} A promise that resolves when the scaffold is complete
|
|
102
105
|
*/
|
|
103
|
-
Scaffold.fromConfig = async function (
|
|
106
|
+
Scaffold.fromConfig = async function (
|
|
107
|
+
/** The path or URL to the config file */
|
|
108
|
+
pathOrUrl,
|
|
109
|
+
/** Information needed before loading the config */
|
|
110
|
+
config,
|
|
111
|
+
/** Any overrides to the loaded config */
|
|
112
|
+
overrides) {
|
|
104
113
|
const _cmdConfig = {
|
|
105
114
|
dryRun: false,
|
|
106
115
|
output: process.cwd(),
|
|
@@ -114,29 +123,9 @@ Scaffold.fromConfig = async function (pathOrUrl, config, overrides) {
|
|
|
114
123
|
config: pathOrUrl,
|
|
115
124
|
...config,
|
|
116
125
|
};
|
|
117
|
-
const
|
|
118
|
-
|
|
126
|
+
const _overrides = (0, utils_1.resolve)(overrides, _cmdConfig);
|
|
127
|
+
const _config = await (0, config_1.parseConfig)(_cmdConfig);
|
|
128
|
+
return Scaffold({ ..._config, ..._overrides });
|
|
119
129
|
};
|
|
120
|
-
async function handleTemplateFile(config, { templatePath, basePath }) {
|
|
121
|
-
return new Promise(async (resolve, reject) => {
|
|
122
|
-
var _a;
|
|
123
|
-
try {
|
|
124
|
-
const { inputPath, outputPathOpt, outputDir, outputPath, exists } = await (0, utils_1.getTemplateFileInfo)(config, {
|
|
125
|
-
templatePath,
|
|
126
|
-
basePath,
|
|
127
|
-
});
|
|
128
|
-
const overwrite = (0, utils_1.getOptionValueForFile)(config, inputPath, (_a = config.overwrite) !== null && _a !== void 0 ? _a : false);
|
|
129
|
-
(0, utils_1.log)(config, types_1.LogLevel.Debug, `\nParsing ${templatePath}`, `\nBase path: ${basePath}`, `\nFull input path: ${inputPath}`, `\nOutput Path Opt: ${outputPathOpt}`, `\nFull output dir: ${outputDir}`, `\nFull output path: ${outputPath}`, `\n`);
|
|
130
|
-
await (0, utils_1.createDirIfNotExists)(path_1.default.dirname(outputPath), config);
|
|
131
|
-
(0, utils_1.log)(config, types_1.LogLevel.Info, `Writing to ${outputPath}`);
|
|
132
|
-
await (0, utils_1.copyFileTransformed)(config, { exists, overwrite, outputPath, inputPath });
|
|
133
|
-
resolve();
|
|
134
|
-
}
|
|
135
|
-
catch (e) {
|
|
136
|
-
(0, utils_1.handleErr)(e);
|
|
137
|
-
reject(e);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
130
|
exports.default = Scaffold;
|
|
142
131
|
//# sourceMappingURL=scaffold.js.map
|
package/scaffold.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../src/scaffold.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;GAKG;AACH,gDAAuB;
|
|
1
|
+
{"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../src/scaffold.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;GAKG;AACH,gDAAuB;AACvB,mCAA4C;AAC5C,iCAWe;AACf,mCAA8F;AAE9F,qCAAsD;AACtD,qCAAyD;AACzD,qCAA6D;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACI,KAAK,UAAU,QAAQ,CAAC,MAAsB;IACnD,MAAM,CAAC,MAAM,KAAK,OAAO,CAAC,GAAG,EAAE,CAAA;IAE/B,IAAA,wBAAe,EAAC,MAAM,CAAC,CAAA;IACvB,IAAI;QACF,MAAM,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAA,mBAAU,EAAC,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,CAAA;QAClF,IAAA,oBAAW,EAAC,MAAM,CAAC,CAAA;QACnB,KAAK,IAAI,SAAS,IAAI,MAAM,CAAC,SAAS,EAAE;YACtC,IAAI;gBACF,MAAM,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE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E,OAAO,CAAC,GAAG,EAAE;QACrB,OAAO,EAAE,gBAAQ,CAAC,IAAI;QACtB,SAAS,EAAE,KAAK;QAChB,SAAS,EAAE,EAAE;QACb,eAAe,EAAE,KAAK;QACtB,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,KAAK;QACX,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,SAAS;QACjB,GAAG,MAAM;KACV,CAAA;IACD,MAAM,UAAU,GAAG,IAAA,eAAO,EAAC,SAAS,EAAE,UAAU,CAAC,CAAA;IACjD,MAAM,OAAO,GAAG,MAAM,IAAA,oBAAW,EAAC,UAAU,CAAC,CAAA;IAC7C,OAAO,QAAQ,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,UAAU,EAAE,CAAC,CAAA;AAChD,CAAC,CAAA;AAED,kBAAe,QAAQ,CAAA"}
|
package/types.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export interface ScaffoldConfig {
|
|
|
52
52
|
* Enable to override output files, even if they already exist.
|
|
53
53
|
*
|
|
54
54
|
* You may supply a function to this option, which can take the arguments `(fullPath, baseDir, baseName)` and returns
|
|
55
|
-
* a
|
|
55
|
+
* a boolean for each file.
|
|
56
56
|
*
|
|
57
57
|
* May also be a {@link FileResponseHandler} which returns a boolean value per file.
|
|
58
58
|
*
|
|
@@ -324,4 +324,21 @@ export interface ScaffoldCmdConfig {
|
|
|
324
324
|
*
|
|
325
325
|
* @see {@link ScaffoldConfig}
|
|
326
326
|
*/
|
|
327
|
-
export type
|
|
327
|
+
export type ScaffoldConfigMap = Record<string, ScaffoldConfig>;
|
|
328
|
+
/** The scaffold config file is either:
|
|
329
|
+
* - A {@link ScaffoldConfigMap} object
|
|
330
|
+
* - A function that returns a {@link ScaffoldConfigMap} object
|
|
331
|
+
* - A promise that resolves to a {@link ScaffoldConfigMap} object
|
|
332
|
+
* - A function that returns a promise that resolves to a {@link ScaffoldConfigMap} object
|
|
333
|
+
*/
|
|
334
|
+
export type ScaffoldConfigFile = AsyncResolver<ScaffoldCmdConfig, ScaffoldConfigMap>;
|
|
335
|
+
/** @internal */
|
|
336
|
+
export type Resolver<T, R = T> = R | ((value: T) => R);
|
|
337
|
+
/** @internal */
|
|
338
|
+
export type AsyncResolver<T, R = T> = Resolver<T, Promise<R> | R>;
|
|
339
|
+
/** @internal */
|
|
340
|
+
export type LogConfig = Pick<ScaffoldConfig, "quiet" | "verbose">;
|
|
341
|
+
/** @internal */
|
|
342
|
+
export type ConfigLoadConfig = LogConfig & Pick<ScaffoldCmdConfig, "config">;
|
|
343
|
+
/** @internal */
|
|
344
|
+
export type MinimalConfig = Pick<ScaffoldCmdConfig, "name" | "key">;
|
package/utils.d.ts
CHANGED
|
@@ -1,70 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
import { DefaultHelpers, FileResponse, Helper, LogLevel, ScaffoldCmdConfig, ScaffoldConfig, ScaffoldConfigFile } from "./types";
|
|
4
|
-
import { OptionsBase } from "massarg/types";
|
|
5
|
-
export declare const defaultHelpers: Record<DefaultHelpers, Helper>;
|
|
6
|
-
export declare function _dateHelper(date: Date, formatString: string): string;
|
|
7
|
-
export declare function _dateHelper(date: Date, formatString: string, durationDifference: number, durationType: keyof Duration): string;
|
|
8
|
-
export declare function nowHelper(formatString: string): string;
|
|
9
|
-
export declare function nowHelper(formatString: string, durationDifference: number, durationType: keyof Duration): string;
|
|
10
|
-
export declare function dateHelper(date: string, formatString: string): string;
|
|
11
|
-
export declare function dateHelper(date: string, formatString: string, durationDifference: number, durationType: keyof Duration): string;
|
|
12
|
-
export declare function registerHelpers(config: ScaffoldConfig): void;
|
|
2
|
+
import { Resolver } from "./types";
|
|
13
3
|
export declare function handleErr(err: NodeJS.ErrnoException | null): void;
|
|
14
|
-
|
|
15
|
-
export type LogConfig = Pick<ScaffoldConfig, "quiet" | "verbose">;
|
|
16
|
-
export declare function log(config: LogConfig, level: LogLevel, ...obj: any[]): void;
|
|
17
|
-
export declare function createDirIfNotExists(dir: string, config: ScaffoldConfig): Promise<void>;
|
|
18
|
-
export declare function getOptionValueForFile<T>(config: ScaffoldConfig, filePath: string, fn: FileResponse<T>, defaultValue?: T): T;
|
|
19
|
-
export declare function handlebarsParse(config: ScaffoldConfig, templateBuffer: Buffer | string, { isPath }?: {
|
|
20
|
-
isPath?: boolean;
|
|
21
|
-
}): Buffer;
|
|
22
|
-
export declare function pathExists(filePath: string): Promise<boolean>;
|
|
23
|
-
export declare function pascalCase(s: string): string;
|
|
24
|
-
export declare function isDir(path: string): Promise<boolean>;
|
|
25
|
-
export declare function removeGlob(template: string): string;
|
|
26
|
-
export declare function makeRelativePath(str: string): string;
|
|
27
|
-
export declare function getBasePath(relPath: string): string;
|
|
28
|
-
export declare function getFileList(config: ScaffoldConfig, template: string): Promise<string[]>;
|
|
29
|
-
export interface GlobInfo {
|
|
30
|
-
nonGlobTemplate: string;
|
|
31
|
-
origTemplate: string;
|
|
32
|
-
isDirOrGlob: boolean;
|
|
33
|
-
isGlob: boolean;
|
|
34
|
-
template: string;
|
|
35
|
-
}
|
|
36
|
-
export declare function getTemplateGlobInfo(config: ScaffoldConfig, template: string): Promise<GlobInfo>;
|
|
37
|
-
export interface OutputFileInfo {
|
|
38
|
-
inputPath: string;
|
|
39
|
-
outputPathOpt: string;
|
|
40
|
-
outputDir: string;
|
|
41
|
-
outputPath: string;
|
|
42
|
-
exists: boolean;
|
|
43
|
-
}
|
|
44
|
-
export declare function getTemplateFileInfo(config: ScaffoldConfig, { templatePath, basePath }: {
|
|
45
|
-
templatePath: string;
|
|
46
|
-
basePath: string;
|
|
47
|
-
}): Promise<OutputFileInfo>;
|
|
48
|
-
export declare function copyFileTransformed(config: ScaffoldConfig, { exists, overwrite, outputPath, inputPath, }: {
|
|
49
|
-
exists: boolean;
|
|
50
|
-
overwrite: boolean;
|
|
51
|
-
outputPath: string;
|
|
52
|
-
inputPath: string;
|
|
53
|
-
}): Promise<void>;
|
|
54
|
-
export declare function getOutputDir(config: ScaffoldConfig, outputPathOpt: string, basePath: string): string;
|
|
55
|
-
export declare function logInputFile(config: ScaffoldConfig, { origTemplate, relPath, template, inputFilePath, nonGlobTemplate, basePath, isDirOrGlob, isGlob, }: {
|
|
56
|
-
origTemplate: string;
|
|
57
|
-
relPath: string;
|
|
58
|
-
template: string;
|
|
59
|
-
inputFilePath: string;
|
|
60
|
-
nonGlobTemplate: string;
|
|
61
|
-
basePath: string;
|
|
62
|
-
isDirOrGlob: boolean;
|
|
63
|
-
isGlob: boolean;
|
|
64
|
-
}): void;
|
|
65
|
-
export declare function logInitStep(config: ScaffoldConfig): void;
|
|
66
|
-
export declare function parseAppendData(value: string, options: ScaffoldCmdConfig & OptionsBase): unknown;
|
|
67
|
-
/** @internal */
|
|
68
|
-
export declare function parseConfig(config: ScaffoldCmdConfig & OptionsBase): Promise<ScaffoldConfig>;
|
|
69
|
-
/** @internal */
|
|
70
|
-
export declare function getConfig(config: Pick<ScaffoldCmdConfig, "quiet" | "verbose" | "config">): Promise<ScaffoldConfigFile>;
|
|
4
|
+
export declare function resolve<T, R = T>(resolver: Resolver<T, R>, arg: T): R;
|