@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.
Files changed (84) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/classes/alias.js +109 -119
  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 +61 -95
  22. package/commands/init.js +89 -109
  23. package/commands/integrity.js +42 -55
  24. package/commands/login.js +80 -101
  25. package/commands/map-alias.js +62 -82
  26. package/commands/map.js +69 -83
  27. package/commands/meta.js +36 -53
  28. package/commands/npm-alias.js +55 -80
  29. package/commands/package-alias.js +58 -90
  30. package/commands/ping.js +19 -30
  31. package/commands/publish.js +117 -127
  32. package/commands/version.js +87 -95
  33. package/formatters/alias.js +60 -63
  34. package/formatters/artifact.js +77 -77
  35. package/formatters/file.js +25 -25
  36. package/formatters/index.js +4 -4
  37. package/formatters/version.js +49 -51
  38. package/index.js +76 -72
  39. package/package.json +5 -4
  40. package/readme.md +1 -1
  41. package/types/classes/alias.d.ts +3 -3
  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/defaults.d.ts +22 -0
  60. package/types/utils/error.d.ts +19 -0
  61. package/types/utils/hash/index.d.ts +3 -3
  62. package/types/utils/http/index.d.ts +4 -4
  63. package/types/utils/index.d.ts +5 -5
  64. package/types/utils/json/index.d.ts +3 -3
  65. package/utils/command-handler.js +72 -0
  66. package/utils/defaults.js +79 -0
  67. package/utils/error.js +42 -0
  68. package/utils/hash/file.js +4 -4
  69. package/utils/hash/files.js +9 -9
  70. package/utils/hash/index.js +3 -3
  71. package/utils/http/index.js +4 -4
  72. package/utils/http/integrity.js +18 -18
  73. package/utils/http/latest-version.js +37 -37
  74. package/utils/http/request.js +42 -42
  75. package/utils/http/versions.js +20 -20
  76. package/utils/index.js +6 -5
  77. package/utils/json/index.js +3 -3
  78. package/utils/json/read.js +26 -26
  79. package/utils/json/write-eik.js +17 -17
  80. package/utils/json/write.js +26 -28
  81. package/utils/logger.js +43 -43
  82. package/utils/type-title.js +3 -3
  83. package/utils/url.js +2 -2
  84. package/commands/index.js +0 -27
@@ -1,78 +1,73 @@
1
- import fs from 'fs';
2
- import { join, resolve, basename, dirname } from 'path';
3
- import * as tar from 'tar';
4
- import Task from './task.js';
1
+ import fs from "fs";
2
+ import { join, resolve, basename, dirname } from "path";
3
+ import * as tar from "tar";
4
+ import Task from "./task.js";
5
5
 
6
6
  const { copyFileSync, writeFileSync } = fs;
7
7
 
