@eik/cli 3.1.3 → 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 +7 -0
- package/classes/alias.js +108 -118
- 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 +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 +3 -2
- 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/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 +2 -2
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,105 @@
|
|
1
|
-
import ora from
|
2
|
-
import semver from
|
3
|
-
import Alias from
|
4
|
-
import { logger, getDefaults } from
|
5
|
-
import { Alias as AliasFormatter } from
|
1
|
+
import ora from "ora";
|
2
|
+
import semver from "semver";
|
3
|
+
import Alias from "../classes/alias.js";
|
4
|
+
import { logger, getDefaults } from "../utils/index.js";
|
5
|
+
import { Alias as AliasFormatter } from "../formatters/index.js";
|
6
6
|
|
7
|
-
export const command =
|
7
|
+
export const command = "alias [name] [version] [alias]";
|
8
8
|
|
9
|
-
export const aliases = [
|
9
|
+
export const aliases = ["a"];
|
10
10
|
|
11
11
|
export const describe = `Create or update a semver major alias for a package, NPM package or import map as identified by its name and version. A package with the given name and version must already exist on the Eik server. The alias should be the semver major part of the package version. Eg. for a package of version 5.4.3, you should use 5 as the alias. The alias type (npm, map, package) is detected from eik.json in the current working directory.`;
|
12
12
|
|
13
13
|
export const builder = (yargs) => {
|
14
|
-
|
14
|
+
const defaults = getDefaults(yargs.argv.config || yargs.argv.cwd);
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
16
|
+
yargs
|
17
|
+
.positional("name", {
|
18
|
+
describe: "Name matching a package or import map on the Eik server",
|
19
|
+
type: "string",
|
20
|
+
// @ts-expect-error
|
21
|
+
default: defaults.name,
|
22
|
+
})
|
23
|
+
.positional("version", {
|
24
|
+
describe: "The version the alias should redirect to",
|
25
|
+
type: "string",
|
26
|
+
// @ts-expect-error
|
27
|
+
default: defaults.version,
|
28
|
+
})
|
29
|
+
.positional("alias", {
|
30
|
+
describe:
|
31
|
+
"Alias, should be the semver major component of version. Eg. 1.0.0 should be given the alias 1",
|
32
|
+
type: "string",
|
33
|
+
// @ts-expect-error
|
34
|
+
default: defaults.version ? semver.major(defaults.version) : null,
|
35
|
+
});
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
37
|
+
yargs.options({
|
38
|
+
server: {
|
39
|
+
alias: "s",
|
40
|
+
describe: "Specify location of Eik asset server.",
|
41
|
+
// @ts-expect-error
|
42
|
+
default: defaults.server,
|
43
|
+
},
|
44
|
+
type: {
|
45
|
+
describe:
|
46
|
+
"Alter the alias type. Default is detected from eik.json. Valid values are `package`, `npm`, or `map` Eg. --type npm",
|
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
57
|
|
58
|
-
|
59
|
-
|
58
|
+
// @ts-expect-error
|
59
|
+
yargs.default("token", defaults.token, defaults.token ? "######" : "");
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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`);
|
69
69
|
};
|
70
70
|
|
71
71
|
export const handler = async (argv) => {
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
const spinner = ora({ stream: process.stdout }).start("working...");
|
73
|
+
let success = false;
|
74
|
+
const { debug, server, type } = argv;
|
75
|
+
const log = logger(spinner, debug);
|
76
|
+
let af;
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
78
|
+
try {
|
79
|
+
const data = await new Alias({
|
80
|
+
type,
|
81
|
+
logger: log,
|
82
|
+
...argv,
|
83
|
+
}).run();
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
// TODO: get rid of this rediculous formatter class idea that past me put here to irk present and future me.
|
86
|
+
// Smells like DRY silliness
|
87
|
+
af = new AliasFormatter(data);
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
89
|
+
const createdOrUpdated = data.update ? "Updated" : "Created";
|
90
|
+
log.info(
|
91
|
+
`${createdOrUpdated} alias for "${type}" "${data.name}". ("${data.version}" => "v${data.alias}")`,
|
92
|
+
);
|
93
|
+
success = true;
|
94
|
+
} catch (err) {
|
95
|
+
log.warn(err.message);
|
96
|
+
}
|
97
97
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
98
|
+
spinner.text = "";
|
99
|
+
spinner.stopAndPersist();
|
100
|
+
if (success) {
|
101
|
+
af?.format(server);
|
102
|
+
} else {
|
103
|
+
process.exit(1);
|
104
|
+
}
|
105
105
|
};
|
package/commands/index.js
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
import * as init from
|
2
|
-
import * as integrity from
|
3
|
-
import * as login from
|
4
|
-
import * as mapAlias from
|
5
|
-
import * as map from
|
6
|
-
import * as meta from
|
7
|
-
import * as npmAlias from
|
8
|
-
import * as packageAlias from
|
9
|
-
import * as ping from
|
10
|
-
import * as publish from
|
11
|
-
import * as version from
|
12
|
-
import * as alias from
|
1
|
+
import * as init from "./init.js";
|
2
|
+
import * as integrity from "./integrity.js";
|
3
|
+
import * as login from "./login.js";
|
4
|
+
import * as mapAlias from "./map-alias.js";
|
5
|
+
import * as map from "./map.js";
|
6
|
+
import * as meta from "./meta.js";
|
7
|
+
import * as npmAlias from "./npm-alias.js";
|
8
|
+
import * as packageAlias from "./package-alias.js";
|
9
|
+
import * as ping from "./ping.js";
|
10
|
+
import * as publish from "./publish.js";
|
11
|
+
import * as version from "./version.js";
|
12
|
+
import * as alias from "./alias.js";
|
13
13
|
|
14
14
|
export const commands = [
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
15
|
+
init,
|
16
|
+
integrity,
|
17
|
+
login,
|
18
|
+
mapAlias,
|
19
|
+
map,
|
20
|
+
meta,
|
21
|
+
npmAlias,
|
22
|
+
packageAlias,
|
23
|
+
ping,
|
24
|
+
publish,
|
25
|
+
version,
|
26
|
+
alias,
|
27
27
|
];
|