@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.
Files changed (78) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/classes/alias.js +108 -118
  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 -80
  7. package/classes/ping.js +53 -53
  8. package/classes/publish/map.js +90 -92
  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 -17
  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 +52 -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 +3 -2
  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/utils/hash/file.js +4 -4
  64. package/utils/hash/files.js +9 -9
  65. package/utils/hash/index.js +3 -3
  66. package/utils/http/index.js +4 -4
  67. package/utils/http/integrity.js +18 -18
  68. package/utils/http/latest-version.js +37 -37
  69. package/utils/http/request.js +42 -42
  70. package/utils/http/versions.js +20 -20
  71. package/utils/index.js +3 -3
  72. package/utils/json/index.js +3 -3
  73. package/utils/json/read.js +26 -26
  74. package/utils/json/write-eik.js +17 -17
  75. package/utils/json/write.js +26 -28
  76. package/utils/logger.js +43 -43
  77. package/utils/type-title.js +3 -3
  78. package/utils/url.js +2 -2
@@ -1,12 +1,12 @@
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';
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
- * @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 } =
67
- this.config;
68
- const { log, level, path } = this;
69
- log.debug('Validating input');
70
-
71
- log.debug(` ==> config object`);
72
- this.config.validate();
73
-
74
- log.debug(` ==> cwd: ${cwd}`);
75
- parse(cwd);
76
-
77
- log.debug(` ==> level: ${level}`);
78
- if (!['major', 'minor', 'patch'].includes(level)) {
79
- // @ts-expect-error
80
- throw new schemas.ValidationError(
81
- 'Parameter "version" is not valid',
82
- );
83
- }
84
-
85
- log.debug(` ==> files: ${JSON.stringify(files)}`);
86
- if (!files) {
87
- // @ts-expect-error
88
- throw new schemas.ValidationError('Parameter "files" is not valid');
89
- }
90
-
91
- log.debug(` ==> map: ${JSON.stringify(map)}`);
92
- if (!Array.isArray(map)) {
93
- // @ts-expect-error
94
- throw new schemas.ValidationError('Parameter "map" is not valid');
95
- }
96
-
97
- log.debug('Checking local package version');
98
- log.debug(`Current local package version determined to be ${version}`);
99
- log.debug(`Fetching remote package metadata from ${server}`);
100
-
101
- let integrityHash;
102
- try {
103
- integrityHash = await integrity(
104
- server,
105
- typeSlug(type),
106
- name,
107
- version,
108
- );
109
- } catch (err) {
110
- throw new Error(
111
- `Unable to fetch package metadata from server: ${err.message}`,
112
- );
113
- }
114
-
115
- if (!integrityHash) {
116
- // version does not exist on server yet. No increment needed.
117
- throw new Error(
118
- `The current version of this package has not yet been published, version change is not needed.`,
119
- );
120
- }
121
-
122
- log.debug('Hashing local files for comparison with server');
123
-
124
- let localHash;
125
- try {
126
- makeDirectorySync(path);
127
- const eikPathDest = join(path, 'eik.json');
128
- const eikJSON = {
129
- name,
130
- server,
131
- files,
132
- 'import-map': map,
133
- out,
134
- };
135
- writeFileSync(eikPathDest, JSON.stringify(eikJSON, null, 2));
136
-
137
- const localFiles = [eikPathDest];
138
- log.debug(` ==> ${eikPathDest}`);
139
-
140
- if (files) {
141
- try {
142
- const mappings = await this.config.mappings();
143
-
144
- for (const mapping of mappings) {
145
- const destination = join(
146
- path,
147
- mapping.destination.filePathname,
148
- );
149
- copyFileSync(mapping.source.absolute, destination);
150
- log.debug(` ==> ${destination}`);
151
- localFiles.push(destination);
152
- }
153
- } catch (err) {
154
- // throw new Error(`Failed to zip JavaScripts: ${err.message}`);
155
- }
156
- }
157
- localHash = await hash.files(localFiles);
158
- } catch (err) {
159
- throw new Error(
160
- `Unable to hash local files for comparison: ${err.message}`,
161
- );
162
- }
163
-
164
- log.debug(`Comparing hashes:`);
165
- log.debug(` ==> local: ${localHash}`);
166
- log.debug(` ==> remote: ${integrityHash}`);
167
- const same = hash.compare(integrityHash, localHash);
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 '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';
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 = 'alias [name] [version] [alias]';
7
+ export const command = "alias [name] [version] [alias]";
8
8
 
9
- export const aliases = ['a'];
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
- const defaults = getDefaults(yargs.argv.config || yargs.argv.cwd);
14
+ const defaults = getDefaults(yargs.argv.config || yargs.argv.cwd);
15
15
 
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
- });
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
- 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
- });
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
- // @ts-expect-error
59
- yargs.default('token', defaults.token, defaults.token ? '######' : '');
58
+ // @ts-expect-error
59
+ yargs.default("token", defaults.token, defaults.token ? "######" : "");
60
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`);
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
- 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;
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
- try {
79
- const data = await new Alias({
80
- type,
81
- logger: log,
82
- ...argv,
83
- }).run();
78
+ try {
79
+ const data = await new Alias({
80
+ type,
81
+ logger: log,
82
+ ...argv,
83
+ }).run();
84
84
 
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);
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
- 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
- }
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
- spinner.text = '';
99
- spinner.stopAndPersist();
100
- if (success) {
101
- af?.format(server);
102
- } else {
103
- process.exit(1);
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 './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';
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
- init,
16
- integrity,
17
- login,
18
- mapAlias,
19
- map,
20
- meta,
21
- npmAlias,
22
- packageAlias,
23
- ping,
24
- publish,
25
- version,
26
- alias,
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
  ];