8
8
  export default class CreateZipFile extends Task {
9
- async process() {
10
- const { log, path } = this;
11
- const { name, map, server, out, files } = this.config;
9
+ async process() {
10
+ const { log, path } = this;
11
+ const { name, map, server, out, files } = this.config;
12
12
 
13
- log.debug('Creating zip file');
14
- log.debug(` ==> ${join(path, 'eik.tgz')}`);
13
+ log.debug("Creating zip file");
14
+ log.debug(` ==> ${join(path, "eik.tgz")}`);
15
15
 
16
- const filesToZip = [];
16
+ const filesToZip = [];
17
17
 
18
- try {
19
- const eikPathDest = join(path, 'eik.json');
20
- writeFileSync(
21
- eikPathDest,
22
- JSON.stringify(
23
- {
24
- name,
25
- server,
26
- files,
27
- 'import-map': map,
28
- out,
29
- },
30
- null,
31
- 2,
32
- ),
33
- );
34
- filesToZip.push(basename(eikPathDest));
35
- } catch (err) {
36
- throw new Error(`Failed to zip eik.json file: ${err.message}`);
37
- }
18
+ try {
19
+ const eikPathDest = join(path, "eik.json");
20
+ writeFileSync(
21
+ eikPathDest,
22
+ JSON.stringify(
23
+ {
24
+ name,
25
+ server,
26
+ files,
27
+ "import-map": map,
28
+ out,
29
+ },
30
+ null,
31
+ 2,
32
+ ),
33
+ );
34
+ filesToZip.push(basename(eikPathDest));
35
+ } catch (err) {
36
+ throw new Error(`Failed to zip eik.json file: ${err.message}`);
37
+ }
38
38
 
39
- if (files) {
40
- try {
41
- const mappings = await this.config.mappings();
39
+ if (files) {
40
+ try {
41
+ const mappings = await this.config.mappings();
42
42
 
43
- for (const mapping of mappings) {
44
- const destination = join(
45
- path,
46
- mapping.destination.filePathname,
47
- );
48
- await fs.promises.mkdir(dirname(destination), {
49
- recursive: true,
50
- });
51
- copyFileSync(mapping.source.absolute, destination);
52
- filesToZip.push(destination.replace(path, '.'));
53
- }
54
- } catch (err) {
55
- throw new Error(
56
- `Failed to copy files for zipping: ${err.message}`,
57
- );
58
- }
59
- }
43
+ for (const mapping of mappings) {
44
+ const destination = join(path, mapping.destination.filePathname);
45
+ await fs.promises.mkdir(dirname(destination), {
46
+ recursive: true,
47
+ });
48
+ copyFileSync(mapping.source.absolute, destination);
49
+ filesToZip.push(destination.replace(path, "."));
50
+ }
51
+ } catch (err) {
52
+ throw new Error(`Failed to copy files for zipping: ${err.message}`);
53
+ }
54
+ }
60
55
 
61
- try {
62
- const zipFile = resolve(path, 'eik.tgz');
56
+ try {
57
+ const zipFile = resolve(path, "eik.tgz");
63
58
 
64
- await tar.c(
65
- {
66
- gzip: true,
67
- file: zipFile,
68
- cwd: path,
69
- },
70
- filesToZip,
71
- );
59
+ await tar.c(
60
+ {
61
+ gzip: true,
62
+ file: zipFile,
63
+ cwd: path,
64
+ },
65
+ filesToZip,
66
+ );
72
67
 
73
- return zipFile;
74
- } catch (err) {
75
- throw new Error(`Unable to create zip file: ${err.message}`);
76
- }
77
- }
68
+ return zipFile;
69
+ } catch (err) {
70
+ throw new Error(`Unable to create zip file: ${err.message}`);
71
+ }
72
+ }
78
73
  }
@@ -1,22 +1,22 @@
1
- import { join } from 'path';
2
- import Task from './task.js';
1
+ import { join } from "path";
2
+ import Task from "./task.js";
3
3
 
4
4
  export default class DryRun extends Task {
5
- async process(zipFile) {
6
- const { path } = this;
5
+ async process(zipFile) {
6
+ const { path } = this;
7
7
 
8
- const files = [
9
- { pathname: path, type: 'temporary directory' },
10
- { pathname: zipFile, type: 'package archive' },
11
- ];
8
+ const files = [
9
+ { pathname: path, type: "temporary directory" },
10
+ { pathname: zipFile, type: "package archive" },
11
+ ];
12
12
 
13
- const mappings = await this.config.mappings();
13
+ const mappings = await this.config.mappings();
14
14
 
15
- for (const mapping of mappings) {
16
- const destination = join(path, mapping.destination.filePathname);
17
- files.push({ pathname: destination, type: 'package file' });
18
- }
15
+ for (const mapping of mappings) {
16
+ const destination = join(path, mapping.destination.filePathname);
17
+ files.push({ pathname: destination, type: "package file" });
18
+ }
19
19
 
20
- return files;
21
- }
20
+ return files;
21
+ }
22
22
  }
