Skip to content

Commit

Permalink
JSDoc config JSON: Fix paths on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Mar 11, 2019
1 parent 207a506 commit 5718c87
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
25 changes: 19 additions & 6 deletions lib/processors/jsdoc/jsdocGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,40 @@ const jsdocGenerator = async function({sourcePath, targetPath, tmpPath, options}
* @returns {string} jsdoc-config.json content string
*/
async function generateJsdocConfig({targetPath, tmpPath, namespace, projectName, version, variants}) {
// Backlash needs to be escaped as double-backslash
// This is not only relevant for win32 paths but also for
// Unix directory names that contain a backslash in their name
const backslashRegex = /\\/g;

// Resolve path to this script to get the path to the JSDoc extensions folder
const jsdocPath = path.normalize(__dirname);
const pluginPath = path.join(jsdocPath, "lib", "ui5", "plugin.js").replace(backslashRegex, "\\\\");
const templatePath = path.join(jsdocPath, "lib", "ui5", "template").replace(backslashRegex, "\\\\");
const destinationPath = path.normalize(tmpPath).replace(backslashRegex, "\\\\");
const jsapiFilePath = path.join(targetPath, "libraries", projectName + ".js").replace(backslashRegex, "\\\\");
const apiJsonFolderPath = path.join(tmpPath, "dependency-apis").replace(backslashRegex, "\\\\");
const apiJsonFilePath =
path.join(targetPath, "test-resources", path.normalize(namespace), "designtime", "api.json")
.replace(backslashRegex, "\\\\");

const config = `{
"plugins": ["${jsdocPath}/lib/ui5/plugin.js"],
"plugins": ["${pluginPath}"],
"opts": {
"recurse": true,
"lenient": true,
"template": "${jsdocPath}/lib/ui5/template",
"template": "${templatePath}",
"ui5": {
"saveSymbols": true
},
"destination": "${tmpPath}"
"destination": "${destinationPath}"
},
"templates": {
"ui5": {
"variants": ${JSON.stringify(variants)},
"version": "${version}",
"jsapiFile": "${targetPath}/libraries/${projectName}.js",
"apiJsonFolder": "${tmpPath}/dependency-apis",
"apiJsonFile": "${targetPath}/test-resources/${namespace}/designtime/api.json"
"jsapiFile": "${jsapiFilePath}",
"apiJsonFolder": "${apiJsonFolderPath}",
"apiJsonFile": "${apiJsonFilePath}"
}
}
}`;
Expand Down
31 changes: 24 additions & 7 deletions test/lib/processors/jsdoc/jsdocGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test("generateJsdocConfig", async (t) => {
const res = await jsdocGenerator._generateJsdocConfig({
sourcePath: "/some/source/path",
targetPath: "/some/target/path",
tmpPath: "/some/tmp/path",
tmpPath: "/some/tm\\p/path",
namespace: "some/namespace",
projectName: "some.namespace",
version: "1.0.0",
Expand All @@ -18,24 +18,41 @@ test("generateJsdocConfig", async (t) => {
const jsdocGeneratorPath = path.resolve(__dirname, "..", "..", "..", "..", "lib", "processors",
"jsdoc");

const backslashRegex = /\\/g;

const pluginPath = path.join(jsdocGeneratorPath, "lib", "ui5", "plugin.js")
.replace(backslashRegex, "\\\\");
const templatePath = path.join(jsdocGeneratorPath, "lib", "ui5", "template")
.replace(backslashRegex, "\\\\");
const destinationPath = path.join("/", "some", "tm\\p", "path")
.replace(backslashRegex, "\\\\");
const jsapiFilePath = path.join("/", "some", "target", "path", "libraries", "some.namespace.js")
.replace(backslashRegex, "\\\\");
const apiJsonFolderPath = path.join("/", "some", "tm\\p", "path", "dependency-apis")
.replace(backslashRegex, "\\\\");
const apiJsonFilePath =
path.join("/", "some", "target", "path", "test-resources", "some", "namespace", "designtime", "api.json")
.replace(backslashRegex, "\\\\");


t.deepEqual(res, `{
"plugins": ["${jsdocGeneratorPath}/lib/ui5/plugin.js"],
"plugins": ["${pluginPath}"],
"opts": {
"recurse": true,
"lenient": true,
"template": "${jsdocGeneratorPath}/lib/ui5/template",
"template": "${templatePath}",
"ui5": {
"saveSymbols": true
},
"destination": "/some/tmp/path"
"destination": "${destinationPath}"
},
"templates": {
"ui5": {
"variants": ["apijson"],
"version": "1.0.0",
"jsapiFile": "/some/target/path/libraries/some.namespace.js",
"apiJsonFolder": "/some/tmp/path/dependency-apis",
"apiJsonFile": "/some/target/path/test-resources/some/namespace/designtime/api.json"
"jsapiFile": "${jsapiFilePath}",
"apiJsonFolder": "${apiJsonFolderPath}",
"apiJsonFile": "${apiJsonFilePath}"
}
}
}`, "Correct config generated");
Expand Down

0 comments on commit 5718c87

Please sign in to comment.