1 | module.exports = {
|
2 | resources: [{
|
3 | name: "file",
|
4 | read({from, resource}) {
|
5 | var path = require("pathlib"),
|
6 | fs = require("fs"),
|
7 | src = ".";
|
8 |
|
9 | if (from && from.name == "file") {
|
10 | src = path(from.args).dir();
|
11 | }
|
12 | resource.args = path(src).resolve(resource.args).path;
|
13 | return fs.readFileSync(resource.args, "utf8");
|
14 | }
|
15 | }],
|
16 | transforms: [{
|
17 | name: "string",
|
18 | transform(file, content, encoding = "utf8") {
|
19 | if (Buffer.isBuffer(content)) {
|
20 | content = content.toString(encoding);
|
21 | }
|
22 | return content;
|
23 | }
|
24 | }, {
|
25 | name: "cssmin",
|
26 | transform(file, content) {
|
27 | return (new (require("clean-css"))).minify(content).styles;
|
28 | }
|
29 | }, {
|
30 | name: "docstring",
|
31 | transform(file, content) {
|
32 | return content.match(/`((\\`|[^`])+)`/)[1];
|
33 | }
|
34 | }, {
|
35 | name: "stringify",
|
36 | transform(file, content) {
|
37 | return JSON.stringify(content);
|
38 | }
|
39 | }, {
|
40 | name: "dataurl",
|
41 | transform(
|
42 | file,
|
43 | content,
|
44 | type = require("mime").getType(file) || "text/plain",
|
45 | charset = ""
|
46 | ) {
|
47 | if (!Buffer.isBuffer(content) || type.startsWith("text")) {
|
48 | if (!charset) charset = "utf8";
|
49 | if (!Buffer.isBuffer(content)) {
|
50 | content = Buffer.from(content, charset);
|
51 | }
|
52 | }
|
53 | if (charset) {
|
54 | charset = `;charset=${charset}`;
|
55 | }
|
56 | return `data:${type}${charset};base64,${content.toString("base64")}`;
|
57 | }
|
58 | }, {
|
59 | name: "eval",
|
60 | transform(file, content, code) {
|
61 | var vm = require("vm");
|
62 | return vm.runInNewContext(code, {$0: content});
|
63 | }
|
64 | }, {
|
65 | name: "markdown",
|
66 | transform(file, content, type) {
|
67 | if (type == "codeblock") {
|
68 | return "```\n" + content + "\n```";
|
69 | }
|
70 | if (type == "code") {
|
71 | return "`" + content + "`";
|
72 | }
|
73 | if (type == "quote") {
|
74 | return content.split("\n").map(l => "> " + l).join("\n");
|
75 | }
|
76 | }
|
77 | }, {
|
78 | name: "parse",
|
79 | transform(file, content, ...props) {
|
80 | var json = JSON.parse(content);
|
81 | while (props.length) {
|
82 | json = json[props.shift()];
|
83 | }
|
84 | return json;
|
85 | }
|
86 | }, {
|
87 | name: "trim",
|
88 | transform(file, content) {
|
89 | return content.trim();
|
90 | }
|
91 | }]
|
92 | }; |
\ | No newline at end of file |