aberlaas-readme 2.10.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/LICENSE +9 -0
- package/lib/main.js +179 -0
- package/package.json +43 -0
- package/templates/README.md +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Tim Carry (tim@pixelastic.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { _, dedent, pMap } from 'golgoth';
|
|
3
|
+
import { absolute, exists, glob, read, readJson, write } from 'firost';
|
|
4
|
+
import frontMatter from 'front-matter';
|
|
5
|
+
import helper from 'aberlaas-helper';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
/**
|
|
9
|
+
* Update the main README.md based on the template and the documentation
|
|
10
|
+
* @param {object} cliArgs CLI Argument object, as created by minimist
|
|
11
|
+
* @param {string} cliArgs.template Path to the template (default to
|
|
12
|
+
* .github/README.template.md
|
|
13
|
+
* @param {string} cliArgs.docs Path to the documentation folder
|
|
14
|
+
* @param {string} cliArgs.lib Path to the library folder
|
|
15
|
+
* @param {string} cliArgs.output List of files to output. Default to
|
|
16
|
+
* README at the root, and next to package.json
|
|
17
|
+
*/
|
|
18
|
+
async run(cliArgs) {
|
|
19
|
+
const template = await this.getTemplate(cliArgs);
|
|
20
|
+
|
|
21
|
+
const packageData = await this.getPackageData(cliArgs);
|
|
22
|
+
const docsData = await this.getDocsData(cliArgs);
|
|
23
|
+
const data = { package: packageData, ...docsData };
|
|
24
|
+
|
|
25
|
+
const output = await this.getReadmes(cliArgs);
|
|
26
|
+
|
|
27
|
+
const content = await this.convert(template, data);
|
|
28
|
+
// console.info({ template, data, docsData });
|
|
29
|
+
|
|
30
|
+
await pMap(output, async (filepath) => {
|
|
31
|
+
await write(content, filepath);
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Returns the content of the template
|
|
36
|
+
* @param {object} cliArgs CLI Argument object, as created by minimist
|
|
37
|
+
* @param {string} cliArgs.template Path to the template
|
|
38
|
+
* Will default to .github/README.template.md in the host, or fallback to
|
|
39
|
+
* a default value in aberllas
|
|
40
|
+
* @returns {string} Template content
|
|
41
|
+
*/
|
|
42
|
+
async getTemplate(cliArgs = {}) {
|
|
43
|
+
if (cliArgs.template) {
|
|
44
|
+
const customTemplate = helper.hostPath(cliArgs.template);
|
|
45
|
+
if (await exists(customTemplate)) {
|
|
46
|
+
return await read(customTemplate);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const hostDefaultTemplate = helper.hostPath('.github/README.template.md');
|
|
51
|
+
if (await exists(hostDefaultTemplate)) {
|
|
52
|
+
return await read(hostDefaultTemplate);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const aberlaasDefaultTemplate = absolute('../templates/README.md');
|
|
56
|
+
return await read(aberlaasDefaultTemplate);
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* Returns the content of the library package.json
|
|
60
|
+
* @param {object} cliArgs CLI Argument object, as created by minimist
|
|
61
|
+
* Will default search in cliArgs.lib, ./lib, or the root
|
|
62
|
+
* @returns {object} package.json content
|
|
63
|
+
*/
|
|
64
|
+
async getPackageData(cliArgs = {}) {
|
|
65
|
+
const packagePath = await this.getPackagePath(cliArgs);
|
|
66
|
+
return await readJson(packagePath);
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* Returns the path to the package.json
|
|
70
|
+
* @param {object} cliArgs CLI Argument object, as created by minimist
|
|
71
|
+
* Will default search in cliArgs.lib, ./lib, or the root
|
|
72
|
+
* @returns {object} package.json content
|
|
73
|
+
*/
|
|
74
|
+
async getPackagePath(cliArgs = {}) {
|
|
75
|
+
const libFolder = helper.hostPath(cliArgs.lib || './lib');
|
|
76
|
+
let packagePath = path.resolve(libFolder, 'package.json');
|
|
77
|
+
|
|
78
|
+
if (await exists(packagePath)) {
|
|
79
|
+
return packagePath;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return helper.hostPath('package.json');
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* Returns all documentation as an object
|
|
86
|
+
* @param {object} cliArgs CLI Argument object, as created by minimist
|
|
87
|
+
* @param {string} cliArgs.docs Path to the documentation directory
|
|
88
|
+
* Will default to ./docs/src
|
|
89
|
+
* @returns {object} Documentation content
|
|
90
|
+
*/
|
|
91
|
+
async getDocsData(cliArgs = {}) {
|
|
92
|
+
const docsPath = helper.hostPath(cliArgs.docs || './docs/src');
|
|
93
|
+
const mdFiles = await glob(`${docsPath}/**/*.md`);
|
|
94
|
+
const docsData = {};
|
|
95
|
+
await pMap(mdFiles, async (filepath) => {
|
|
96
|
+
// Convert filepath to a (nested) dot key
|
|
97
|
+
const key = _.chain(path.relative(docsPath, filepath))
|
|
98
|
+
.replace(/\.md$/, '')
|
|
99
|
+
.replace(/\//g, '.')
|
|
100
|
+
.value();
|
|
101
|
+
|
|
102
|
+
// Grab the content, excluding front-matter
|
|
103
|
+
const rawContent = await read(filepath);
|
|
104
|
+
const { body } = frontMatter(rawContent);
|
|
105
|
+
_.set(docsData, key, body);
|
|
106
|
+
});
|
|
107
|
+
return docsData;
|
|
108
|
+
},
|
|
109
|
+
/**
|
|
110
|
+
* Returns path to all README.md to write
|
|
111
|
+
* @param {object} cliArgs CLI Argument object, as created by minimist
|
|
112
|
+
* @param {string} cliArgs.output Comma-separated list of output path
|
|
113
|
+
* Will default to a README.md at the git root, and one in the module code
|
|
114
|
+
* (./lib by default)
|
|
115
|
+
* @returns {Array} List of paths to write the READMEs
|
|
116
|
+
*/
|
|
117
|
+
async getReadmes(cliArgs = {}) {
|
|
118
|
+
// Custom --output passed as a comma-separated list
|
|
119
|
+
if (cliArgs.output) {
|
|
120
|
+
return _.chain(cliArgs.output)
|
|
121
|
+
.split(',')
|
|
122
|
+
.map((filepath) => {
|
|
123
|
+
return helper.hostPath(filepath);
|
|
124
|
+
})
|
|
125
|
+
.sort()
|
|
126
|
+
.value();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// README.md at the git root for GitHub
|
|
130
|
+
const hostReadmePath = helper.hostPath('README.md');
|
|
131
|
+
|
|
132
|
+
// README.md in the module folder for npm/yarn
|
|
133
|
+
const packagePath = await this.getPackagePath(cliArgs);
|
|
134
|
+
const moduleReadmePath = path.resolve(
|
|
135
|
+
path.dirname(packagePath),
|
|
136
|
+
'README.md',
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const readmes = _.uniq([hostReadmePath, moduleReadmePath]);
|
|
140
|
+
return readmes;
|
|
141
|
+
},
|
|
142
|
+
/**
|
|
143
|
+
* Convert a source string by replace {key} with the matching keys of data
|
|
144
|
+
* @param {string} source The source string
|
|
145
|
+
* @param {object} data The data object to use to compile
|
|
146
|
+
* @returns {string} The converted string
|
|
147
|
+
*/
|
|
148
|
+
convert(source, data) {
|
|
149
|
+
const regexp = /{(?<key>.*?)}/gm;
|
|
150
|
+
const matches = Array.from(source.matchAll(regexp));
|
|
151
|
+
|
|
152
|
+
let convertedSource = dedent`
|
|
153
|
+
<!--
|
|
154
|
+
This page was automatically generated by aberlaas readme.
|
|
155
|
+
DO NOT EDIT IT MANUALLY.
|
|
156
|
+
-->
|
|
157
|
+
|
|
158
|
+
${source}`;
|
|
159
|
+
|
|
160
|
+
_.each(matches, (match) => {
|
|
161
|
+
const key = match.groups.key;
|
|
162
|
+
convertedSource = convertedSource.replace(
|
|
163
|
+
`{${key}}`,
|
|
164
|
+
_.get(data, key, ''),
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
return convertedSource;
|
|
168
|
+
},
|
|
169
|
+
/**
|
|
170
|
+
* Read a file from disk, removing its front-matter if it has one
|
|
171
|
+
* @param {string} filepath Path to the file
|
|
172
|
+
* @returns {string} File content, stripped of front-matter
|
|
173
|
+
*/
|
|
174
|
+
async read(filepath) {
|
|
175
|
+
const source = await this.__read(filepath);
|
|
176
|
+
const { body } = frontMatter(source);
|
|
177
|
+
return body;
|
|
178
|
+
},
|
|
179
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aberlaas-readme",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "aberlaas readme helper: Write and synchronize README",
|
|
5
|
+
"version": "2.10.0",
|
|
6
|
+
"repository": "pixelastic/aberlaas",
|
|
7
|
+
"homepage": "https://projects.pixelastic.com/aberlaas/",
|
|
8
|
+
"author": "Tim Carry (@pixelastic)",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"files": [
|
|
11
|
+
"lib/*.js",
|
|
12
|
+
"templates/"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./lib/main.js"
|
|
16
|
+
},
|
|
17
|
+
"main": "./lib/main.js",
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18.18.0"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "../../scripts/local/build",
|
|
23
|
+
"build:prod": "../../scripts/local/build-prod",
|
|
24
|
+
"cms": "../../scripts/local/cms",
|
|
25
|
+
"serve": "../../scripts/local/serve",
|
|
26
|
+
"ci": "../../scripts/local/ci",
|
|
27
|
+
"release": "../../scripts/local/release",
|
|
28
|
+
"update": "node ../../scripts/meta/update.js",
|
|
29
|
+
"test:meta": "../../scripts/local/test-meta",
|
|
30
|
+
"test": "../../scripts/local/test",
|
|
31
|
+
"test:watch": "../../scripts/local/test-watch",
|
|
32
|
+
"compress": "../../scripts/local/compress",
|
|
33
|
+
"lint": "../../scripts/local/lint",
|
|
34
|
+
"lint:fix": "../../scripts/local/lint-fix"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"aberlaas-helper": "^2.10.0",
|
|
38
|
+
"firost": "4.3.0",
|
|
39
|
+
"front-matter": "4.0.2",
|
|
40
|
+
"golgoth": "2.4.0"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "bcdaf87c198a588e02b5539c222f611e356d3079"
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aberlaas template
|