@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.
Files changed (79) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/classes/alias.js +108 -114
  3. package/classes/index.js +58 -58
  4. package/classes/integrity.js +89 -97
  5. package/classes/login.js +47 -47
  6. package/classes/meta.js +75 -77
  7. package/classes/ping.js +53 -53
  8. package/classes/publish/map.js +90 -91
  9. package/classes/publish/package/index.js +130 -130
  10. package/classes/publish/package/tasks/check-bundle-sizes.js +19 -21
  11. package/classes/publish/package/tasks/check-if-already-published.js +67 -72
  12. package/classes/publish/package/tasks/cleanup.js +17 -13
  13. package/classes/publish/package/tasks/create-temp-directory.js +17 -17
  14. package/classes/publish/package/tasks/create-zip-file.js +60 -65
  15. package/classes/publish/package/tasks/dry-run.js +15 -15
  16. package/classes/publish/package/tasks/save-metafile.js +17 -17
  17. package/classes/publish/package/tasks/task.js +7 -7
  18. package/classes/publish/package/tasks/upload-files.js +53 -56
  19. package/classes/publish/package/tasks/validate-input.js +24 -24
  20. package/classes/version.js +152 -163
  21. package/commands/alias.js +87 -87
  22. package/commands/index.js +24 -24
  23. package/commands/init.js +98 -105
  24. package/commands/integrity.js +52 -52
  25. package/commands/login.js +96 -98
  26. package/commands/map-alias.js +73 -73
  27. package/commands/map.js +72 -72
  28. package/commands/meta.js +49 -50
  29. package/commands/npm-alias.js +69 -69
  30. package/commands/package-alias.js +79 -80
  31. package/commands/ping.js +25 -25
  32. package/commands/publish.js +120 -124
  33. package/commands/version.js +86 -88
  34. package/formatters/alias.js +60 -63
  35. package/formatters/artifact.js +77 -77
  36. package/formatters/file.js +25 -25
  37. package/formatters/index.js +4 -4
  38. package/formatters/version.js +49 -51
  39. package/index.js +61 -61
  40. package/package.json +4 -7
  41. package/types/classes/alias.d.ts +1 -1
  42. package/types/classes/integrity.d.ts +1 -1
  43. package/types/classes/login.d.ts +1 -1
  44. package/types/classes/meta.d.ts +1 -1
  45. package/types/classes/ping.d.ts +1 -1
  46. package/types/classes/publish/map.d.ts +1 -1
  47. package/types/classes/publish/package/index.d.ts +11 -11
  48. package/types/classes/publish/package/tasks/check-bundle-sizes.d.ts +1 -1
  49. package/types/classes/publish/package/tasks/check-if-already-published.d.ts +1 -1
  50. package/types/classes/publish/package/tasks/cleanup.d.ts +1 -1
  51. package/types/classes/publish/package/tasks/create-temp-directory.d.ts +1 -1
  52. package/types/classes/publish/package/tasks/create-zip-file.d.ts +1 -1
  53. package/types/classes/publish/package/tasks/dry-run.d.ts +1 -1
  54. package/types/classes/publish/package/tasks/save-metafile.d.ts +1 -1
  55. package/types/classes/publish/package/tasks/task.d.ts +1 -1
  56. package/types/classes/publish/package/tasks/upload-files.d.ts +1 -1
  57. package/types/classes/publish/package/tasks/validate-input.d.ts +1 -1
  58. package/types/classes/version.d.ts +3 -3
  59. package/types/utils/hash/index.d.ts +3 -3
  60. package/types/utils/http/index.d.ts +4 -4
  61. package/types/utils/index.d.ts +3 -3
  62. package/types/utils/json/index.d.ts +3 -3
  63. package/types/utils/url.d.ts +6 -0
  64. package/utils/hash/file.js +4 -4
  65. package/utils/hash/files.js +9 -9
  66. package/utils/hash/index.js +3 -3
  67. package/utils/http/index.js +4 -4
  68. package/utils/http/integrity.js +18 -18
  69. package/utils/http/latest-version.js +37 -37
  70. package/utils/http/request.js +42 -42
  71. package/utils/http/versions.js +20 -20
  72. package/utils/index.js +3 -3
  73. package/utils/json/index.js +3 -3
  74. package/utils/json/read.js +26 -26
  75. package/utils/json/write-eik.js +17 -17
  76. package/utils/json/write.js +26 -28
  77. package/utils/logger.js +43 -43
  78. package/utils/type-title.js +3 -3
  79. package/utils/url.js +10 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [3.1.4](https://github.com/eik-lib/cli/compare/v3.1.3...v3.1.4) (2024-08-26)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update dependency ora to v8.1.0 ([7a784bc](https://github.com/eik-lib/cli/commit/7a784bc3f36713d932041a7b7c9a7dc56ffc0a63))
7
+
8
+ ## [3.1.3](https://github.com/eik-lib/cli/compare/v3.1.2...v3.1.3) (2024-08-19)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add support for Windows ([#584](https://github.com/eik-lib/cli/issues/584)) ([3d2dc7e](https://github.com/eik-lib/cli/commit/3d2dc7ef87abc48a3b4b796e5d717b280837974b))
14
+
1
15
  ## [3.1.2](https://github.com/eik-lib/cli/compare/v3.1.1...v3.1.2) (2024-08-19)
2
16
 
3
17
 
package/classes/alias.js CHANGED
@@ -1,9 +1,9 @@
1
- import assert from 'assert';
2
- import abslog from 'abslog';
3
- import { join } from 'path';
4
- import { schemas, validators } from '@eik/common';
5
- import { request } from '../utils/http/index.js';
6
- import { typeSlug } from '../utils/index.js';
1
+ import assert from "assert";
2
+ import abslog from "abslog";
3
+ import { schemas, validators } from "@eik/common";
4
+ import { request } from "../utils/http/index.js";
5
+ import { typeSlug } from "../utils/index.js";
6
+ import { joinUrlPathname } from "../utils/url.js";
7
7
 
8
8
  /**
9
9
  * @typedef {object} AliasOptions
@@ -30,123 +30,117 @@ import { typeSlug } from '../utils/index.js';
30
30
  */
31
31
 
32
32
  export default class Alias {
33
- /**
34
- * @param {AliasOptions} options
35
- */
36
- constructor({ logger, server, token, type, name, version, alias }) {
37
- this.log = abslog(logger);
38
- this.server = server;
39
- this.token = token;
40
- this.type = typeSlug(type);
41
- this.name = name;
42
- this.alias = alias;
43
- this.version = version;
44
- }
33
+ /**
34
+ * @param {AliasOptions} options
35
+ */
36
+ constructor({ logger, server, token, type, name, version, alias }) {
37
+ this.log = abslog(logger);
38
+ this.server = server;
39
+ this.token = token;
40
+ this.type = typeSlug(type);
41
+ this.name = name;
42
+ this.alias = alias;
43
+ this.version = version;
44
+ }
45
45
 
46
- /**
47
- * @returns {Promise<AliasResult>}
48
- */
49
- async run() {
50
- const data = {
51
- server: this.server,
52
- type: this.type,
53
- name: this.name,
54
- alias: this.alias,
55
- version: this.version,
56
- update: false,
57
- files: [],
58
- org: '',
59
- integrity: '',
60
- };
46
+ /**
47
+ * @returns {Promise<AliasResult>}
48
+ */
49
+ async run() {
50
+ const data = {
51
+ server: this.server,
52
+ type: this.type,
53
+ name: this.name,
54
+ alias: this.alias,
55
+ version: this.version,
56
+ update: false,
57
+ files: [],
58
+ org: "",
59
+ integrity: "",
60
+ };
61
61
 
62
- this.log.debug('Validating command input');
63
- schemas.assert.server(this.server);
64
- schemas.assert.name(this.name);
65
- schemas.assert.version(this.version);
66
- validators.type(this.type);
67
- validators.alias(this.alias);
68
- assert(
69
- this.token && typeof this.token === 'string',
70
- `Parameter "token" is not valid`,
71
- );
62
+ this.log.debug("Validating command input");
63
+ schemas.assert.server(this.server);
64
+ schemas.assert.name(this.name);
65
+ schemas.assert.version(this.version);
66
+ validators.type(this.type);
67
+ validators.alias(this.alias);
68
+ assert(
69
+ this.token && typeof this.token === "string",
70
+ `Parameter "token" is not valid`,
71
+ );
72
72
 
73
- this.log.debug(
74
- `Requesting creation of ${this.type} alias "v${this.alias}" for ${this.name} v${this.version} on ${this.server}`,
75
- );
73
+ this.log.debug(
74
+ `Requesting creation of ${this.type} alias "v${this.alias}" for ${this.name} v${this.version} on ${this.server}`,
75
+ );
76
76
 
77
- const pathname = join(this.type, this.name, `v${this.alias}`);
78
- try {
79
- const { message } = await request({
80
- host: this.server,
81
- method: 'PUT',
82
- pathname,
83
- data: { version: this.version },
84
- token: this.token,
85
- });
77
+ const pathname = joinUrlPathname(this.type, this.name, `v${this.alias}`);
78
+ try {
79
+ const { message } = await request({
80
+ host: this.server,
81
+ method: "PUT",
82
+ pathname,
83
+ data: { version: this.version },
84
+ token: this.token,
85
+ });
86
86
 
87
- data.org = message.org || '';
88
- data.integrity = message.integrity || '';
89
- data.version = message.version || this.version;
90
- data.name = message.name || this.name;
91
- data.files = message.files || [];
87
+ data.org = message.org || "";
88
+ data.integrity = message.integrity || "";
89
+ data.version = message.version || this.version;
90
+ data.name = message.name || this.name;
91
+ data.files = message.files || [];
92
92
 
93
- return data;
94
- } catch (err) {
95
- let status = err.statusCode;
93
+ return data;
94
+ } catch (err) {
95
+ let status = err.statusCode;
96
96
 
97
- if (status === 409) {
98
- this.log.debug(
99
- 'Alias already exists on server, performing update',
100
- );
97
+ if (status === 409) {
98
+ this.log.debug("Alias already exists on server, performing update");
101
99
 
102
- try {
103
- const { message: msg } = await request({
104
- host: this.server,
105
- method: 'POST',
106
- pathname,
107
- data: { version: this.version },
108
- token: this.token,
109
- });
100
+ try {
101
+ const { message: msg } = await request({
102
+ host: this.server,
103
+ method: "POST",
104
+ pathname,
105
+ data: { version: this.version },
106
+ token: this.token,
107
+ });
110
108
 
111
- data.org = msg.org || '';
112
- data.integrity = msg.integrity || '';
113
- data.version = msg.version || this.version;
114
- data.name = msg.name || this.name;
115
- data.files = msg.files || [];
116
- data.update = true;
109
+ data.org = msg.org || "";
110
+ data.integrity = msg.integrity || "";
111
+ data.version = msg.version || this.version;
112
+ data.name = msg.name || this.name;
113
+ data.files = msg.files || [];
114
+ data.update = true;
117
115
 
118
- return data;
119
- } catch (error) {
120
- status = error.statusCode;
121
- }
122
- }
116
+ return data;
117
+ } catch (error) {
118
+ status = error.statusCode;
119
+ }
120
+ }
123
121
 
124
- switch (status) {
125
- case 400:
126
- throw new Error(
127
- 'Client attempted to send an invalid URL parameter',
128
- );
129
- case 401:
130
- throw new Error('Client unauthorized with server');
131
- case 404:
132
- throw new Error(
133
- `The server was unable to locate ${pathname}. Ensure you have the correct package type (eik package-alias vs eik npm-alias), name and that the version exists on the server.`,
134
- );
135
- case 409:
136
- throw new Error(
137
- `${this.type} with name "${this.name}" and version "${this.version}" already exists on server`,
138
- );
139
- case 415:
140
- throw new Error(
141
- 'Client attempted to send an unsupported file format to server',
142
- );
143
- case 502:
144
- throw new Error(
145
- 'Server was unable to write file to storage',
146
- );
147
- default:
148
- throw new Error('Server failure');
149
- }
150
- }
151
- }
122
+ switch (status) {
123
+ case 400:
124
+ throw new Error("Client attempted to send an invalid URL parameter");
125
+ case 401:
126
+ throw new Error("Client unauthorized with server");
127
+ case 404:
128
+ throw new Error(
129
+ `The server was unable to locate ${pathname}. Ensure you have the correct package type (eik package-alias vs eik npm-alias), name and that the version exists on the server.`,
130
+ );
131
+ case 409:
132
+ throw new Error(
133
+ `${this.type} with name "${this.name}" and version "${this.version}" already exists on server`,
134
+ );
135
+ case 415:
136
+ throw new Error(
137
+ "Client attempted to send an unsupported file format to server",
138
+ );
139
+ case 502:
140
+ throw new Error("Server was unable to write file to storage");
141
+ default:
142
+ throw new Error("Server failure");
143
+ }
144
+ }
145
+ }
152
146
  }
package/classes/index.js CHANGED
@@ -1,68 +1,68 @@
1
- import Ping from './ping.js';
2
- import Alias from './alias.js';
3
- import Meta from './meta.js';
4
- import Login from './login.js';
5
- import PublishMap from './publish/map.js';
6
- import PublishPackage from './publish/package/index.js';
7
- import Integrity from './integrity.js';
8
- import Version from './version.js';
1
+ import Ping from "./ping.js";
2
+ import Alias from "./alias.js";
3
+ import Meta from "./meta.js";
4
+ import Login from "./login.js";
5
+ import PublishMap from "./publish/map.js";
6
+ import PublishPackage from "./publish/package/index.js";
7
+ import Integrity from "./integrity.js";
8
+ import Version from "./version.js";
9
9
 
10
10
  export default {
11
- /**
12
- * @param {import('./alias.js').AliasOptions} opts
13
- */
14
- alias(opts) {
15
- return new Alias(opts).run();
16
- },
11
+ /**
12
+ * @param {import('./alias.js').AliasOptions} opts
13
+ */
14
+ alias(opts) {
15
+ return new Alias(opts).run();
16
+ },
17
17
 
18
- /**
19
- * @param {import('./integrity.js').IntegrityOptions} opts
20
- */
21
- integrity(opts) {
22
- return new Integrity(opts).run();
23
- },
18
+ /**
19
+ * @param {import('./integrity.js').IntegrityOptions} opts
20
+ */
21
+ integrity(opts) {
22
+ return new Integrity(opts).run();
23
+ },
24
24
 
25
- /**
26
- * Log in using a key to get a Bearer token for use with other commands.
27
- *
28
- * @param {import('./login.js').LoginOptions} opts
29
- */
30
- login(opts) {
31
- return new Login(opts).run();
32
- },
25
+ /**
26
+ * Log in using a key to get a Bearer token for use with other commands.
27
+ *
28
+ * @param {import('./login.js').LoginOptions} opts
29
+ */
30
+ login(opts) {
31
+ return new Login(opts).run();
32
+ },
33
33
 
34
- /**
35
- * @param {import('./publish/map.js').PublishMapOptions} opts
36
- */
37
- map(opts) {
38
- return new PublishMap(opts).run();
39
- },
34
+ /**
35
+ * @param {import('./publish/map.js').PublishMapOptions} opts
36
+ */
37
+ map(opts) {
38
+ return new PublishMap(opts).run();
39
+ },
40
40
 
41
- /**
42
- * @param {import('./meta.js').MetaOptions} opts
43
- */
44
- meta(opts) {
45
- return new Meta(opts).run();
46
- },
41
+ /**
42
+ * @param {import('./meta.js').MetaOptions} opts
43
+ */
44
+ meta(opts) {
45
+ return new Meta(opts).run();
46
+ },
47
47
 
48
- /**
49
- * @param {import('./ping.js').PingOptions} opts
50
- */
51
- ping(opts) {
52
- return new Ping(opts).run();
53
- },
48
+ /**
49
+ * @param {import('./ping.js').PingOptions} opts
50
+ */
51
+ ping(opts) {
52
+ return new Ping(opts).run();
53
+ },
54
54
 
55
- /**
56
- * @param {import('./publish/package/index.js').PublishOptions} opts
57
- */
58
- publish(opts) {
59
- return new PublishPackage(opts).run();
60
- },
55
+ /**
56
+ * @param {import('./publish/package/index.js').PublishOptions} opts
57
+ */
58
+ publish(opts) {
59
+ return new PublishPackage(opts).run();
60
+ },
61
61
 
62
- /**
63
- * @param {import('./version.js').VersionOptions} opts
64
- */
65
- version(opts) {
66
- return new Version(opts).run();
67
- },
62
+ /**
63
+ * @param {import('./version.js').VersionOptions} opts
64
+ */
65
+ version(opts) {
66
+ return new Version(opts).run();
67
+ },
68
68
  };
@@ -1,7 +1,7 @@
1
- import abslog from 'abslog';
2
- import { join } from 'path';
3
- import eik from '@eik/common';
4
- import { typeSlug } from '../utils/index.js';
1
+ import abslog from "abslog";
2
+ import eik from "@eik/common";
3
+ import { typeSlug } from "../utils/index.js";
4
+ import { joinUrlPathname } from "../utils/url.js";
5
5
 
6
6
  const { schemas } = eik;
7
7
 
@@ -17,97 +17,89 @@ const { schemas } = eik;
17
17
  */
18
18
 
19
19
  export default class Integrity {
20
- /**
21
- *
22
- * @param {IntegrityOptions} options
23
- */
24
- constructor({
25
- logger,
26
- name,
27
- version,
28
- server,
29
- type,
30
- debug = false,
31
- cwd = process.cwd(),
32
- }) {
33
- this.log = abslog(logger);
34
- this.server = server;
35
- this.name = name;
36
- this.version = version;
37
- this.debug = debug;
38
- this.cwd = cwd;
39
- this.type = type;
40
- }
41
-
42
- async run() {
43
- this.log.debug('Validating input');
44
-
45
- try {
46
- this.log.debug(` ==> server: ${this.server}`);
47
- schemas.assert.server(this.server);
48
-
49
- this.log.debug(` ==> name: ${this.name}`);
50
- schemas.assert.name(this.name);
51
-
52
- this.log.debug(` ==> version: ${this.version}`);
53
- schemas.assert.version(this.version);
54
-
55
- this.log.debug(` ==> type: ${this.type}`);
56
- schemas.assert.type(this.type || null);
57
-
58
- this.log.debug(` ==> debug: ${this.debug}`);
59
- if (typeof this.debug !== 'boolean') {
60
- // @ts-expect-error
61
- throw new schemas.ValidationError(
62
- `Parameter "debug" is not valid`,
63
- );
64
- }
65
-
66
- this.log.debug(` ==> cwd: ${this.cwd}`);
67
- if (typeof this.cwd !== 'string') {
68
- // @ts-expect-error
69
- throw new schemas.ValidationError(
70
- `Parameter "cwd" is not valid`,
71
- );
72
- }
73
- } catch (err) {
74
- throw new Error(
75
- `Unable to validate input to command: ${err.message}`,
76
- );
77
- }
78
-
79
- this.log.debug('Requesting meta information from asset server');
80
- try {
81
- const url = new URL(
82
- join(typeSlug(this.type), this.name, this.version),
83
- this.server,
84
- );
85
- this.log.debug(` ==> url: ${url}`);
86
-
87
- const res = await fetch(url);
88
-
89
- if (res.ok) {
90
- this.log.debug(` ==> ok: true`);
91
- return await res.json();
92
- }
93
-
94
- this.log.debug(` ==> ok: false`);
95
-
96
- if (res.status === 400) {
97
- throw new Error(
98
- 'Client attempted to send an invalid URL parameter',
99
- );
100
- }
101
-
102
- if (res.status === 401) {
103
- throw new Error('Client unauthorized with server');
104
- }
105
-
106
- throw new Error('Server Error');
107
- } catch (err) {
108
- throw new Error(
109
- `Unable to retrieve meta information for package: ${err.message}`,
110
- );
111
- }
112
- }
20
+ /**
21
+ *
22
+ * @param {IntegrityOptions} options
23
+ */
24
+ constructor({
25
+ logger,
26
+ name,
27
+ version,
28
+ server,
29
+ type,
30
+ debug = false,
31
+ cwd = process.cwd(),
32
+ }) {
33
+ this.log = abslog(logger);
34
+ this.server = server;
35
+ this.name = name;
36
+ this.version = version;
37
+ this.debug = debug;
38
+ this.cwd = cwd;
39
+ this.type = type;
40
+ }
41
+
42
+ async run() {
43
+ this.log.debug("Validating input");
44
+
45
+ try {
46
+ this.log.debug(` ==> server: ${this.server}`);
47
+ schemas.assert.server(this.server);
48
+
49
+ this.log.debug(` ==> name: ${this.name}`);
50
+ schemas.assert.name(this.name);
51
+
52
+ this.log.debug(` ==> version: ${this.version}`);
53
+ schemas.assert.version(this.version);
54
+
55
+ this.log.debug(` ==> type: ${this.type}`);
56
+ schemas.assert.type(this.type || null);
57
+
58
+ this.log.debug(` ==> debug: ${this.debug}`);
59
+ if (typeof this.debug !== "boolean") {
60
+ // @ts-expect-error
61
+ throw new schemas.ValidationError(`Parameter "debug" is not valid`);
62
+ }
63
+
64
+ this.log.debug(` ==> cwd: ${this.cwd}`);
65
+ if (typeof this.cwd !== "string") {
66
+ // @ts-expect-error
67
+ throw new schemas.ValidationError(`Parameter "cwd" is not valid`);
68
+ }
69
+ } catch (err) {
70
+ throw new Error(`Unable to validate input to command: ${err.message}`);
71
+ }
72
+
73
+ this.log.debug("Requesting meta information from asset server");
74
+ try {
75
+ const url = new URL(
76
+ joinUrlPathname(typeSlug(this.type), this.name, this.version),
77
+ this.server,
78
+ );
79
+ this.log.debug(` ==> url: ${url}`);
80
+
81
+ const res = await fetch(url);
82
+
83
+ if (res.ok) {
84
+ this.log.debug(` ==> ok: true`);
85
+ return await res.json();
86
+ }
87
+
88
+ this.log.debug(` ==> ok: false`);
89
+
90
+ if (res.status === 400) {
91
+ throw new Error("Client attempted to send an invalid URL parameter");
92
+ }
93
+
94
+ if (res.status === 401) {
95
+ throw new Error("Client unauthorized with server");
96
+ }
97
+
98
+ throw new Error("Server Error");
99
+ } catch (err) {
100
+ throw new Error(
101
+ `Unable to retrieve meta information for package: ${err.message}`,
102
+ );
103
+ }
104
+ }
113
105
  }