forked from microsoft/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
md-magic.config.js
71 lines (60 loc) · 2.52 KB
/
md-magic.config.js
1
2
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
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
const fs = require("fs");
const pathLib = require("path");
const getPackageName = (path) => {
try {
const pkg = JSON.parse(fs.readFileSync(path, "utf8"));
return pkg.name;
} catch (ex) {
console.log(ex);
}
}
const getPackagePath = (path) => {
const inPosix = pathLib.dirname(path).split(pathLib.sep).join(pathLib.posix.sep);
return inPosix;
}
const getStartedInfo = (path, includeTinylicious = false) => {
const preamble = `<!-- The getting started instructions are automatically generated.
To update them, edit md-magic.config.js in the root of the repo, then run npm run readme:update -->
## Getting Started
You can run this example using the following steps:
1. Run \`npm install\` and \`npm run build:fast -- --nolint\` from the \`FluidFramework\` root directory.
a. For an even faster build, you can add the package name to the build command, like this:
\`npm run build:fast -- --nolint ${getPackageName(path)}\``;
const tinyliciousStep = `1. In a separate terminal, start a Tinylicious server by following the instructions in [Tinylicious](../../../server/tinylicious).`;
const finalStep = `1. Run \`npm run start\` from this directory (${getPackagePath(path)}) and open <http://localhost:8080> in a web browser to see the app running.`;
const steps = [
preamble,
includeTinylicious ? tinyliciousStep : undefined,
finalStep,
].filter(item => item !== undefined);
return steps.join("\n");
}
/* markdown-magic config */
module.exports = {
transforms: {
/* Match <!-- AUTO-GENERATED-CONTENT:START (INCLUDE:path=../file.js) --> */
INCLUDE(content, options) {
const fileContents = fs.readFileSync(options.path, "utf8");
return fileContents;
},
/* Match <!-- AUTO-GENERATED-CONTENT:START (GET_STARTED) --> */
GET_STARTED(content, options, config) {
// console.log(JSON.stringify(config, null, 2));
const dir = pathLib.dirname(config.originalPath);
const jsonPath = pathLib.join(dir, "package.json");
if(options && options.tinylicious) {
return getStartedInfo(jsonPath, options.tinylicious);
}else {
return getStartedInfo(jsonPath, false);
}
},
// SCRIPTS: require("markdown-magic-package-scripts"),
},
callback: function () {
console.log("done");
}
}