-
Notifications
You must be signed in to change notification settings - Fork 79
/
make.js
50 lines (41 loc) · 3.4 KB
/
make.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
var path = require("path");
// Making resharper less noisy - These are defined in Generate.js
if (typeof (getCompiledTemplate) === "undefined") getCompiledTemplate = function () { };
if (typeof (templatizeTree) === "undefined") templatizeTree = function () { };
// generate.js looks for some specific exported functions (as defined in TOC.json) in make.js, like:
exports.makeClientAPI2 = function (apis, sourceDir, apiOutputDir) {
// Builds the client api. The provided "api" variable is a single object, the API_SPECS/client.api.json as an object
console.log("Generating Client api from: " + sourceDir + " to: " + apiOutputDir);
templatizeTree({}, path.resolve(sourceDir, "source"), apiOutputDir); // Copy the whole source directory as-is
MakeExampleTemplateFile(sourceDir, apiOutputDir);
}
// generate.js looks for some specific exported functions (as defined in TOC.json) in make.js, like:
exports.makeServerAPI = function (apis, sourceDir, apiOutputDir) {
// Builds the server api. The provided "apis" variable is a list of objects, Examples: API_SPECS/Legacy/PlayFab/admin.api.json and API_SPECS/Legacy/PlayFab/server.api.json
// If you don't want admin, you should filter it out yourself (for now)
console.log("Generating Server api from: " + sourceDir + " to: " + apiOutputDir);
templatizeTree({}, path.resolve(sourceDir, "source"), apiOutputDir); // Copy the whole source directory as-is
MakeExampleTemplateFile(sourceDir, apiOutputDir);
}
// generate.js looks for some specific exported functions (as defined in TOC.json) in make.js, like:
exports.makeCombinedAPI = function (apis, sourceDir, apiOutputDir) {
// Builds every api. The provided "apis" variable is a list of objects, Examples: API_SPECS/Legacy/PlayFab/admin.api.json, API_SPECS/Legacy/PlayFab/server.api.json, and API_SPECS/Legacy/PlayFab/client.api.json
console.log("Generating Combined api from: " + sourceDir + " to: " + apiOutputDir);
templatizeTree({}, path.resolve(sourceDir, "source"), apiOutputDir); // Copy the whole source directory as-is
MakeExampleTemplateFile(sourceDir, apiOutputDir);
}
// Unlike source, Templates are written one file at a time.
// You may want to write a helper function to write each template file, so you can call it from multiple places
function MakeExampleTemplateFile(sourceDir, apiOutputDir) {
// Each template must be given any variables/information that it needs for generation.
// This might include apis, datatypes, custom functions defined in this make.js file, or anything else you want
var locals = {};
locals.GeneratedText = "This is generated text"; // A specific variable we wish to access in exampleTemplate.txt.ejs
locals.sdkVersion = sdkGlobals.sdkVersion; // sdkGlobals.sdkVersion is automatically injected into this file from generate.js, and comes from SdkManualNotes.json - you must provide your target in that file
// Compiles the source .ejs file into a template function.
var template = getCompiledTemplate(path.resolve(sourceDir, "templates/exampleTemplate.txt.ejs"));
// Call the template function, which executes the template, and evaluates all the ejs tags/logic
var generatedTemplateText = template(locals);
// generatedTemplateText is an in-memory string of the output file. At this point, you just write it to the destination:
writeFile(path.resolve(apiOutputDir, "exampleTemplate.txt"), generatedTemplateText);
}