-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathparse-blueprint-package.js
More file actions
63 lines (55 loc) · 1.33 KB
/
parse-blueprint-package.js
File metadata and controls
63 lines (55 loc) · 1.33 KB
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
'use strict';
const path = require('path');
const { URL } = require('url');
const fs = require('fs-extra');
function toPosixAbsolutePath(path) {
let posixPath = path.replace(/\\/g, '/').replace(/^(.+):/, function() {
return arguments[1].toLowerCase();
});
if (!posixPath.startsWith('/')) {
posixPath = `/${posixPath}`;
}
return posixPath;
}
async function parseBlueprintPackage({
cwd = '.',
packageName,
localLocation,
}) {
let name;
let location;
let url;
let blueprintPath;
if (localLocation) {
return {
name: packageName,
location: localLocation,
};
}
if (packageName.startsWith('.')) {
blueprintPath = path.resolve(cwd, packageName);
} else if (path.isAbsolute(packageName) && await fs.pathExists(packageName)) {
blueprintPath = packageName;
}
if (blueprintPath) {
let posixBlueprintPath = toPosixAbsolutePath(blueprintPath);
url = `git+file://${posixBlueprintPath}`;
location = packageName;
} else {
try {
// This matches Window's paths, so it can't be done first.
new URL(packageName);
url = packageName;
location = packageName;
} catch (err) {
name = packageName;
}
}
return {
name,
location,
url
};
}
module.exports = parseBlueprintPackage;
module.exports.toPosixAbsolutePath = toPosixAbsolutePath;