@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/classes/version.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
import { copyFileSync, writeFileSync } from
|
2
|
-
import { join, isAbsolute, parse } from
|
3
|
-
import abslog from
|
4
|
-
import semver from
|
5
|
-
import { makeDirectorySync } from
|
6
|
-
import { schemas, EikConfig } from
|
7
|
-
import { integrity } from
|
8
|
-
import hash from
|
9
|
-
import { typeSlug } from
|
1
|
+
import { copyFileSync, writeFileSync } from "fs";
|
2
|
+
import { join, isAbsolute, parse } from "path";
|
3
|
+
import abslog from "abslog";
|
4
|
+
import semver from "semver";
|
5
|
+
import { makeDirectorySync } from "make-dir";
|
6
|
+
import { schemas, EikConfig } from "@eik/common";
|
7
|
+
import { integrity } from "../utils/http/index.js";
|
8
|
+
import hash from "../utils/hash/index.js";
|
9
|
+
import { typeSlug } from "../utils/index.js";
|
10
10
|
|
11
11
|
/**
|
12
12
|
* @typedef {object} VersionOptions
|
@@ -23,158 +23,147 @@ import { typeSlug } from '../utils/index.js';
|
|
23
23
|
*/
|
24
24
|
|
25
25
|
export default class Version {
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
if (same) {
|
170
|
-
throw new Error(
|
171
|
-
`The current version of this package already contains these files, version change is not needed.`,
|
172
|
-
);
|
173
|
-
}
|
174
|
-
|
175
|
-
log.debug(`Incrementing by "${level}" level`);
|
176
|
-
const newVersion = semver.inc(version, level);
|
177
|
-
log.debug(` ==> ${newVersion}`);
|
178
|
-
return newVersion;
|
179
|
-
}
|
26
|
+
/**
|
27
|
+
* @param {VersionOptions} options
|
28
|
+
*/
|
29
|
+
constructor({
|
30
|
+
logger,
|
31
|
+
server,
|
32
|
+
type = "package",
|
33
|
+
name,
|
34
|
+
version,
|
35
|
+
level = "patch",
|
36
|
+
cwd,
|
37
|
+
map = [],
|
38
|
+
out = "./.eik",
|
39
|
+
files,
|
40
|
+
}) {
|
41
|
+
const config = new EikConfig(
|
42
|
+
{
|
43
|
+
server,
|
44
|
+
type,
|
45
|
+
name,
|
46
|
+
version,
|
47
|
+
"import-map": map,
|
48
|
+
out,
|
49
|
+
files,
|
50
|
+
},
|
51
|
+
null,
|
52
|
+
cwd,
|
53
|
+
);
|
54
|
+
|
55
|
+
this.log = abslog(logger);
|
56
|
+
this.config = config;
|
57
|
+
this.path = isAbsolute(config.out) ? config.out : join(cwd, config.out);
|
58
|
+
this.level = level;
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Similar to `npm version`, but updates `eik.json`
|
63
|
+
* @returns {Promise<string | null>} The new version number, or null if the versioning failed
|
64
|
+
*/
|
65
|
+
async run() {
|
66
|
+
const { name, server, type, version, cwd, out, files, map } = this.config;
|
67
|
+
const { log, level, path } = this;
|
68
|
+
log.debug("Validating input");
|
69
|
+
|
70
|
+
log.debug(` ==> config object`);
|
71
|
+
this.config.validate();
|
72
|
+
|
73
|
+
log.debug(` ==> cwd: ${cwd}`);
|
74
|
+
parse(cwd);
|
75
|
+
|
76
|
+
log.debug(` ==> level: ${level}`);
|
77
|
+
if (!["major", "minor", "patch"].includes(level)) {
|
78
|
+
// @ts-expect-error
|
79
|
+
throw new schemas.ValidationError('Parameter "version" is not valid');
|
80
|
+
}
|
81
|
+
|
82
|
+
log.debug(` ==> files: ${JSON.stringify(files)}`);
|
83
|
+
if (!files) {
|
84
|
+
// @ts-expect-error
|
85
|
+
throw new schemas.ValidationError('Parameter "files" is not valid');
|
86
|
+
}
|
87
|
+
|
88
|
+
log.debug(` ==> map: ${JSON.stringify(map)}`);
|
89
|
+
if (!Array.isArray(map)) {
|
90
|
+
// @ts-expect-error
|
91
|
+
throw new schemas.ValidationError('Parameter "map" is not valid');
|
92
|
+
}
|
93
|
+
|
94
|
+
log.debug("Checking local package version");
|
95
|
+
log.debug(`Current local package version determined to be ${version}`);
|
96
|
+
log.debug(`Fetching remote package metadata from ${server}`);
|
97
|
+
|
98
|
+
let integrityHash;
|
99
|
+
try {
|
100
|
+
integrityHash = await integrity(server, typeSlug(type), name, version);
|
101
|
+
} catch (err) {
|
102
|
+
throw new Error(
|
103
|
+
`Unable to fetch package metadata from server: ${err.message}`,
|
104
|
+
);
|
105
|
+
}
|
106
|
+
|
107
|
+
if (!integrityHash) {
|
108
|
+
// version does not exist on server yet. No increment needed.
|
109
|
+
throw new Error(
|
110
|
+
`The current version of this package has not yet been published, version change is not needed.`,
|
111
|
+
);
|
112
|
+
}
|
113
|
+
|
114
|
+
log.debug("Hashing local files for comparison with server");
|
115
|
+
|
116
|
+
let localHash;
|
117
|
+
try {
|
118
|
+
makeDirectorySync(path);
|
119
|
+
const eikPathDest = join(path, "eik.json");
|
120
|
+
const eikJSON = {
|
121
|
+
name,
|
122
|
+
server,
|
123
|
+
files,
|
124
|
+
"import-map": map,
|
125
|
+
out,
|
126
|
+
};
|
127
|
+
writeFileSync(eikPathDest, JSON.stringify(eikJSON, null, 2));
|
128
|
+
|
129
|
+
const localFiles = [eikPathDest];
|
130
|
+
log.debug(` ==> ${eikPathDest}`);
|
131
|
+
|
132
|
+
if (files) {
|
133
|
+
try {
|
134
|
+
const mappings = await this.config.mappings();
|
135
|
+
|
136
|
+
for (const mapping of mappings) {
|
137
|
+
const destination = join(path, mapping.destination.filePathname);
|
138
|
+
copyFileSync(mapping.source.absolute, destination);
|
139
|
+
log.debug(` ==> ${destination}`);
|
140
|
+
localFiles.push(destination);
|
141
|
+
}
|
142
|
+
} catch (err) {
|
143
|
+
// throw new Error(`Failed to zip JavaScripts: ${err.message}`);
|
144
|
+
}
|
145
|
+
}
|
146
|
+
localHash = await hash.files(localFiles);
|
147
|
+
} catch (err) {
|
148
|
+
throw new Error(
|
149
|
+
`Unable to hash local files for comparison: ${err.message}`,
|
150
|
+
);
|
151
|
+
}
|
152
|
+
|
153
|
+
log.debug(`Comparing hashes:`);
|
154
|
+
log.debug(` ==> local: ${localHash}`);
|
155
|
+
log.debug(` ==> remote: ${integrityHash}`);
|
156
|
+
const same = hash.compare(integrityHash, localHash);
|
157
|
+
|
158
|
+
if (same) {
|
159
|
+
throw new Error(
|
160
|
+
`The current version of this package already contains these files, version change is not needed.`,
|
161
|
+
);
|
162
|
+
}
|
163
|
+
|
164
|
+
log.debug(`Incrementing by "${level}" level`);
|
165
|
+
const newVersion = semver.inc(version, level);
|
166
|
+
log.debug(` ==> ${newVersion}`);
|
167
|
+
return newVersion;
|
168
|
+
}
|
180
169
|
}
|
package/commands/alias.js
CHANGED
@@ -1,105 +1,71 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
4
|
-
import { logger, getDefaults } from '../utils/index.js';
|
5
|
-
import { Alias as AliasFormatter } from '../formatters/index.js';
|
1
|
+
import Alias from "../classes/alias.js";
|
2
|
+
import { Alias as AliasFormatter } from "../formatters/index.js";
|
3
|
+
import { commandHandler } from "../utils/command-handler.js";
|
6
4
|
|
7
|
-
export const command =
|
5
|
+
export const command = "alias [name] [version] [alias]";
|
8
6
|
|
9
|
-
export const aliases = [
|
7
|
+
export const aliases = ["a"];
|
10
8
|
|
11
|
-
export const describe =
|
9
|
+
export const describe =
|
10
|
+
"Create or update a semver major alias for a package or map";
|
12
11
|
|
12
|
+
/** @type {import('yargs').CommandBuilder} */
|
13
13
|
export const builder = (yargs) => {
|
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
|
-
// @ts-expect-error
|
48
|
-
default: defaults.type,
|
49
|
-
},
|
50
|
-
token: {
|
51
|
-
describe:
|
52
|
-
'Provide a jwt token to be used to authenticate with the Eik server.',
|
53
|
-
default: '',
|
54
|
-
alias: 't',
|
55
|
-
},
|
56
|
-
});
|
57
|
-
|
58
|
-
// @ts-expect-error
|
59
|
-
yargs.default('token', defaults.token, defaults.token ? '######' : '');
|
60
|
-
|
61
|
-
yargs.example(`eik alias my-app 1.0.0 1`);
|
62
|
-
yargs.example(`eik alias my-app 1.7.3 1`);
|
63
|
-
yargs.example(`eik alias my-app 6.3.1 6`);
|
64
|
-
yargs.example(
|
65
|
-
`eik alias my-app 6.3.1 6 --server https://assets.myeikserver.com`,
|
66
|
-
);
|
67
|
-
yargs.example(`eik alias my-app 4.2.2 4 --debug`);
|
68
|
-
yargs.example(`eik alias my-app 4.2.2 4 --type package`);
|
14
|
+
return yargs
|
15
|
+
.positional("name", {
|
16
|
+
describe: "Name matching a package or import map on the Eik server",
|
17
|
+
type: "string",
|
18
|
+
})
|
19
|
+
.positional("version", {
|
20
|
+
describe: "The version the alias should redirect to",
|
21
|
+
type: "string",
|
22
|
+
})
|
23
|
+
.positional("alias", {
|
24
|
+
describe:
|
25
|
+
"Alias, should be the semver major component of version. Eg. 1.0.0 should be given the alias 1",
|
26
|
+
type: "string",
|
27
|
+
})
|
28
|
+
.options({
|
29
|
+
server: {
|
30
|
+
alias: "s",
|
31
|
+
describe: "Eik server address, if different from configuration file",
|
32
|
+
},
|
33
|
+
type: {
|
34
|
+
describe:
|
35
|
+
"Alter the alias type. Default is detected from eik.json. Valid values are `package`, `npm`, 'image', or `map` Eg. --type npm",
|
36
|
+
},
|
37
|
+
token: {
|
38
|
+
describe: "JWT used for authentication, if not using eik login",
|
39
|
+
alias: "t",
|
40
|
+
},
|
41
|
+
})
|
42
|
+
.example("eik alias my-app 1.0.0 1")
|
43
|
+
.example("eik alias my-app 1.7.3 1")
|
44
|
+
.example("eik alias my-app 6.3.1 6 --server https://assets.myeikserver.com")
|
45
|
+
.example("eik alias my-app 6.3.1 6 --token yourtoken")
|
46
|
+
.example("eik alias my-app 4.2.2 4 --type package");
|
69
47
|
};
|
70
48
|
|
71
|
-
export const handler =
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
logger: log,
|
82
|
-
...argv,
|
83
|
-
}).run();
|
49
|
+
export const handler = commandHandler(
|
50
|
+
{ command, options: ["server", "type"] },
|
51
|
+
async (argv, log) => {
|
52
|
+
const { debug, server, type, ...rest } = argv;
|
53
|
+
const data = await new Alias({
|
54
|
+
type,
|
55
|
+
server,
|
56
|
+
logger: log,
|
57
|
+
...rest,
|
58
|
+
}).run();
|
84
59
|
|
85
|
-
|
86
|
-
|
87
|
-
|
60
|
+
// TODO: get rid of this rediculous formatter class idea that past me put here to irk present and future me.
|
61
|
+
// Smells like DRY silliness
|
62
|
+
const af = new AliasFormatter(data);
|
88
63
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
success = true;
|
94
|
-
} catch (err) {
|
95
|
-
log.warn(err.message);
|
96
|
-
}
|
64
|
+
const createdOrUpdated = data.update ? "Updated" : "Created";
|
65
|
+
log.info(
|
66
|
+
`${createdOrUpdated} alias for "${type}" "${data.name}". ("${data.version}" => "v${data.alias}")`,
|
67
|
+
);
|
97
68
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
af?.format(server);
|
102
|
-
} else {
|
103
|
-
process.exit(1);
|
104
|
-
}
|
105
|
-
};
|
69
|
+
af.format(server);
|
70
|
+
},
|
71
|
+
);
|