@@ -1,20 +1,20 @@
1
- import { join } from 'path';
2
- import json from '../../../../utils/json/index.js';
3
- import Task from './task.js';
1
+ import { join } from "path";
2
+ import json from "../../../../utils/json/index.js";
3
+ import Task from "./task.js";
4
4
 
5
5
  export default class SaveMetaFile extends Task {
6
- async process(response) {
7
- const { log, cwd } = this;
8
- const { out } = this.config;
9
- const filepath = join(out, 'integrity.json');
10
- log.debug('Saving integrity file');
11
- log.debug(` ==> ${filepath}`);
12
- try {
13
- await json.write(response, { cwd, filename: filepath });
14
- } catch (err) {
15
- throw new Error(
16
- `Unable to save integrity file [${filepath}]: ${err.message}`,
17
- );
18
- }
19
- }
6
+ async process(response) {
7
+ const { log, cwd } = this;
8
+ const { out } = this.config;
9
+ const filepath = join(out, "integrity.json");
10
+ log.debug("Saving integrity file");
11
+ log.debug(` ==> ${filepath}`);
12
+ try {
13
+ await json.write(response, { cwd, filename: filepath });
14
+ } catch (err) {
15
+ throw new Error(
16
+ `Unable to save integrity file [${filepath}]: ${err.message}`,
17
+ );
18
+ }
19
+ }
20
20
  }
@@ -1,10 +1,10 @@
1
- import abslog from 'abslog';
1
+ import abslog from "abslog";
2
2
 
3
3
  export default class Task {
4
- constructor(options) {
5
- this.cwd = options.cwd;
6
- this.log = abslog(options.logger);
7
- this.path = options.path;
8
- this.config = options.config;
9
- }
4
+ constructor(options) {
5
+ this.cwd = options.cwd;
6
+ this.log = abslog(options.logger);
7
+ this.path = options.path;
8
+ this.config = options.config;
9
+ }
10
10
  }
@@ -1,62 +1,58 @@
1
- import { request } from '../../../../utils/http/index.js';
2
- import { typeSlug } from '../../../../utils/index.js';
3
- import { joinUrlPathname } from '../../../../utils/url.js';
1
+ import { request } from "../../../../utils/http/index.js";
2
+ import { typeSlug } from "../../../../utils/index.js";
3
+ import { joinUrlPathname } from "../../../../utils/url.js";
4
4
 
5
- import Task from './task.js';
5
+ import Task from "./task.js";
6
6
 
