juisy 2.0.0-beta.0
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 +211 -0
- package/bin/cli/cli.js +23 -0
- package/bin/cli/cmds/changelog.js +41 -0
- package/bin/cli/cmds/docs/generate-api.js +22 -0
- package/bin/cli/cmds/docs/generate-cli.js +11 -0
- package/bin/cli/cmds/docs/generate-readme.js +11 -0
- package/bin/cli/cmds/docs/index.js +22 -0
- package/bin/cli/cmds/docs/lint.js +42 -0
- package/bin/cli/cmds/eject.js +28 -0
- package/bin/cli/cmds/git-hooks/index.js +20 -0
- package/bin/cli/cmds/git-hooks/reset.js +48 -0
- package/bin/cli/cmds/git-hooks/sync.js +19 -0
- package/bin/cli/cmds/index.js +15 -0
- package/bin/cli/cmds/print-globals.js +28 -0
- package/bin/cli/cmds/release.js +231 -0
- package/bin/cli/cmds/squeeze.js +269 -0
- package/bin/cli/cmds/test.js +33 -0
- package/bin/cli/index.js +9 -0
- package/bin/cli/lib/docs/generate-api-doc.js +78 -0
- package/bin/cli/lib/version/update-version.js +52 -0
- package/bin/scripts/commit-msg.js +32 -0
- package/bin/scripts/pre-commit.js +24 -0
- package/dist/DataExporter.d.ts +67 -0
- package/dist/cli/CLIFactory.d.ts +19 -0
- package/dist/cli/Command.d.ts +44 -0
- package/dist/cli/InterfaceUtils.d.ts +53 -0
- package/dist/cli/OutputUtils.d.ts +123 -0
- package/dist/cli/command-visitors/command-handler-injections.d.ts +10 -0
- package/dist/cli/command-visitors/get-command-meta.d.ts +10 -0
- package/dist/cli/command-visitors/index.d.ts +9 -0
- package/dist/cli/command-visitors/private-command.d.ts +16 -0
- package/dist/cli/create-engine.d.ts +7 -0
- package/dist/cli/extract-usage.d.ts +72 -0
- package/dist/cli/index.d.ts +20 -0
- package/dist/cli/index.js +559 -0
- package/dist/cli/types.d.ts +112 -0
- package/dist/cli/utils.d.ts +19 -0
- package/dist/eject.d.ts +22 -0
- package/dist/get-package-info.d.ts +6 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +244 -0
- package/dist/project-globals.d.ts +63 -0
- package/dist/templater/Templater.d.ts +23 -0
- package/dist/templater/index.d.ts +6 -0
- package/dist/templater/index.js +330 -0
- package/dist/templater/markdown-templater/ReadmeTemplater.d.ts +154 -0
- package/dist/templater/markdown-templater/index.d.ts +25 -0
- package/dist/templater/types.d.ts +10 -0
- package/dist/utils/misc.d.ts +21 -0
- package/package.json +179 -0
- package/src/index.js +507 -0
- package/template/CHANGELOG.md +0 -0
- package/template/bin/cli/cli.js +27 -0
- package/template/bin/cli/cmds/changelog.js +71 -0
- package/template/bin/cli/cmds/docs.js +30 -0
- package/template/bin/cli/cmds/docs_cmds/generate-api.js +75 -0
- package/template/bin/cli/cmds/docs_cmds/generate-readme.js +51 -0
- package/template/bin/cli/cmds/git-hooks.js +30 -0
- package/template/bin/cli/cmds/git_hooks_cmds/reset.js +76 -0
- package/template/bin/cli/cmds/git_hooks_cmds/sync.js +44 -0
- package/template/bin/cli/cmds/release.js +219 -0
- package/template/bin/cli/index.js +7 -0
- package/template/bin/cli/lib/docs/generate-api-doc.js +33 -0
- package/template/bin/cli/lib/release/generate-release-note.js +3 -0
- package/template/bin/cli/lib/version/update-version.js +51 -0
- package/template/bin/scripts/commit-msg.js +42 -0
- package/template/bin/scripts/pre-commit.js +32 -0
- package/template/docs/api/docs.config.js +10 -0
- package/template/docs/readme/config.js +22 -0
- package/template/docs/readme/readme.js +70 -0
- package/template/docs/readme/template.md +53 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* juisy v1.4.0
|
|
3
|
+
* Copyright © 2022-Present Hervé Perchec
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import ejs from 'ejs';
|
|
7
|
+
import handlebars from 'handlebars';
|
|
8
|
+
import { remark } from 'remark';
|
|
9
|
+
import remarkToc from 'remark-toc';
|
|
10
|
+
import remarkFrontmatter from 'remark-frontmatter';
|
|
11
|
+
import path, { dirname } from 'path';
|
|
12
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
13
|
+
import fs from 'fs-extra';
|
|
14
|
+
import chalk from 'chalk';
|
|
15
|
+
import merge from 'lodash.merge';
|
|
16
|
+
import mdu from 'markdown-utils';
|
|
17
|
+
import { markdownTable } from 'markdown-table';
|
|
18
|
+
import asciitree from 'ascii-tree';
|
|
19
|
+
import GithubSlugger from 'github-slugger';
|
|
20
|
+
|
|
21
|
+
class Templater {
|
|
22
|
+
constructor(engine, options) {
|
|
23
|
+
this.engine = engine;
|
|
24
|
+
options = options || {};
|
|
25
|
+
switch (engine) {
|
|
26
|
+
case "handlebars":
|
|
27
|
+
this.engine = handlebars;
|
|
28
|
+
this.methodsMap.compile = async (template) => {
|
|
29
|
+
return handlebars.compile(template, options.engineOptions);
|
|
30
|
+
};
|
|
31
|
+
this.methodsMap.render = async (template, data = void 0, opts = void 0) => {
|
|
32
|
+
return this.methodsMap.compile(template).template(data);
|
|
33
|
+
};
|
|
34
|
+
break;
|
|
35
|
+
case "ejs":
|
|
36
|
+
this.engine = ejs;
|
|
37
|
+
this.methodsMap.compile = async (template) => {
|
|
38
|
+
return ejs.compile(template, options.engineOptions);
|
|
39
|
+
};
|
|
40
|
+
this.methodsMap.render = async (template, data = void 0, opts) => {
|
|
41
|
+
return ejs.render(template, data, {
|
|
42
|
+
...options.engineOptions,
|
|
43
|
+
...opts || {}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
break;
|
|
47
|
+
case "pug":
|
|
48
|
+
this.engine = (template, options2) => () => "";
|
|
49
|
+
break;
|
|
50
|
+
default:
|
|
51
|
+
throw new Error(`Unsupported templating engine: ${engine}`);
|
|
52
|
+
}
|
|
53
|
+
if (options.defaultData) {
|
|
54
|
+
this.defaultData = options.defaultData;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
engine;
|
|
58
|
+
defaultData;
|
|
59
|
+
methodsMap = {};
|
|
60
|
+
/**
|
|
61
|
+
* @returns Get the engine
|
|
62
|
+
*/
|
|
63
|
+
getEngine() {
|
|
64
|
+
return this.engine;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Renders a template with the given context.
|
|
68
|
+
*/
|
|
69
|
+
async render(template, data = void 0, options = void 0) {
|
|
70
|
+
const mergedData = { ...this.defaultData, ...data || {} };
|
|
71
|
+
return await this.methodsMap.render(template, mergedData, options);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Renders a template file with the given context.
|
|
75
|
+
* @todo not yet implemented
|
|
76
|
+
*/
|
|
77
|
+
renderFile(filePath, context = {}) {
|
|
78
|
+
return "";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
class MarkdownTemplater extends Templater {
|
|
83
|
+
constructor(engine = "ejs", options) {
|
|
84
|
+
super(engine, options);
|
|
85
|
+
this.processor = options?.processor ? options.processor === "remark" ? remark() : options.processor : remark();
|
|
86
|
+
this.processorOptions = this.buildProcessorOptions(options?.processorOptions || {});
|
|
87
|
+
this.initProcessor();
|
|
88
|
+
}
|
|
89
|
+
processor;
|
|
90
|
+
processorOptions;
|
|
91
|
+
buildProcessorOptions(options) {
|
|
92
|
+
options = options || {};
|
|
93
|
+
const defaultRemarkTocOptions = {};
|
|
94
|
+
const defaultRemarkFrontmatterOptions = {
|
|
95
|
+
type: "yaml",
|
|
96
|
+
marker: "-"
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
use: [
|
|
100
|
+
...options.use || []
|
|
101
|
+
],
|
|
102
|
+
toc: options.toc === true ? defaultRemarkTocOptions : options.toc !== void 0 ? options.toc : defaultRemarkTocOptions,
|
|
103
|
+
frontmatter: options.frontmatter === true ? defaultRemarkFrontmatterOptions : options.frontmatter !== void 0 ? options.frontmatter : defaultRemarkFrontmatterOptions
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
initProcessor() {
|
|
107
|
+
const processorPlugins = [];
|
|
108
|
+
if (this.processorOptions.toc)
|
|
109
|
+
processorPlugins.push([remarkToc, this.processorOptions.toc]);
|
|
110
|
+
if (this.processorOptions.frontmatter)
|
|
111
|
+
processorPlugins.push([remarkFrontmatter, this.processorOptions.frontmatter]);
|
|
112
|
+
for (const plugin of processorPlugins.concat(this.processorOptions.use)) {
|
|
113
|
+
this.processor.use(...plugin);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Renders a template with the given context.
|
|
118
|
+
*/
|
|
119
|
+
async render(template, data = void 0, options = void 0) {
|
|
120
|
+
const content = await super.render(template, data, options);
|
|
121
|
+
return (await this.processor.process(content)).toString();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
126
|
+
dirname(__filename);
|
|
127
|
+
const slugger = new GithubSlugger();
|
|
128
|
+
const DEFAULT_INIT_TARGET_RELATIVE_PATH = "./docs/readme";
|
|
129
|
+
class ReadmeTemplater {
|
|
130
|
+
constructor(config) {
|
|
131
|
+
this.config = config;
|
|
132
|
+
this.templater = new MarkdownTemplater("ejs", {});
|
|
133
|
+
}
|
|
134
|
+
config;
|
|
135
|
+
templater;
|
|
136
|
+
/**
|
|
137
|
+
* @param {Configuration|string} config - The config object to process. Can be path to config file as string.
|
|
138
|
+
* @param {object} [options] - Same as render
|
|
139
|
+
* @returns {void|Promise<void>} Promise is immediately resolved except if a module is async.
|
|
140
|
+
* @throws Throws error if render or file writing fails
|
|
141
|
+
* @description
|
|
142
|
+
* Writes rendered README markdown to file
|
|
143
|
+
* @example
|
|
144
|
+
* readmeGenerator.generate(config) // => output to README.md file
|
|
145
|
+
* readmeGenerator.generate('./.docs/readme/config.js') // pass config path
|
|
146
|
+
* readmeGenerator.generate(config, { data: { foo: 'bar' } }) // pass options
|
|
147
|
+
* // Async
|
|
148
|
+
* await readmeGenerator.generate('./.docs/readme/config.js') // async module
|
|
149
|
+
* await readmeGenerator.generate({
|
|
150
|
+
* ejsDataPath: '/path/to/ejs/data.js' // async module
|
|
151
|
+
* })
|
|
152
|
+
*/
|
|
153
|
+
async generate(options = {}) {
|
|
154
|
+
const processedConfig = await ReadmeTemplater.processConfig(this.config);
|
|
155
|
+
const targetFilePath = path.join(processedConfig.destFolder, processedConfig.fileName);
|
|
156
|
+
console.log(`Auto-generating "${processedConfig.fileName}" file`);
|
|
157
|
+
console.log();
|
|
158
|
+
console.log("- Syntax: " + chalk.yellow("ejs"));
|
|
159
|
+
const renderResult = await this.render(options);
|
|
160
|
+
try {
|
|
161
|
+
fs.writeFileSync(targetFilePath, renderResult);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.log("- Status:", chalk.red("✘ FAILED"));
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
console.log("- Status:", chalk.green("✔ OK"));
|
|
167
|
+
console.log('- Written to: "' + chalk.cyan(targetFilePath) + '"');
|
|
168
|
+
console.log();
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Render README markdown
|
|
172
|
+
* @param options - Options object
|
|
173
|
+
* @param options.data - Additionnal data object to merge with default EJS data
|
|
174
|
+
* @returns Returns the rendered markdown as string. Promise is immediately resolved except if a module is async.
|
|
175
|
+
* @example
|
|
176
|
+
* const result = readmeGenerator.render(config)
|
|
177
|
+
* const result = readmeGenerator.render('./.docs/readme/config.js')
|
|
178
|
+
* const result = readmeGenerator.render(config, { data: { foo: 'bar' } })
|
|
179
|
+
* // Async
|
|
180
|
+
* const result = await readmeGenerator.render('./.docs/readme/config.js') // async module
|
|
181
|
+
* const result = await readmeGenerator.render({
|
|
182
|
+
* ejsDataPath: '/path/to/ejs/data.js' // async module
|
|
183
|
+
* })
|
|
184
|
+
*/
|
|
185
|
+
async render(options = {}) {
|
|
186
|
+
const processedConfig = await ReadmeTemplater.processConfig(this.config);
|
|
187
|
+
const data = processedConfig.ejsDataPath ? await import(pathToFileURL(processedConfig.ejsDataPath).toString()).then((mod) => mod.default || mod) : {};
|
|
188
|
+
options.data = options.data || {};
|
|
189
|
+
const ejsData = merge(merge({
|
|
190
|
+
...ReadmeTemplater.defaultEjsData,
|
|
191
|
+
$config: processedConfig
|
|
192
|
+
}, data), options.data);
|
|
193
|
+
let template = await fs.readFile(processedConfig.templatePath, { encoding: "utf8" });
|
|
194
|
+
if (processedConfig.appendAutoGenMessage) {
|
|
195
|
+
template += "\n----\n\n*<%= $config.fileName %> - this file was auto generated with [juisy](https://www.npmjs.com/package/juisy) README templater. Don't edit it.*\n";
|
|
196
|
+
}
|
|
197
|
+
return await this.templater.render(template, ejsData, processedConfig.ejsOptions);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Static methods
|
|
201
|
+
*/
|
|
202
|
+
/**
|
|
203
|
+
* Takes a custom config as unique parameter and merges it with the default configuration object.
|
|
204
|
+
* @param config - The config object to process. Can be path to config file as string.
|
|
205
|
+
* @returns Returns the processed configuration. Promise is immediately resolved except if module is async.
|
|
206
|
+
* @example
|
|
207
|
+
* readmeGenerator.processConfig({ ... }) // pass object
|
|
208
|
+
* readmeGenerator.processConfig('./.docs/readme/config.js') // pass path as string
|
|
209
|
+
* // If module.exports is a promise
|
|
210
|
+
* await readmeGenerator.processConfig('./.docs/readme/config.js') // async module
|
|
211
|
+
*/
|
|
212
|
+
static async processConfig(config) {
|
|
213
|
+
let customConfig;
|
|
214
|
+
if (typeof config === "string") {
|
|
215
|
+
const configPath = pathToFileURL(path.isAbsolute(config) ? config : path.resolve(process.cwd(), config));
|
|
216
|
+
customConfig = (await import(configPath.toString())).default;
|
|
217
|
+
} else if (typeof config !== "object") {
|
|
218
|
+
throw new TypeError("config parameter must be object or string. Received " + typeof config);
|
|
219
|
+
} else {
|
|
220
|
+
customConfig = config;
|
|
221
|
+
}
|
|
222
|
+
const result = {};
|
|
223
|
+
result.fileName = customConfig.fileName || ReadmeTemplater.defaultConfig.fileName;
|
|
224
|
+
result.destFolder = customConfig.destFolder || ReadmeTemplater.defaultConfig.destFolder;
|
|
225
|
+
result.templatePath = customConfig.templatePath || ReadmeTemplater.defaultConfig.templatePath;
|
|
226
|
+
result.ejsDataPath = customConfig.ejsDataPath || customConfig.ejsDataPath === null ? customConfig.ejsDataPath : ReadmeTemplater.defaultConfig.ejsDataPath;
|
|
227
|
+
if (customConfig.ejsOptions) {
|
|
228
|
+
result.ejsOptions = {
|
|
229
|
+
async: ReadmeTemplater.defaultConfig.ejsOptions.async,
|
|
230
|
+
// async prop see below
|
|
231
|
+
root: ReadmeTemplater.defaultConfig.ejsOptions.root,
|
|
232
|
+
// root prop see below (always array)
|
|
233
|
+
views: ReadmeTemplater.defaultConfig.ejsOptions.views,
|
|
234
|
+
// views prop see below (always array)
|
|
235
|
+
...customConfig.ejsOptions
|
|
236
|
+
};
|
|
237
|
+
} else {
|
|
238
|
+
result.ejsOptions = ReadmeTemplater.defaultConfig.ejsOptions;
|
|
239
|
+
}
|
|
240
|
+
result.appendAutoGenMessage = customConfig.appendAutoGenMessage !== void 0 ? customConfig.appendAutoGenMessage : ReadmeTemplater.defaultConfig.appendAutoGenMessage;
|
|
241
|
+
result.autoToc = customConfig.autoToc !== void 0 ? customConfig.autoToc : ReadmeTemplater.defaultConfig.autoToc;
|
|
242
|
+
result.slugify = customConfig.slugify !== void 0 ? customConfig.slugify : ReadmeTemplater.defaultConfig.slugify;
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* @alias module:readme-generator.defaultConfig
|
|
247
|
+
* @type {Configuration}
|
|
248
|
+
* @description
|
|
249
|
+
* Returns the default configuration object.
|
|
250
|
+
* This base configuration is used by `processConfig` method and so `generate` and `render` methods.
|
|
251
|
+
* See also {@link module:readme-generator~Configuration Configuration} defaults.
|
|
252
|
+
*/
|
|
253
|
+
static defaultConfig = {
|
|
254
|
+
fileName: "README.md",
|
|
255
|
+
destFolder: process.cwd(),
|
|
256
|
+
templatePath: path.resolve(process.cwd(), DEFAULT_INIT_TARGET_RELATIVE_PATH, "template.md"),
|
|
257
|
+
ejsDataPath: path.resolve(process.cwd(), DEFAULT_INIT_TARGET_RELATIVE_PATH, "data.js"),
|
|
258
|
+
ejsOptions: {
|
|
259
|
+
/**
|
|
260
|
+
* Always render in async mode
|
|
261
|
+
* @since v3.0.0
|
|
262
|
+
*/
|
|
263
|
+
async: true,
|
|
264
|
+
/**
|
|
265
|
+
* Set project root for includes with an absolute path (e.g, /file.ejs).
|
|
266
|
+
* Can be array to try to resolve include from multiple directories.
|
|
267
|
+
*/
|
|
268
|
+
root: [
|
|
269
|
+
// User template path
|
|
270
|
+
// path.resolve(process.cwd(), DEFAULT_INIT_TARGET_RELATIVE_PATH)
|
|
271
|
+
],
|
|
272
|
+
/**
|
|
273
|
+
* An array of paths to use when resolving includes with relative paths.
|
|
274
|
+
*/
|
|
275
|
+
views: [
|
|
276
|
+
// // User template path
|
|
277
|
+
// path.resolve(process.cwd(), DEFAULT_INIT_TARGET_RELATIVE_PATH)
|
|
278
|
+
]
|
|
279
|
+
},
|
|
280
|
+
appendAutoGenMessage: true,
|
|
281
|
+
autoToc: true,
|
|
282
|
+
slugify: slugger.slug.bind(slugger)
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* The default EJS data object.
|
|
286
|
+
* This base EJS data object is used by `render` methods and merged with user provided EJS data.
|
|
287
|
+
*/
|
|
288
|
+
static defaultEjsData = {
|
|
289
|
+
/**
|
|
290
|
+
* Contains the default configuration by default.
|
|
291
|
+
* Will be merged with custom configuration when using `generate` or `render` method.
|
|
292
|
+
* @example
|
|
293
|
+
* // Access configuration
|
|
294
|
+
* $config.fileName // => README.md
|
|
295
|
+
*/
|
|
296
|
+
$config: {},
|
|
297
|
+
/**
|
|
298
|
+
* Contains the following methods:
|
|
299
|
+
*
|
|
300
|
+
* - `table`: generates a markdown table
|
|
301
|
+
* - `asciiTree`: generates an "ASCII" tree
|
|
302
|
+
* - ... all methods from `markdown-utils` package
|
|
303
|
+
*
|
|
304
|
+
* > Please check the following package documentations:
|
|
305
|
+
* > - [markdown-utils](https://github.com/jonschlinkert/markdown-utils)
|
|
306
|
+
* > - [markdown-table](https://www.npmjs.com/package/markdown-table)
|
|
307
|
+
* > - [ascii-tree](https://www.npmjs.com/package/ascii-tree)
|
|
308
|
+
* @example
|
|
309
|
+
* // Generates a blockquote
|
|
310
|
+
* $utils.blockquote('This is a blockquote')
|
|
311
|
+
* // Generates a table
|
|
312
|
+
* $utils.table([
|
|
313
|
+
* [ 'Column 1', 'Column 2' ],
|
|
314
|
+
* [ 'Value 1', 'Value 2' ]
|
|
315
|
+
* ])
|
|
316
|
+
* // Generates an ascii tree
|
|
317
|
+
* $utils.asciiTree('*.\n**a\n**b\n*...')
|
|
318
|
+
*/
|
|
319
|
+
$utils: {
|
|
320
|
+
// markdown-utils
|
|
321
|
+
...mdu,
|
|
322
|
+
// markdown-table
|
|
323
|
+
table: markdownTable,
|
|
324
|
+
// ascii-tree
|
|
325
|
+
asciiTree: asciitree.generate
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export { MarkdownTemplater, ReadmeTemplater, Templater };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { default as ejs } from 'ejs';
|
|
2
|
+
type Configuration = {
|
|
3
|
+
/**
|
|
4
|
+
* Output file name: `README.md` by default. Only for **generate** method
|
|
5
|
+
*/
|
|
6
|
+
fileName: string;
|
|
7
|
+
/**
|
|
8
|
+
* Output path, default is `process.cwd` (project root). Only for **generate** method
|
|
9
|
+
*/
|
|
10
|
+
destFolder: string;
|
|
11
|
+
/**
|
|
12
|
+
* Template path: default is `.docs/readme/template.md`
|
|
13
|
+
*/
|
|
14
|
+
templatePath: string;
|
|
15
|
+
/**
|
|
16
|
+
* Path to EJS data file: default is `.docs/readme/data.js`. If null, no file will be required
|
|
17
|
+
*/
|
|
18
|
+
ejsDataPath: string;
|
|
19
|
+
/**
|
|
20
|
+
* EJS options: see also {@link https://www.npmjs.com/package/ejs#options EJS documentation}.
|
|
21
|
+
* @property {string[]} [ejsOptions.root] - The path of template folder is automatically included.
|
|
22
|
+
* @property {string[]} [ejsOptions.views] - The path of template folder and the path of internal partials are automatically included.
|
|
23
|
+
*/
|
|
24
|
+
ejsOptions: ejs.Options & {
|
|
25
|
+
root: string[];
|
|
26
|
+
views: string[];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* If true, append "don't edit" message to rendered markdown. Default is **true**.
|
|
30
|
+
*/
|
|
31
|
+
appendAutoGenMessage: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* If true, parse `<!-- toc -->` special comment to automatically inject generated table of contents. Default is **true**.
|
|
34
|
+
* The `markdown-toc` package is used for this feature, check the {@link https://www.npmjs.com/package/markdown-toc documentation}.
|
|
35
|
+
*/
|
|
36
|
+
autoToc: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* If provided, will be used by `markdown-toc` to slugify headings id.
|
|
39
|
+
* Default uses `github-slugger`: see [**slug** method documentation](https://github.com/Flet/github-slugger#usage).
|
|
40
|
+
*/
|
|
41
|
+
slugify: Function;
|
|
42
|
+
};
|
|
43
|
+
export type UserConfiguration = {
|
|
44
|
+
fileName?: Configuration['fileName'];
|
|
45
|
+
destFolder?: Configuration['destFolder'];
|
|
46
|
+
templatePath?: Configuration['templatePath'];
|
|
47
|
+
ejsDataPath?: Configuration['ejsDataPath'];
|
|
48
|
+
ejsOptions?: Configuration['ejsOptions'];
|
|
49
|
+
appendAutoGenMessage?: Configuration['appendAutoGenMessage'];
|
|
50
|
+
autoToc?: Configuration['autoToc'];
|
|
51
|
+
slugify?: Configuration['slugify'];
|
|
52
|
+
};
|
|
53
|
+
export declare class ReadmeTemplater {
|
|
54
|
+
constructor(config: Parameters<typeof ReadmeTemplater.processConfig>[0]);
|
|
55
|
+
private config;
|
|
56
|
+
private templater;
|
|
57
|
+
/**
|
|
58
|
+
* @param {Configuration|string} config - The config object to process. Can be path to config file as string.
|
|
59
|
+
* @param {object} [options] - Same as render
|
|
60
|
+
* @returns {void|Promise<void>} Promise is immediately resolved except if a module is async.
|
|
61
|
+
* @throws Throws error if render or file writing fails
|
|
62
|
+
* @description
|
|
63
|
+
* Writes rendered README markdown to file
|
|
64
|
+
* @example
|
|
65
|
+
* readmeGenerator.generate(config) // => output to README.md file
|
|
66
|
+
* readmeGenerator.generate('./.docs/readme/config.js') // pass config path
|
|
67
|
+
* readmeGenerator.generate(config, { data: { foo: 'bar' } }) // pass options
|
|
68
|
+
* // Async
|
|
69
|
+
* await readmeGenerator.generate('./.docs/readme/config.js') // async module
|
|
70
|
+
* await readmeGenerator.generate({
|
|
71
|
+
* ejsDataPath: '/path/to/ejs/data.js' // async module
|
|
72
|
+
* })
|
|
73
|
+
*/
|
|
74
|
+
generate(options?: {}): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Render README markdown
|
|
77
|
+
* @param options - Options object
|
|
78
|
+
* @param options.data - Additionnal data object to merge with default EJS data
|
|
79
|
+
* @returns Returns the rendered markdown as string. Promise is immediately resolved except if a module is async.
|
|
80
|
+
* @example
|
|
81
|
+
* const result = readmeGenerator.render(config)
|
|
82
|
+
* const result = readmeGenerator.render('./.docs/readme/config.js')
|
|
83
|
+
* const result = readmeGenerator.render(config, { data: { foo: 'bar' } })
|
|
84
|
+
* // Async
|
|
85
|
+
* const result = await readmeGenerator.render('./.docs/readme/config.js') // async module
|
|
86
|
+
* const result = await readmeGenerator.render({
|
|
87
|
+
* ejsDataPath: '/path/to/ejs/data.js' // async module
|
|
88
|
+
* })
|
|
89
|
+
*/
|
|
90
|
+
render(options?: {
|
|
91
|
+
data?: Record<any, any>;
|
|
92
|
+
}): Promise<string>;
|
|
93
|
+
/**
|
|
94
|
+
* Static methods
|
|
95
|
+
*/
|
|
96
|
+
/**
|
|
97
|
+
* Takes a custom config as unique parameter and merges it with the default configuration object.
|
|
98
|
+
* @param config - The config object to process. Can be path to config file as string.
|
|
99
|
+
* @returns Returns the processed configuration. Promise is immediately resolved except if module is async.
|
|
100
|
+
* @example
|
|
101
|
+
* readmeGenerator.processConfig({ ... }) // pass object
|
|
102
|
+
* readmeGenerator.processConfig('./.docs/readme/config.js') // pass path as string
|
|
103
|
+
* // If module.exports is a promise
|
|
104
|
+
* await readmeGenerator.processConfig('./.docs/readme/config.js') // async module
|
|
105
|
+
*/
|
|
106
|
+
static processConfig(config: UserConfiguration | string): Promise<Configuration>;
|
|
107
|
+
/**
|
|
108
|
+
* @alias module:readme-generator.defaultConfig
|
|
109
|
+
* @type {Configuration}
|
|
110
|
+
* @description
|
|
111
|
+
* Returns the default configuration object.
|
|
112
|
+
* This base configuration is used by `processConfig` method and so `generate` and `render` methods.
|
|
113
|
+
* See also {@link module:readme-generator~Configuration Configuration} defaults.
|
|
114
|
+
*/
|
|
115
|
+
static defaultConfig: Configuration;
|
|
116
|
+
/**
|
|
117
|
+
* The default EJS data object.
|
|
118
|
+
* This base EJS data object is used by `render` methods and merged with user provided EJS data.
|
|
119
|
+
*/
|
|
120
|
+
static defaultEjsData: {
|
|
121
|
+
/**
|
|
122
|
+
* Contains the default configuration by default.
|
|
123
|
+
* Will be merged with custom configuration when using `generate` or `render` method.
|
|
124
|
+
* @example
|
|
125
|
+
* // Access configuration
|
|
126
|
+
* $config.fileName // => README.md
|
|
127
|
+
*/
|
|
128
|
+
$config: {};
|
|
129
|
+
/**
|
|
130
|
+
* Contains the following methods:
|
|
131
|
+
*
|
|
132
|
+
* - `table`: generates a markdown table
|
|
133
|
+
* - `asciiTree`: generates an "ASCII" tree
|
|
134
|
+
* - ... all methods from `markdown-utils` package
|
|
135
|
+
*
|
|
136
|
+
* > Please check the following package documentations:
|
|
137
|
+
* > - [markdown-utils](https://github.com/jonschlinkert/markdown-utils)
|
|
138
|
+
* > - [markdown-table](https://www.npmjs.com/package/markdown-table)
|
|
139
|
+
* > - [ascii-tree](https://www.npmjs.com/package/ascii-tree)
|
|
140
|
+
* @example
|
|
141
|
+
* // Generates a blockquote
|
|
142
|
+
* $utils.blockquote('This is a blockquote')
|
|
143
|
+
* // Generates a table
|
|
144
|
+
* $utils.table([
|
|
145
|
+
* [ 'Column 1', 'Column 2' ],
|
|
146
|
+
* [ 'Value 1', 'Value 2' ]
|
|
147
|
+
* ])
|
|
148
|
+
* // Generates an ascii tree
|
|
149
|
+
* $utils.asciiTree('*.\n**a\n**b\n*...')
|
|
150
|
+
*/
|
|
151
|
+
$utils: any;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { remark } from 'remark';
|
|
2
|
+
import { Templater } from '../Templater';
|
|
3
|
+
import { TemplaterOptions } from '../types';
|
|
4
|
+
export type MarkdownTemplaterOptions = TemplaterOptions<any> & {
|
|
5
|
+
processor?: 'remark' | typeof remark;
|
|
6
|
+
/**
|
|
7
|
+
* Options to pass to remark
|
|
8
|
+
*/
|
|
9
|
+
processorOptions?: {
|
|
10
|
+
use?: MarkdownTemplater['processorOptions']['use'];
|
|
11
|
+
toc?: MarkdownTemplater['processorOptions']['toc'];
|
|
12
|
+
frontmatter?: MarkdownTemplater['processorOptions']['frontmatter'];
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare class MarkdownTemplater extends Templater {
|
|
16
|
+
constructor(engine?: ConstructorParameters<typeof Templater>[0], options?: MarkdownTemplaterOptions);
|
|
17
|
+
private processor;
|
|
18
|
+
private processorOptions;
|
|
19
|
+
private buildProcessorOptions;
|
|
20
|
+
private initProcessor;
|
|
21
|
+
/**
|
|
22
|
+
* Renders a template with the given context.
|
|
23
|
+
*/
|
|
24
|
+
render(template: string, data?: undefined, options?: any): Promise<string>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Options as EJSOptions } from 'ejs';
|
|
2
|
+
import { compile as HandlebarsCompiler } from 'handlebars';
|
|
3
|
+
export type SupportedEngines = ['handlebars', 'ejs', 'pug'];
|
|
4
|
+
export type TemplaterOptions<E extends SupportedEngines[number]> = {
|
|
5
|
+
engineOptions?: E extends 'handlebars' ? Parameters<typeof HandlebarsCompiler>[1] : E extends 'ejs' ? EJSOptions : unknown;
|
|
6
|
+
/**
|
|
7
|
+
* Default data to be merged with template context.
|
|
8
|
+
*/
|
|
9
|
+
defaultData?: Record<string, any>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { GlobOptions } from 'glob';
|
|
2
|
+
/**
|
|
3
|
+
* @param pattern - Same as node-glob pattern argument
|
|
4
|
+
* @param options - Same as gloab options argument
|
|
5
|
+
* @returns {string[]} Returns an array of file path
|
|
6
|
+
* @description
|
|
7
|
+
* Get file urls that match glob (see: https://github.com/isaacs/node-glob)
|
|
8
|
+
* @example
|
|
9
|
+
* utils.getFileUrls('path/to/*.js') // => [ 'path/to/file1.js', 'path/to/file2.js', ... ]
|
|
10
|
+
*/
|
|
11
|
+
export declare function getFileUrls(pattern: string, options?: GlobOptions): string[] | import('path-scurry').Path[];
|
|
12
|
+
/**
|
|
13
|
+
* @param dir - The directory path
|
|
14
|
+
* @returns Returns an array of file path
|
|
15
|
+
* @yields {string[]} The next found files.
|
|
16
|
+
* @description
|
|
17
|
+
* Get all files in a directory (recursively)
|
|
18
|
+
* @example
|
|
19
|
+
* utils.getFiles(path) // => [ 'path/to/file1', 'path/to/file2', ... ]
|
|
20
|
+
*/
|
|
21
|
+
export declare function getFiles(dir: string): AsyncGenerator<string[]>;
|