@eik/cli 3.1.3 → 3.1.5
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 +109 -119
- package/classes/index.js +58 -58
- package/classes/integrity.js +89 -97
- package/classes/login.js +47 -47
- package/classes/meta.js +75 -80
- package/classes/ping.js +53 -53
- package/classes/publish/map.js +90 -92
- 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 -17
- 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 +52 -56
- package/classes/publish/package/tasks/validate-input.js +24 -24
- package/classes/version.js +152 -163
- package/commands/alias.js +61 -95
- package/commands/init.js +89 -109
- package/commands/integrity.js +42 -55
- package/commands/login.js +80 -101
- package/commands/map-alias.js +62 -82
- package/commands/map.js +69 -83
- package/commands/meta.js +36 -53
- package/commands/npm-alias.js +55 -80
- package/commands/package-alias.js +58 -90
- package/commands/ping.js +19 -30
- package/commands/publish.js +117 -127
- package/commands/version.js +87 -95
- 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 +76 -72
- package/package.json +5 -4
- package/readme.md +1 -1
- package/types/classes/alias.d.ts +3 -3
- 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/defaults.d.ts +22 -0
- package/types/utils/error.d.ts +19 -0
- package/types/utils/hash/index.d.ts +3 -3
- package/types/utils/http/index.d.ts +4 -4
- package/types/utils/index.d.ts +5 -5
- package/types/utils/json/index.d.ts +3 -3
- package/utils/command-handler.js +72 -0
- package/utils/defaults.js +79 -0
- package/utils/error.js +42 -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 +6 -5
- 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 +2 -2
- package/commands/index.js +0 -27
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## [3.1.5](https://github.com/eik-lib/cli/compare/v3.1.4...v3.1.5) (2024-08-29)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* handle relative and absolute paths to config, improve error messages, edit help for brevity ([06e9951](https://github.com/eik-lib/cli/commit/06e9951a6efe6b3f37600f6f0477417e708dcf08))
|
7
|
+
|
8
|
+
## [3.1.4](https://github.com/eik-lib/cli/compare/v3.1.3...v3.1.4) (2024-08-26)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* **deps:** update dependency ora to v8.1.0 ([7a784bc](https://github.com/eik-lib/cli/commit/7a784bc3f36713d932041a7b7c9a7dc56ffc0a63))
|
14
|
+
|
1
15
|
## [3.1.3](https://github.com/eik-lib/cli/compare/v3.1.2...v3.1.3) (2024-08-19)
|
2
16
|
|
3
17
|
|
package/classes/alias.js
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
import assert from
|
2
|
-
import abslog from
|
3
|
-
import { schemas, validators } from
|
4
|
-
import { request } from
|
5
|
-
import { typeSlug } from
|
6
|
-
import { joinUrlPathname } from
|
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
|
10
10
|
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
11
11
|
* @property {string} server
|
12
|
-
* @property {"package" | "npm" | "map"} [type="package"]
|
12
|
+
* @property {"package" | "npm" | "image" | "map"} [type="package"]
|
13
13
|
* @property {string} name
|
14
14
|
* @property {string} version
|
15
15
|
* @property {string} alias
|
@@ -30,127 +30,117 @@ import { joinUrlPathname } from '../utils/url.js';
|
|
30
30
|
*/
|
31
31
|
|
32
32
|
export default class Alias {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
74
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
pathname,
|
87
|
-
data: { version: this.version },
|
88
|
-
token: this.token,
|
89
|
-
});
|
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
|
+
});
|
90
86
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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 || [];
|
96
92
|
|
97
|
-
|
98
|
-
|
99
|
-
|
93
|
+
return data;
|
94
|
+
} catch (err) {
|
95
|
+
let status = err.statusCode;
|
100
96
|
|
101
|
-
|
102
|
-
|
103
|
-
'Alias already exists on server, performing update',
|
104
|
-
);
|
97
|
+
if (status === 409) {
|
98
|
+
this.log.debug("Alias already exists on server, performing update");
|
105
99
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
+
});
|
114
108
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
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;
|
121
115
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
116
|
+
return data;
|
117
|
+
} catch (error) {
|
118
|
+
status = error.statusCode;
|
119
|
+
}
|
120
|
+
}
|
127
121
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
throw new Error('Server failure');
|
153
|
-
}
|
154
|
-
}
|
155
|
-
}
|
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
|
+
}
|
156
146
|
}
|
package/classes/index.js
CHANGED
@@ -1,68 +1,68 @@
|
|
1
|
-
import Ping from
|
2
|
-
import Alias from
|
3
|
-
import Meta from
|
4
|
-
import Login from
|
5
|
-
import PublishMap from
|
6
|
-
import PublishPackage from
|
7
|
-
import Integrity from
|
8
|
-
import Version from
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
/**
|
12
|
+
* @param {import('./alias.js').AliasOptions} opts
|
13
|
+
*/
|
14
|
+
alias(opts) {
|
15
|
+
return new Alias(opts).run();
|
16
|
+
},
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
/**
|
19
|
+
* @param {import('./integrity.js').IntegrityOptions} opts
|
20
|
+
*/
|
21
|
+
integrity(opts) {
|
22
|
+
return new Integrity(opts).run();
|
23
|
+
},
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
/**
|
42
|
+
* @param {import('./meta.js').MetaOptions} opts
|
43
|
+
*/
|
44
|
+
meta(opts) {
|
45
|
+
return new Meta(opts).run();
|
46
|
+
},
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
/**
|
49
|
+
* @param {import('./ping.js').PingOptions} opts
|
50
|
+
*/
|
51
|
+
ping(opts) {
|
52
|
+
return new Ping(opts).run();
|
53
|
+
},
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
/**
|
63
|
+
* @param {import('./version.js').VersionOptions} opts
|
64
|
+
*/
|
65
|
+
version(opts) {
|
66
|
+
return new Version(opts).run();
|
67
|
+
},
|
68
68
|
};
|
package/classes/integrity.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import abslog from
|
2
|
-
import eik from
|
3
|
-
import { typeSlug } from
|
4
|
-
import { joinUrlPathname } from
|
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
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
}
|