7
7
  export default class UploadFiles extends Task {
8
- async process(zipFile) {
9
- const { log } = this;
10
- const { server, name, version, type, token } = this.config;
11
- log.debug('Uploading zip file to server');
12
- try {
13
- const pathname = joinUrlPathname(
14
- typeSlug(type),
15
- encodeURIComponent(name),
16
- version,
17
- );
8
+ async process(zipFile) {
9
+ const { log } = this;
10
+ const { server, name, version, type, token } = this.config;
11
+ log.debug("Uploading zip file to server");
12
+ try {
13
+ const pathname = joinUrlPathname(
14
+ typeSlug(type),
15
+ encodeURIComponent(name),
16
+ version,
17
+ );
18
18
 
19
- const { message } = await request({
20
- method: 'PUT',
21
- host: server,
22
- pathname,
23
- file: zipFile,
24
- token,
25
- });
19
+ const { message } = await request({
20
+ method: "PUT",
21
+ host: server,
22
+ pathname,
23
+ file: zipFile,
24
+ token,
25
+ });
26
26
 
27
- return message;
28
- } catch (err) {
29
- log.error('Unable to upload zip file to server');
30
- switch (err.statusCode) {
31
- case 400:
32
- throw new Error(
33
- `${err.statusCode}: Client attempted to send an invalid URL parameter`,
34
- );
35
- case 401:
36
- throw new Error(
37
- `${err.statusCode}: Client unauthorized with server`,
38
- );
39
- case 404:
40
- throw new Error(
41
- `${err.statusCode}: Client could not find server route`,
42
- );
43
- case 409:
44
- throw new Error(
45
- `Package with name "${name}" and version "${version}" already exists on server`,
46
- );
47
- case 415:
48
- throw new Error(
49
- `${err.statusCode}: Client attempted to send an unsupported file format to server`,
50
- );
51
- case 502:
52
- throw new Error(
53
- `${err.statusCode}: Server was unable to write file to storage, ${err.message}`,
54
- );
55
- default:
56
- throw new Error(
57
- `${err.statusCode}: Server failed, ${err.message}`,
58
- );
59
- }
60
- }
61
- }
27
+ return message;
28
+ } catch (err) {
29
+ log.error("Unable to upload zip file to server");
30
+ switch (err.statusCode) {
31
+ case 400:
32
+ throw new Error(
33
+ `${err.statusCode}: Client attempted to send an invalid URL parameter`,
34
+ );
35
+ case 401:
36
+ throw new Error(`${err.statusCode}: Client unauthorized with server`);
37
+ case 404:
38
+ throw new Error(
39
+ `${err.statusCode}: Client could not find server route`,
40
+ );
41
+ case 409:
42
+ throw new Error(
43
+ `Package with name "${name}" and version "${version}" already exists on server`,
44
+ );
45
+ case 415:
46
+ throw new Error(
47
+ `${err.statusCode}: Client attempted to send an unsupported file format to server`,
48
+ );
49
+ case 502:
50
+ throw new Error(
51
+ `${err.statusCode}: Server was unable to write file to storage, ${err.message}`,
52
+ );
53
+ default:
54
+ throw new Error(`${err.statusCode}: Server failed, ${err.message}`);
55
+ }
56
+ }
57
+ }
62
58
  }
@@ -1,33 +1,33 @@
1
- import { parse } from 'path';
2
- import Task from './task.js';
1
+ import { parse } from "path";
2
+ import Task from "./task.js";
3
3
 
4
4
  class ValidationError extends Error {
5
- constructor(message, err) {
6
- let m = message;
7
- if (err && err.message) m += `: ${err.message}`;
8
- super(m);
9
- this.name = this.constructor.name;
10
- Error.captureStackTrace(this, this.constructor);
11
- }
5
+ constructor(message, err) {
6
+ let m = message;
7
+ if (err && err.message) m += `: ${err.message}`;
8
+ super(m);
9
+ this.name = this.constructor.name;
10
+ Error.captureStackTrace(this, this.constructor);
11
+ }
12
12
  }
13
13
 
14
14
  export default class ValidateInput extends Task {
15
- process() {
16
- const { log } = this;
17
- const { cwd, dryRun } = this.config;
15
+ process() {
16
+ const { log } = this;
17
+ const { cwd, dryRun } = this.config;
18
18
 
19
- log.debug('Validating input');
19
+ log.debug("Validating input");
20
20
 
21
- try {
22
- log.debug(` ==> cwd: ${cwd}`);
23
- parse(cwd);
24
- } catch (err) {
25
- throw new ValidationError('Parameter "cwd" is not valid', err);
26
- }
21
+ try {
22
+ log.debug(` ==> cwd: ${cwd}`);
23
+ parse(cwd);
24
+ } catch (err) {
25
+ throw new ValidationError('Parameter "cwd" is not valid', err);
26
+ }
27
27
 
28
- log.debug(` ==> dryRun: ${dryRun}`);
29
- if (dryRun && dryRun !== true && dryRun !== false) {
30
- throw new ValidationError('Parameter "dryRun" is not valid');
31
- }
32
- }
28
+ log.debug(` ==> dryRun: ${dryRun}`);
29
+ if (dryRun && dryRun !== true && dryRun !== false) {
30
+ throw new ValidationError('Parameter "dryRun" is not valid');
31
+ }
32
+ }
33
33
  }