-
Notifications
You must be signed in to change notification settings - Fork 36
/
generate-path-prefix.js
30 lines (26 loc) · 1.22 KB
/
generate-path-prefix.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
const { normalizePath } = require('./normalize-path');
const generatePathPrefix = ({ commitHash, parserBranch, patchId, pathPrefix, project, snootyBranch, user }) => {
// If user specified a PATH_PREFIX environment variable, ensure it begins with a prefix and use
if (pathPrefix) {
if (pathPrefix.startsWith('/')) {
return pathPrefix;
}
return `/${pathPrefix}`;
}
let prefix = '';
if (commitHash) prefix += `${commitHash}`;
if (patchId) prefix += `/${patchId}`;
// Include the Snooty branch in pathPrefix for Snooty developers. mut automatically
// includes the git branch of the repo where it is called, so this parameter must
// be present in the URL's path prefix in order to be mut-compatible.
//
// TODO: Simplify this logic when Snooty development is staged in integration environment
const base = `${project}/${user}`;
const path = process.env.GATSBY_SNOOTY_DEV
? `/${prefix}/${parserBranch}/${base}/${snootyBranch}`
: `/${prefix}/${base}/${parserBranch}`;
return normalizePath(path);
};
// TODO: switch to ES6 export syntax if Gatsby implements support for ES6 module imports
// https://github.com/gatsbyjs/gatsby/issues/7810
module.exports.generatePathPrefix = generatePathPrefix;