@eik/cli 3.1.2 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/classes/alias.js +108 -114
- package/classes/index.js +58 -58
- package/classes/integrity.js +89 -97
- package/classes/login.js +47 -47
- package/classes/meta.js +75 -77
- package/classes/ping.js +53 -53
- package/classes/publish/map.js +90 -91
- package/classes/publish/package/index.js +130 -130
- package/classes/publish/package/tasks/check-bundle-sizes.js +19 -21
- package/classes/publish/package/tasks/check-if-already-published.js +67 -72
- package/classes/publish/package/tasks/cleanup.js +17 -13
- package/classes/publish/package/tasks/create-temp-directory.js +17 -17
- package/classes/publish/package/tasks/create-zip-file.js +60 -65
- package/classes/publish/package/tasks/dry-run.js +15 -15
- package/classes/publish/package/tasks/save-metafile.js +17 -17
- package/classes/publish/package/tasks/task.js +7 -7
- package/classes/publish/package/tasks/upload-files.js +53 -56
- package/classes/publish/package/tasks/validate-input.js +24 -24
- package/classes/version.js +152 -163
- package/commands/alias.js +87 -87
- package/commands/index.js +24 -24
- package/commands/init.js +98 -105
- package/commands/integrity.js +52 -52
- package/commands/login.js +96 -98
- package/commands/map-alias.js +73 -73
- package/commands/map.js +72 -72
- package/commands/meta.js +49 -50
- package/commands/npm-alias.js +69 -69
- package/commands/package-alias.js +79 -80
- package/commands/ping.js +25 -25
- package/commands/publish.js +120 -124
- package/commands/version.js +86 -88
- package/formatters/alias.js +60 -63
- package/formatters/artifact.js +77 -77
- package/formatters/file.js +25 -25
- package/formatters/index.js +4 -4
- package/formatters/version.js +49 -51
- package/index.js +61 -61
- package/package.json +4 -7
- package/types/classes/alias.d.ts +1 -1
- package/types/classes/integrity.d.ts +1 -1
- package/types/classes/login.d.ts +1 -1
- package/types/classes/meta.d.ts +1 -1
- package/types/classes/ping.d.ts +1 -1
- package/types/classes/publish/map.d.ts +1 -1
- package/types/classes/publish/package/index.d.ts +11 -11
- package/types/classes/publish/package/tasks/check-bundle-sizes.d.ts +1 -1
- package/types/classes/publish/package/tasks/check-if-already-published.d.ts +1 -1
- package/types/classes/publish/package/tasks/cleanup.d.ts +1 -1
- package/types/classes/publish/package/tasks/create-temp-directory.d.ts +1 -1
- package/types/classes/publish/package/tasks/create-zip-file.d.ts +1 -1
- package/types/classes/publish/package/tasks/dry-run.d.ts +1 -1
- package/types/classes/publish/package/tasks/save-metafile.d.ts +1 -1
- package/types/classes/publish/package/tasks/task.d.ts +1 -1
- package/types/classes/publish/package/tasks/upload-files.d.ts +1 -1
- package/types/classes/publish/package/tasks/validate-input.d.ts +1 -1
- package/types/classes/version.d.ts +3 -3
- package/types/utils/hash/index.d.ts +3 -3
- package/types/utils/http/index.d.ts +4 -4
- package/types/utils/index.d.ts +3 -3
- package/types/utils/json/index.d.ts +3 -3
- package/types/utils/url.d.ts +6 -0
- package/utils/hash/file.js +4 -4
- package/utils/hash/files.js +9 -9
- package/utils/hash/index.js +3 -3
- package/utils/http/index.js +4 -4
- package/utils/http/integrity.js +18 -18
- package/utils/http/latest-version.js +37 -37
- package/utils/http/request.js +42 -42
- package/utils/http/versions.js +20 -20
- package/utils/index.js +3 -3
- package/utils/json/index.js +3 -3
- package/utils/json/read.js +26 -26
- package/utils/json/write-eik.js +17 -17
- package/utils/json/write.js +26 -28
- package/utils/logger.js +43 -43
- package/utils/type-title.js +3 -3
- package/utils/url.js +10 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
import { join } from
|
1
|
+
import { join } from "path";
|
2
2
|
|
3
3
|
/**
|
4
4
|
* Fetches the latest version from an Eik server of a package by name, optionally restricting the lookup to a specified semver major version
|
@@ -12,44 +12,44 @@ import { join } from 'path';
|
|
12
12
|
* @throws Error
|
13
13
|
*/
|
14
14
|
export default async (server, type, name, major) => {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
const url = new URL(`${join(type, name)}?t=${Date.now()}`, server);
|
16
|
+
const res = await fetch(url);
|
17
|
+
if (!res.ok) {
|
18
|
+
if (res.status === 404) {
|
19
|
+
return null;
|
20
|
+
}
|
21
|
+
throw new Error("Server responded with non 200 status code.");
|
22
|
+
}
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
let body;
|
25
|
+
try {
|
26
|
+
body = await res.json();
|
27
|
+
} catch (err) {
|
28
|
+
throw new Error(
|
29
|
+
"An error occurred while attempting to parse json response from server.",
|
30
|
+
);
|
31
|
+
}
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
let versions;
|
34
|
+
try {
|
35
|
+
versions = new Map(body.versions);
|
36
|
+
} catch (err) {
|
37
|
+
throw new Error(
|
38
|
+
"An error occurred while attempting to create an internal versions map. The JSON returned from the server is most likely invalid.",
|
39
|
+
);
|
40
|
+
}
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
const highestMajor = Math.max(...versions.keys());
|
43
|
+
if (Number.isNaN(highestMajor)) {
|
44
|
+
throw new Error(
|
45
|
+
"An error occurred while attempting to get the highest major version from the internal versions map.",
|
46
|
+
);
|
47
|
+
}
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
try {
|
50
|
+
const entry = versions.get(Number(major || highestMajor));
|
51
|
+
return entry.version;
|
52
|
+
} catch (err) {
|
53
|
+
return null;
|
54
|
+
}
|
55
55
|
};
|
package/utils/http/request.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { readFile } from
|
1
|
+
import { readFile } from "node:fs/promises";
|
2
2
|
|
3
3
|
/**
|
4
4
|
* @typedef {object} RequestOptions
|
@@ -21,54 +21,54 @@ import { readFile } from 'node:fs/promises';
|
|
21
21
|
* @throws Error
|
22
22
|
*/
|
23
23
|
async function request(options) {
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
const { method = "POST", host, pathname, data, file, map, token } = options;
|
25
|
+
const body = new FormData();
|
26
|
+
const headers = new Headers();
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
if (data) {
|
29
|
+
for (const [key, value] of Object.entries(data)) {
|
30
|
+
body.set(key, value);
|
31
|
+
}
|
32
|
+
}
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
if (file) {
|
35
|
+
const fileData = await readFile(file);
|
36
|
+
body.set("package", new Blob([fileData]));
|
37
|
+
}
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
if (map) {
|
40
|
+
const mapData = await readFile(map);
|
41
|
+
body.set("map", new Blob([mapData]));
|
42
|
+
}
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
if (token) {
|
45
|
+
headers.set("Authorization", `Bearer ${token}`);
|
46
|
+
}
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
try {
|
49
|
+
const url = new URL(pathname, host);
|
50
|
+
url.search = `?t=${Date.now()}`;
|
51
51
|
|
52
|
-
|
52
|
+
const res = await fetch(url, { method, body, headers });
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
54
|
+
if (!res.ok) {
|
55
|
+
const err = new Error(
|
56
|
+
`Server responded with a non 200 ok status code. Response: ${res.status}`,
|
57
|
+
);
|
58
|
+
// @ts-ignore
|
59
|
+
err.statusCode = res.status;
|
60
|
+
throw err;
|
61
|
+
}
|
62
|
+
if (res?.headers?.get("content-type")?.includes("application/json")) {
|
63
|
+
return { message: await res.json(), status: res.status };
|
64
|
+
}
|
65
|
+
return { message: await res.text(), status: res.status };
|
66
|
+
} catch (err) {
|
67
|
+
if (!err.statusCode) {
|
68
|
+
err.statusCode = 500;
|
69
|
+
}
|
70
|
+
throw err;
|
71
|
+
}
|
72
72
|
}
|
73
73
|
|
74
74
|
export default request;
|
package/utils/http/versions.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { join } from
|
1
|
+
import { join } from "path";
|
2
2
|
|
3
3
|
/**
|
4
4
|
* Fetches package versions by name from a given Eik asset server.
|
@@ -11,27 +11,27 @@ import { join } from 'path';
|
|
11
11
|
* @throws Error
|
12
12
|
*/
|
13
13
|
export default async (server, type, name) => {
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
const pkg = join(type, name);
|
15
|
+
const url = new URL(pkg, server);
|
16
|
+
url.search = `?t=${Date.now()}`;
|
17
17
|
|
18
|
-
|
18
|
+
const res = await fetch(url);
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
if (!res.ok) {
|
21
|
+
if (res.status === 404) {
|
22
|
+
return null;
|
23
|
+
}
|
24
|
+
throw new Error("Server responded with non 200 status code.");
|
25
|
+
}
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
let body;
|
28
|
+
try {
|
29
|
+
body = await res.json();
|
30
|
+
} catch (err) {
|
31
|
+
throw new Error(
|
32
|
+
"An error occurred while attempting to parse json response from server.",
|
33
|
+
);
|
34
|
+
}
|
35
35
|
|
36
|
-
|
36
|
+
return body.versions;
|
37
37
|
};
|
package/utils/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { helpers } from
|
2
|
-
import logger from
|
3
|
-
import typeTitle from
|
1
|
+
import { helpers } from "@eik/common";
|
2
|
+
import logger from "./logger.js";
|
3
|
+
import typeTitle from "./type-title.js";
|
4
4
|
|
5
5
|
const { getDefaults, typeSlug } = helpers;
|
6
6
|
|
package/utils/json/index.js
CHANGED
package/utils/json/read.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import assert from
|
2
|
-
import fs from
|
3
|
-
import { join, isAbsolute } from
|
1
|
+
import assert from "assert";
|
2
|
+
import fs from "node:fs/promises";
|
3
|
+
import { join, isAbsolute } from "path";
|
4
4
|
|
5
5
|
/**
|
6
6
|
* Reads a file at a given location, assumes the contents to be JSON and then deserializes into a JavaScript object
|
@@ -17,27 +17,27 @@ import { join, isAbsolute } from 'path';
|
|
17
17
|
* @example json.read({ filename: './relative/path/to/file.json', cwd: '/path/to/cwd });
|
18
18
|
*/
|
19
19
|
export default async (location) => {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
20
|
+
if (typeof location !== "string") {
|
21
|
+
assert(
|
22
|
+
location.filename,
|
23
|
+
'When "location" is not of type "string" then it must be an "object" with property "filename"',
|
24
|
+
);
|
25
|
+
}
|
26
|
+
let cwd = process.cwd();
|
27
|
+
let filename = "";
|
28
|
+
if (typeof location === "string") {
|
29
|
+
filename = location;
|
30
|
+
} else {
|
31
|
+
filename = location.filename;
|
32
|
+
if (location.cwd) {
|
33
|
+
cwd = location.cwd;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
const path = isAbsolute(filename) ? filename : join(cwd, filename);
|
37
|
+
try {
|
38
|
+
const meta = await fs.readFile(path, "utf8");
|
39
|
+
return JSON.parse(meta);
|
40
|
+
} catch (err) {
|
41
|
+
return {};
|
42
|
+
}
|
43
43
|
};
|
package/utils/json/write-eik.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import fs from
|
2
|
-
import { join } from
|
1
|
+
import fs from "node:fs/promises";
|
2
|
+
import { join } from "path";
|
3
3
|
|
4
4
|
/**
|
5
5
|
* Reads, updates and then writes data to given eik.json file (defaults to file in current directory)
|
@@ -14,20 +14,20 @@ import { join } from 'path';
|
|
14
14
|
* @example json.writeEik({ key: 'value' }, { cwd: '/path/to/cwd', filename: 'eik.json' });
|
15
15
|
*/
|
16
16
|
export default async (data = {}, options) => {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
const { cwd = process.cwd(), filename = "eik.json" } = options;
|
18
|
+
const eikpath = join(cwd, filename);
|
19
|
+
const eik = await fs.readFile(eikpath, "utf-8");
|
20
|
+
const eikjson = JSON.parse(eik);
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
await fs.writeFile(
|
23
|
+
eikpath,
|
24
|
+
JSON.stringify(
|
25
|
+
{
|
26
|
+
...eikjson,
|
27
|
+
...data,
|
28
|
+
},
|
29
|
+
null,
|
30
|
+
2,
|
31
|
+
),
|
32
|
+
);
|
33
33
|
};
|
package/utils/json/write.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import assert from
|
2
|
-
import fs from
|
3
|
-
import { join, isAbsolute, dirname } from
|
1
|
+
import assert from "assert";
|
2
|
+
import fs from "node:fs/promises";
|
3
|
+
import { join, isAbsolute, dirname } from "path";
|
4
4
|
|
5
5
|
/**
|
6
6
|
* Utility function that can be used to write a JavaScript object to a file at a given location.
|
@@ -20,29 +20,27 @@ import { join, isAbsolute, dirname } from 'path';
|
|
20
20
|
* @throws Error
|
21
21
|
*/
|
22
22
|
export default async (meta = {}, location) => {
|
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
|
-
}
|
23
|
+
if (typeof location !== "string") {
|
24
|
+
assert(
|
25
|
+
location.filename,
|
26
|
+
'When "location" is not of type "string" then it must be an "object" with property "filename"',
|
27
|
+
);
|
28
|
+
}
|
29
|
+
let cwd = process.cwd();
|
30
|
+
let filename = "";
|
31
|
+
if (typeof location === "string") {
|
32
|
+
filename = location;
|
33
|
+
} else {
|
34
|
+
filename = location.filename;
|
35
|
+
if (location.cwd) {
|
36
|
+
cwd = location.cwd;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
const path = isAbsolute(filename) ? filename : join(cwd, filename);
|
40
|
+
try {
|
41
|
+
await fs.mkdir(dirname(path), { recursive: true });
|
42
|
+
await fs.writeFile(path, JSON.stringify(meta, null, 2));
|
43
|
+
} catch (err) {
|
44
|
+
throw new Error(`Error writing to JSON file ["${path}"]: ${err.message}`);
|
45
|
+
}
|
48
46
|
};
|
package/utils/logger.js
CHANGED
@@ -5,50 +5,50 @@
|
|
5
5
|
* @param {boolean} debug
|
6
6
|
*/
|
7
7
|
const logger = (spinner, debug = false) => ({
|
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
|
-
|
8
|
+
/**
|
9
|
+
* @param {string} message
|
10
|
+
*/
|
11
|
+
fatal(message) {
|
12
|
+
spinner.fail(message).start();
|
13
|
+
},
|
14
|
+
/**
|
15
|
+
* @param {string} message
|
16
|
+
*/
|
17
|
+
error(message) {
|
18
|
+
spinner.fail(message).start();
|
19
|
+
},
|
20
|
+
/**
|
21
|
+
* @param {string} message
|
22
|
+
*/
|
23
|
+
warn(message) {
|
24
|
+
spinner.warn(message).start();
|
25
|
+
},
|
26
|
+
/**
|
27
|
+
* @param {string} message
|
28
|
+
*/
|
29
|
+
info(message) {
|
30
|
+
if (typeof message !== "string") {
|
31
|
+
spinner.text = "";
|
32
|
+
spinner.stopAndPersist();
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
34
|
+
console.log(message);
|
35
|
+
spinner.start();
|
36
|
+
} else {
|
37
|
+
spinner.succeed(message).start();
|
38
|
+
}
|
39
|
+
},
|
40
|
+
/**
|
41
|
+
* @param {string} message
|
42
|
+
*/
|
43
|
+
debug(message) {
|
44
|
+
if (debug) spinner.info(message).start();
|
45
|
+
},
|
46
|
+
/**
|
47
|
+
* @param {string} message
|
48
|
+
*/
|
49
|
+
trace(message) {
|
50
|
+
if (debug) spinner.info(message).start();
|
51
|
+
},
|
52
52
|
});
|
53
53
|
|
54
54
|
export default logger;
|
package/utils/type-title.js
CHANGED
package/utils/url.js
ADDED