@thi.ng/transclude 0.1.51 → 0.1.52
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/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/api.js +0 -1
- package/package.json +13 -10
- package/tpl/file.js +9 -18
- package/tpl/markdown.js +39 -26
- package/tpl/pkg.js +173 -212
- package/tpl/whitespace.js +8 -16
- package/transclude.js +35 -32
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/api.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/transclude",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.52",
|
|
4
4
|
"description": "Extensible functional template engine for text document generation, incl. various high-level Markdown features",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
30
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc tpl",
|
|
29
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -33,16 +35,17 @@
|
|
|
33
35
|
"test": "testament test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/api": "^8.9.
|
|
37
|
-
"@thi.ng/checks": "^3.4.
|
|
38
|
-
"@thi.ng/file-io": "^1.0.
|
|
39
|
-
"@thi.ng/logger": "^2.0.
|
|
40
|
-
"@thi.ng/strings": "^3.7.
|
|
41
|
-
"@thi.ng/transducers": "^8.8.
|
|
38
|
+
"@thi.ng/api": "^8.9.12",
|
|
39
|
+
"@thi.ng/checks": "^3.4.12",
|
|
40
|
+
"@thi.ng/file-io": "^1.0.5",
|
|
41
|
+
"@thi.ng/logger": "^2.0.2",
|
|
42
|
+
"@thi.ng/strings": "^3.7.3",
|
|
43
|
+
"@thi.ng/transducers": "^8.8.15"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
46
|
"@microsoft/api-extractor": "^7.38.3",
|
|
45
|
-
"@thi.ng/testament": "^0.4.
|
|
47
|
+
"@thi.ng/testament": "^0.4.5",
|
|
48
|
+
"esbuild": "^0.19.8",
|
|
46
49
|
"rimraf": "^5.0.5",
|
|
47
50
|
"tools": "^0.0.1",
|
|
48
51
|
"typedoc": "^0.25.4",
|
|
@@ -108,5 +111,5 @@
|
|
|
108
111
|
"status": "alpha",
|
|
109
112
|
"year": 2022
|
|
110
113
|
},
|
|
111
|
-
"gitHead": "
|
|
114
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
112
115
|
}
|
package/tpl/file.js
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import { readText } from "@thi.ng/file-io";
|
|
2
2
|
import { resolve } from "path";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Pre-processing stage parametric template function. Includes file given as
|
|
14
|
-
* template argument: `<!-- include header.md -->`.
|
|
15
|
-
*
|
|
16
|
-
* @param ctx
|
|
17
|
-
* @param args
|
|
18
|
-
* @param currPath
|
|
19
|
-
*/
|
|
20
|
-
export const preincludeFile = ({ logger }, [src], currPath) => src.replace(new RegExp(`<!-- include (.+) -->`, "g"), (_, path) => readText(resolve(resolve(currPath, ".."), path.trim()), logger));
|
|
3
|
+
const includeFile = ({ logger }, args, currPath) => readText(resolve(resolve(currPath, ".."), args[2].trim()), logger);
|
|
4
|
+
const preincludeFile = ({ logger }, [src], currPath) => src.replace(
|
|
5
|
+
new RegExp(`<!-- include (.+) -->`, "g"),
|
|
6
|
+
(_, path) => readText(resolve(resolve(currPath, ".."), path.trim()), logger)
|
|
7
|
+
);
|
|
8
|
+
export {
|
|
9
|
+
includeFile,
|
|
10
|
+
preincludeFile
|
|
11
|
+
};
|
package/tpl/markdown.js
CHANGED
|
@@ -6,30 +6,43 @@ import { filter } from "@thi.ng/transducers/filter";
|
|
|
6
6
|
import { map } from "@thi.ng/transducers/map";
|
|
7
7
|
import { str } from "@thi.ng/transducers/str";
|
|
8
8
|
import { transduce } from "@thi.ng/transducers/transduce";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const [_, level,
|
|
31
|
-
const indent = repeat(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
9
|
+
const image = (url, alt = "") => ``;
|
|
10
|
+
const link = (title, href) => `[${title}](${href})`;
|
|
11
|
+
const list = (items, eol = "\n") => transduce(
|
|
12
|
+
map((x) => `- ${x}`),
|
|
13
|
+
str(eol),
|
|
14
|
+
items
|
|
15
|
+
);
|
|
16
|
+
const toc = (opts) => ({ src, eol }) => {
|
|
17
|
+
const { min, max, match, disable, title } = {
|
|
18
|
+
min: 2,
|
|
19
|
+
max: 4,
|
|
20
|
+
match: "<!-- toc -->",
|
|
21
|
+
disable: /<\!-- notoc -->/i,
|
|
22
|
+
...opts
|
|
23
|
+
};
|
|
24
|
+
const isHeading = new RegExp(`^#{${min},${max}}\\s`);
|
|
25
|
+
const reHeading = new RegExp(`^(#{${min},${max}})\\s(.+)`);
|
|
26
|
+
const toc2 = transduce(
|
|
27
|
+
comp(
|
|
28
|
+
filter((line) => isHeading.test(line) && !disable.test(line)),
|
|
29
|
+
map((hd) => {
|
|
30
|
+
const [_, level, title2] = reHeading.exec(hd);
|
|
31
|
+
const indent = repeat(
|
|
32
|
+
" ",
|
|
33
|
+
Math.max(0, level.length - min)
|
|
34
|
+
);
|
|
35
|
+
return `${indent}- ${link(title2, `#${slugifyGH(title2)}`)}`;
|
|
36
|
+
})
|
|
37
|
+
),
|
|
38
|
+
str(eol),
|
|
39
|
+
split(src)
|
|
40
|
+
);
|
|
41
|
+
return src.replace(match, title ? title + toc2 : toc2);
|
|
42
|
+
};
|
|
43
|
+
export {
|
|
44
|
+
image,
|
|
45
|
+
link,
|
|
46
|
+
list,
|
|
47
|
+
toc
|
|
35
48
|
};
|
package/tpl/pkg.js
CHANGED
|
@@ -1,219 +1,180 @@
|
|
|
1
1
|
import { isString } from "@thi.ng/checks/is-string";
|
|
2
2
|
import { link, list } from "./markdown.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
3
|
+
const LICENSES = {
|
|
4
|
+
"Apache-2.0": {
|
|
5
|
+
name: "Apache License 2.0",
|
|
6
|
+
url: "https://spdx.org/licenses/Apache-2.0.html"
|
|
7
|
+
},
|
|
8
|
+
"BSD-2-Clause": {
|
|
9
|
+
name: 'BSD 2-Clause "Simplified" License',
|
|
10
|
+
url: "https://spdx.org/licenses/BSD-2-Clause.html"
|
|
11
|
+
},
|
|
12
|
+
"BSD-3-Clause": {
|
|
13
|
+
name: 'BSD 3-Clause "New" or "Revised" License',
|
|
14
|
+
url: "https://spdx.org/licenses/BSD-3-Clause.html"
|
|
15
|
+
},
|
|
16
|
+
"CC-BY-4.0": {
|
|
17
|
+
name: "Creative Commons Attribution 4.0 International",
|
|
18
|
+
url: "https://spdx.org/licenses/CC-BY-4.0.html"
|
|
19
|
+
},
|
|
20
|
+
"CC-BY-NC-4.0": {
|
|
21
|
+
name: "Creative Commons Attribution Non Commercial 4.0 International",
|
|
22
|
+
url: "https://spdx.org/licenses/CC-BY-NC-4.0.html"
|
|
23
|
+
},
|
|
24
|
+
"CC-BY-NC-ND-4.0": {
|
|
25
|
+
name: "Creative Commons Attribution Non Commercial No Derivatives 4.0 International",
|
|
26
|
+
url: "https://spdx.org/licenses/CC-BY-NC-ND-4.0.html"
|
|
27
|
+
},
|
|
28
|
+
"CC-BY-NC-SA-4.0": {
|
|
29
|
+
name: "Creative Commons Attribution Non Commercial Share Alike 4.0 International",
|
|
30
|
+
url: "https://spdx.org/licenses/CC-BY-NC-SA-4.0.html"
|
|
31
|
+
},
|
|
32
|
+
"CC-BY-ND-4.0": {
|
|
33
|
+
name: "Creative Commons Attribution No Derivatives 4.0 International",
|
|
34
|
+
url: "https://spdx.org/licenses/CC-BY-ND-4.0.html"
|
|
35
|
+
},
|
|
36
|
+
"CC-BY-SA-4.0": {
|
|
37
|
+
name: "Creative Commons Attribution Share Alike 4.0 International",
|
|
38
|
+
url: "https://spdx.org/licenses/CC-BY-SA-4.0.html"
|
|
39
|
+
},
|
|
40
|
+
"CPAL-1.0": {
|
|
41
|
+
name: "Common Public Attribution License 1.0",
|
|
42
|
+
url: "https://spdx.org/licenses/CPAL-1.0.html"
|
|
43
|
+
},
|
|
44
|
+
"CPL-1.0": {
|
|
45
|
+
name: "Common Public License 1.0",
|
|
46
|
+
url: "https://spdx.org/licenses/CPL-1.0.html"
|
|
47
|
+
},
|
|
48
|
+
"ECL-2.0": {
|
|
49
|
+
name: "Educational Community License v2.0",
|
|
50
|
+
url: "https://spdx.org/licenses/ECL-2.0.html"
|
|
51
|
+
},
|
|
52
|
+
"EPL-2.0": {
|
|
53
|
+
name: "Eclipse Public License 2.0",
|
|
54
|
+
url: "https://spdx.org/licenses/EPL-2.0.html"
|
|
55
|
+
},
|
|
56
|
+
EUDatagrid: {
|
|
57
|
+
name: "EU DataGrid Software License",
|
|
58
|
+
url: "https://spdx.org/licenses/EUDatagrid.html"
|
|
59
|
+
},
|
|
60
|
+
"EUPL-1.2": {
|
|
61
|
+
name: "European Union Public License 1.2",
|
|
62
|
+
url: "https://spdx.org/licenses/EUPL-1.2.html"
|
|
63
|
+
},
|
|
64
|
+
"GFDL-1.3-or-later": {
|
|
65
|
+
name: "GNU Free Documentation License v1.3 or later",
|
|
66
|
+
url: "https://spdx.org/licenses/GFDL-1.3-or-later.html"
|
|
67
|
+
},
|
|
68
|
+
"GPL-3.0-or-later": {
|
|
69
|
+
name: "GNU General Public License v3.0 or later",
|
|
70
|
+
url: "https://spdx.org/licenses/GPL-3.0-or-later.html"
|
|
71
|
+
},
|
|
72
|
+
ISC: { name: "ISC License", url: "https://spdx.org/licenses/ISC.html" },
|
|
73
|
+
"LGPL-3.0-or-later": {
|
|
74
|
+
name: "GNU Lesser General Public License v3.0 or later",
|
|
75
|
+
url: "https://spdx.org/licenses/LGPL-3.0-or-later.html"
|
|
76
|
+
},
|
|
77
|
+
MIT: { name: "MIT License", url: "https://spdx.org/licenses/MIT.html" },
|
|
78
|
+
"MPL-2.0": {
|
|
79
|
+
name: "Mozilla Public License 2.0",
|
|
80
|
+
url: "https://spdx.org/licenses/MPL-2.0.html"
|
|
81
|
+
},
|
|
82
|
+
"OFL-1.1": {
|
|
83
|
+
name: "SIL Open Font License 1.1",
|
|
84
|
+
url: "https://spdx.org/licenses/OFL-1.1.html"
|
|
85
|
+
},
|
|
86
|
+
Unlicense: {
|
|
87
|
+
name: "The Unlicense",
|
|
88
|
+
url: "https://spdx.org/licenses/Unlicense.html"
|
|
89
|
+
},
|
|
90
|
+
"UPL-1.0": {
|
|
91
|
+
name: "Universal Permissive License v1.0",
|
|
92
|
+
url: "https://spdx.org/licenses/UPL-1.0.html"
|
|
93
|
+
},
|
|
94
|
+
Zlib: { name: "zlib License", url: "https://spdx.org/licenses/Zlib.html" }
|
|
95
|
+
};
|
|
96
|
+
const shortName = (name) => {
|
|
97
|
+
const idx = name.indexOf("/");
|
|
98
|
+
return idx > 0 ? name.substring(idx + 1) : name;
|
|
95
99
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return idx > 0 ? name.substring(idx + 1) : name;
|
|
100
|
+
const author = (author2) => isString(author2) ? author2.split(/\s*[<\(]/)[0] : author2.name;
|
|
101
|
+
const authorLink = (author2) => {
|
|
102
|
+
if (isString(author2)) {
|
|
103
|
+
const [name, a, b] = author2.split(/\s*[<\(]/);
|
|
104
|
+
const href = b ? b[b.length - 1] == ")" ? b : a : a ? a : "";
|
|
105
|
+
return href.length && href[href.length - 1] === ")" ? link(name, href.substring(0, href.length - 1)) : name;
|
|
106
|
+
}
|
|
107
|
+
return author2.url ? link(author2.name, author2.url) : author2.name;
|
|
105
108
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Similar to {@link author}, but if an URL is available, returns a Markdown
|
|
114
|
-
* link to the author's URL, else just the name.
|
|
115
|
-
*
|
|
116
|
-
* @param author
|
|
117
|
-
*/
|
|
118
|
-
export const authorLink = (author) => {
|
|
119
|
-
if (isString(author)) {
|
|
120
|
-
const [name, a, b] = author.split(/\s*[<\(]/);
|
|
121
|
-
const href = b ? (b[b.length - 1] == ")" ? b : a) : a ? a : "";
|
|
122
|
-
return href.length && href[href.length - 1] === ")"
|
|
123
|
-
? link(name, href.substring(0, href.length - 1))
|
|
124
|
-
: name;
|
|
125
|
-
}
|
|
126
|
-
return author.url ? link(author.name, author.url) : author.name;
|
|
109
|
+
const contributors = (people, eol = "\n") => list(people.map(author), eol);
|
|
110
|
+
const contributorLinks = (people, eol = "\n") => list(people.map(authorLink), eol);
|
|
111
|
+
const license = (spdxID) => LICENSES[spdxID].name || `${spdxID} license`;
|
|
112
|
+
const licenseLink = (spdxID) => {
|
|
113
|
+
const license2 = LICENSES[spdxID];
|
|
114
|
+
return license2 ? link(license2.name, license2.url) : `${spdxID} license`;
|
|
127
115
|
};
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
116
|
+
const packageTemplates = (pkg, opts) => {
|
|
117
|
+
const $opts = {
|
|
118
|
+
hdContributors: "### Contributors\n\n",
|
|
119
|
+
...opts
|
|
120
|
+
};
|
|
121
|
+
const tpls = {
|
|
122
|
+
"pkg.name": ({ user }) => pkg(user).name,
|
|
123
|
+
"pkg.shortName": ({ user }) => shortName(pkg(user).name),
|
|
124
|
+
"pkg.version": ({ user }) => "v" + pkg(user).version,
|
|
125
|
+
"pkg.description": ({ user }) => pkg(user).description,
|
|
126
|
+
"pkg.link": ({ user }) => link(pkg(user).name, pkg(user).homepage),
|
|
127
|
+
"pkg.author": ({ user }) => author(pkg(user).author),
|
|
128
|
+
"pkg.authorLink": ({ user }) => authorLink(pkg(user).author),
|
|
129
|
+
"pkg.contributors": ({ user, eol }) => {
|
|
130
|
+
const people = pkg(user).contributors;
|
|
131
|
+
return people ? $opts.hdContributors + contributors(people, eol) : "";
|
|
132
|
+
},
|
|
133
|
+
"pkg.contributorLinks": ({ user, eol }) => {
|
|
134
|
+
const people = pkg(user).contributors;
|
|
135
|
+
return people ? $opts.hdContributors + contributorLinks(people, eol) : "";
|
|
136
|
+
},
|
|
137
|
+
"pkg.allAuthors": ({ user, eol }) => {
|
|
138
|
+
const $pkg = pkg(user);
|
|
139
|
+
const $author = author($pkg.author);
|
|
140
|
+
const res = [];
|
|
141
|
+
if ($pkg.contributors) {
|
|
142
|
+
res.push(
|
|
143
|
+
$author + " (Main author)",
|
|
144
|
+
...$pkg.contributors.map(author)
|
|
145
|
+
);
|
|
146
|
+
} else {
|
|
147
|
+
res.push($author);
|
|
148
|
+
}
|
|
149
|
+
return list(res, eol);
|
|
150
|
+
},
|
|
151
|
+
"pkg.allAuthorLinks": ({ user, eol }) => {
|
|
152
|
+
const $pkg = pkg(user);
|
|
153
|
+
const $author = authorLink($pkg.author);
|
|
154
|
+
const res = [];
|
|
155
|
+
if ($pkg.contributors) {
|
|
156
|
+
res.push(
|
|
157
|
+
$author + " (Main author)",
|
|
158
|
+
...$pkg.contributors.map(authorLink)
|
|
159
|
+
);
|
|
160
|
+
} else {
|
|
161
|
+
res.push($author);
|
|
162
|
+
}
|
|
163
|
+
return list(res, eol);
|
|
164
|
+
},
|
|
165
|
+
"pkg.license": ({ user }) => license(pkg(user).license),
|
|
166
|
+
"pkg.licenseLink": ({ user }) => licenseLink(pkg(user).license)
|
|
167
|
+
};
|
|
168
|
+
return tpls;
|
|
157
169
|
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
hdContributors: "### Contributors\n\n",
|
|
169
|
-
...opts,
|
|
170
|
-
};
|
|
171
|
-
const tpls = {
|
|
172
|
-
"pkg.name": ({ user }) => pkg(user).name,
|
|
173
|
-
"pkg.shortName": ({ user }) => shortName(pkg(user).name),
|
|
174
|
-
"pkg.version": ({ user }) => "v" + pkg(user).version,
|
|
175
|
-
"pkg.description": ({ user }) => pkg(user).description,
|
|
176
|
-
"pkg.link": ({ user }) => link(pkg(user).name, pkg(user).homepage),
|
|
177
|
-
"pkg.author": ({ user }) => author(pkg(user).author),
|
|
178
|
-
"pkg.authorLink": ({ user }) => authorLink(pkg(user).author),
|
|
179
|
-
"pkg.contributors": ({ user, eol }) => {
|
|
180
|
-
const people = pkg(user).contributors;
|
|
181
|
-
return people
|
|
182
|
-
? $opts.hdContributors + contributors(people, eol)
|
|
183
|
-
: "";
|
|
184
|
-
},
|
|
185
|
-
"pkg.contributorLinks": ({ user, eol }) => {
|
|
186
|
-
const people = pkg(user).contributors;
|
|
187
|
-
return people
|
|
188
|
-
? $opts.hdContributors + contributorLinks(people, eol)
|
|
189
|
-
: "";
|
|
190
|
-
},
|
|
191
|
-
"pkg.allAuthors": ({ user, eol }) => {
|
|
192
|
-
const $pkg = pkg(user);
|
|
193
|
-
const $author = author($pkg.author);
|
|
194
|
-
const res = [];
|
|
195
|
-
if ($pkg.contributors) {
|
|
196
|
-
res.push($author + " (Main author)", ...$pkg.contributors.map(author));
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
res.push($author);
|
|
200
|
-
}
|
|
201
|
-
return list(res, eol);
|
|
202
|
-
},
|
|
203
|
-
"pkg.allAuthorLinks": ({ user, eol }) => {
|
|
204
|
-
const $pkg = pkg(user);
|
|
205
|
-
const $author = authorLink($pkg.author);
|
|
206
|
-
const res = [];
|
|
207
|
-
if ($pkg.contributors) {
|
|
208
|
-
res.push($author + " (Main author)", ...$pkg.contributors.map(authorLink));
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
res.push($author);
|
|
212
|
-
}
|
|
213
|
-
return list(res, eol);
|
|
214
|
-
},
|
|
215
|
-
"pkg.license": ({ user }) => license(pkg(user).license),
|
|
216
|
-
"pkg.licenseLink": ({ user }) => licenseLink(pkg(user).license),
|
|
217
|
-
};
|
|
218
|
-
return tpls;
|
|
170
|
+
export {
|
|
171
|
+
LICENSES,
|
|
172
|
+
author,
|
|
173
|
+
authorLink,
|
|
174
|
+
contributorLinks,
|
|
175
|
+
contributors,
|
|
176
|
+
license,
|
|
177
|
+
licenseLink,
|
|
178
|
+
packageTemplates,
|
|
179
|
+
shortName
|
|
219
180
|
};
|
package/tpl/whitespace.js
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return ({ src }) => src.replace(/^\t+/gm, (x) => indent.repeat(x.length));
|
|
1
|
+
const tabsToSpaces = (size = 4) => {
|
|
2
|
+
const indent = " ".repeat(size);
|
|
3
|
+
return ({ src }) => src.replace(/^\t+/gm, (x) => indent.repeat(x.length));
|
|
4
|
+
};
|
|
5
|
+
const compactEmptyLines = ({ src, eol }) => src.replace(/(\r?\n){2,}/g, eol.repeat(2)).trim() + eol;
|
|
6
|
+
export {
|
|
7
|
+
compactEmptyLines,
|
|
8
|
+
tabsToSpaces
|
|
10
9
|
};
|
|
11
|
-
/**
|
|
12
|
-
* Post-processing stage template function. Compacts successive empty lines to a
|
|
13
|
-
* max. of 1 empty line.
|
|
14
|
-
*
|
|
15
|
-
* @param ctx
|
|
16
|
-
*/
|
|
17
|
-
export const compactEmptyLines = ({ src, eol }) => src.replace(/(\r?\n){2,}/g, eol.repeat(2)).trim() + eol;
|
package/transclude.js
CHANGED
|
@@ -2,37 +2,40 @@ import { readText } from "@thi.ng/file-io/text";
|
|
|
2
2
|
import { ConsoleLogger } from "@thi.ng/logger";
|
|
3
3
|
import { resolve } from "path";
|
|
4
4
|
const DEFAULT_LOGGER = new ConsoleLogger("transclude");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return $ctx;
|
|
5
|
+
const transclude = (ctx, path) => {
|
|
6
|
+
const $ctx = {
|
|
7
|
+
logger: DEFAULT_LOGGER,
|
|
8
|
+
match: /\{\{([a-z0-9.]+)([^}]*)\}\}/gi,
|
|
9
|
+
pre: [],
|
|
10
|
+
post: [],
|
|
11
|
+
eol: "\n",
|
|
12
|
+
...ctx
|
|
13
|
+
};
|
|
14
|
+
$ctx.pre.reduce((acc, fn) => $ctx.src = fn($ctx, [acc], path), $ctx.src);
|
|
15
|
+
$ctx.src = $ctx.src.replace($ctx.match, (...xs) => {
|
|
16
|
+
const [orig, id] = xs;
|
|
17
|
+
const tpl = $ctx.templates[id];
|
|
18
|
+
if (tpl !== void 0) {
|
|
19
|
+
return typeof tpl === "function" ? tpl($ctx, xs, path) : tpl;
|
|
20
|
+
} else {
|
|
21
|
+
$ctx.logger.warn(`skipping unknown tpl ID: "${id}"`);
|
|
22
|
+
return orig;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
$ctx.post.reduce((acc, fn) => $ctx.src = fn($ctx, [acc], path), $ctx.src);
|
|
26
|
+
return $ctx;
|
|
28
27
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
const transcludeFile = (path, ctx) => {
|
|
29
|
+
const $ctx = {
|
|
30
|
+
logger: DEFAULT_LOGGER,
|
|
31
|
+
src: "",
|
|
32
|
+
...ctx
|
|
33
|
+
};
|
|
34
|
+
path = resolve(path);
|
|
35
|
+
$ctx.src = readText(path, $ctx.logger);
|
|
36
|
+
return transclude($ctx, path);
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
transclude,
|
|
40
|
+
transcludeFile
|
|
38
41
|
};
|