@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,95 +1,75 @@
1
- // @deprecated in favor of `alias` command
1
+ import Alias from "../classes/alias.js";
2
+ import { Alias as AliasFormatter } from "../formatters/index.js";
3
+ import { commandHandler } from "../utils/command-handler.js";
2
4
 
3
- import ora from 'ora';
4
- import Alias from '../classes/alias.js';
5
- import { logger, getDefaults } from '../utils/index.js';
6
- import { Alias as AliasFormatter } from '../formatters/index.js';
5
+ export const command = "map-alias <name> <version> <alias>";
7
6
 
8
- export const command = 'map-alias <name> <version> <alias>';
7
+ export const aliases = ["ma"];
9
8
 
10
- export const aliases = ['ma'];
9
+ export const describe = "Create an alias for a map";
11
10
 
12
- export const describe = `DEPRECATED: This command has been replaced by the alias command and will be removed in a future version. Create a semver major alias for an import map as identified by its name and version. An import map with the given name and version must already exist on asset server. Alias should be the semver major part of the import map version. Eg. For an import map of version 5.4.3, you should use 5 as the alias`;
11
+ export const deprecated = "map-alias has been replaced by alias";
13
12
 
13
+ /** @type {import('yargs').CommandBuilder} */
14
14
  export const builder = (yargs) => {
15
- const defaults = getDefaults(yargs.argv.config || yargs.argv.cwd);
16
-
17
- yargs
18
- .positional('name', {
19
- describe: `Import map name for import map that is to be aliased`,
20
- type: 'string',
21
- })
22
- .positional('version', {
23
- describe: `Import map version for import map that is to be aliased`,
24
- type: 'string',
25
- })
26
- .positional('alias', {
27
- describe: `Alias for a semver version. Should be the semver major component of version.`,
28
- type: 'string',
29
- });
30
-
31
- yargs.options({
32
- server: {
33
- alias: 's',
34
- describe: 'Specify location of asset server.',
35
- // @ts-expect-error
36
- default: defaults.server,
37
- },
38
- token: {
39
- describe:
40
- 'Provide a jwt token to be used to authenticate with the Eik server.',
41
- default: '',
42
- alias: 't',
43
- },
44
- });
45
-
46
- // @ts-expect-error
47
- yargs.default('token', defaults.token, defaults.token ? '######' : '');
48
-
49
- yargs.example(`eik map-alias my-map 1.0.0 1`);
50
- yargs.example(`eik map-alias my-map 1.7.3 1`);
51
- yargs.example(`eik map-alias my-map 6.3.1 6`);
52
- yargs.example(
53
- `eik map-alias my-map 6.3.1 6 --server https://assets.myeikserver.com`,
54
- );
55
- yargs.example(`eik map-alias my-map 4.2.2 4 --debug`);
15
+ return yargs
16
+ .positional("name", {
17
+ describe: "Import map package name",
18
+ type: "string",
19
+ })
20
+ .positional("version", {
21
+ describe: "Import map version",
22
+ type: "string",
23
+ })
24
+ .positional("alias", {
25
+ describe:
26
+ "Alias value, the semver major component of the import map version",
27
+ type: "string",
28
+ })
29
+ .options({
30
+ server: {
31
+ alias: "s",
32
+ describe: "Eik server address, if different from configuration file",
33
+ },
34
+ token: {
35
+ describe: "JWT used for authentication, if not using eik login",
36
+ alias: "t",
37
+ },
38
+ })
39
+ .example("eik map-alias my-map 1.0.0 1")
40
+ .example("eik map-alias my-map 1.7.3 1")
41
+ .example("eik map-alias my-map 6.3.1 6")
42
+ .example(
43
+ "eik map-alias my-map 6.3.1 6 --server https://assets.myeikserver.com",
44
+ )
45
+ .example("eik map-alias my-map 6.3.1 6 --token yourtoken");
56
46
  };
57
47
 
58
- export const handler = async (argv) => {
59
- const spinner = ora({ stream: process.stdout }).start('working...');
60
- let success = false;
61
- const { debug, name, version, server } = argv;
62
- const log = logger(spinner, debug);
63
- let data = {};
48
+ export const handler = commandHandler(
49
+ { command, options: ["server"] },
50
+ async (argv, log) => {
51
+ const { debug, name, version, server, ...rest } = argv;
64
52
 
65
- try {
66
- data = await new Alias({
67
- type: 'map',
68
- logger: log,
69
- ...argv,
70
- }).run();
53
+ const data = await new Alias({
54
+ debug,
55
+ name,
56
+ version,
57
+ server,
58
+ ...rest,
59
+ type: "map",
60
+ logger: log,
61
+ }).run();
71
62
 
72
- data.name = name;
73
- data.version = version;
74
- data.files = [];
63
+ data.name = name;
64
+ data.version = version;
65
+ data.files = [];
75
66
 
76
- const createdOrUpdated = data.update ? 'Updated' : 'Created';
77
- log.info(
78
- `${createdOrUpdated} alias for package "${data.name}". ("${data.version}" => "v${data.alias}")`,
79
- );
80
- success = true;
81
- } catch (err) {
82
- log.warn(err.message);
83
- }
67
+ const createdOrUpdated = data.update ? "Updated" : "Created";
84
68
 
85
- spinner.text = '';
86
- spinner.stopAndPersist();
87
- if (success) {
88
- new AliasFormatter(data).format(server);
89
- } else {
90
- process.exit(1);
91
- }
92
- };
69
+ log.info(
70
+ `${createdOrUpdated} alias for package "${data.name}". ("${data.version}" => "v${data.alias}")`,
71
+ );
93
72
 
94
- export const deprecated =
95
- '"map-alias" will be removed in a future version. Please use "alias" instead';
73
+ new AliasFormatter(data).format(server);
74
+ },
75
+ );
package/commands/map.js CHANGED
@@ -1,90 +1,76 @@
1
- import { join } from 'path';
2
- import ora from 'ora';
3
- import PublishMap from '../classes/publish/map.js';
4
- import { logger, getDefaults } from '../utils/index.js';
5
- import { Artifact } from '../formatters/index.js';
1
+ import { join } from "path";
2
+ import PublishMap from "../classes/publish/map.js";
3
+ import { Artifact } from "../formatters/index.js";
4
+ import { commandHandler } from "../utils/command-handler.js";
6
5
 
7
- export const command = 'map <name> <version> <file>';
6
+ export const command = "map <name> <version> <file>";
8
7
 
9
- export const aliases = ['m'];
8
+ export const aliases = ["m"];
10
9
 
11
- export const describe = `Upload an import map file to the server under a given name and version. A name/version combination must be unique and a version must be semver compliant. Subsquent published versions must increase. Eg. 1.0.0 1.0.1, 1.1.0, 2.0.0 etc.`;
10
+ export const describe = "Publish an import map to the server";
12
11
 
12
+ /** @type {import('yargs').CommandBuilder} */
13
13
  export const builder = (yargs) => {
14
- const defaults = getDefaults(yargs.argv.config || yargs.argv.cwd);
15
-
16
- yargs
17
- .positional('name', {
18
- describe: 'Import map name.',
19
- type: 'string',
20
- })
21
- .positional('version', {
22
- describe: 'Import map version.',
23
- type: 'string',
24
- })
25
- .positional('file', {
26
- describe:
27
- 'Path to import map file on local disk relative to the current working directory.',
28
- type: 'string',
29
- normalize: true,
30
- });
31
-
32
- yargs.options({
33
- server: {
34
- alias: 's',
35
- describe: 'Specify location of asset server.',
36
- // @ts-expect-error
37
- default: defaults.server,
38
- },
39
- token: {
40
- describe:
41
- 'Provide a jwt token to be used to authenticate with the Eik server.',
42
- default: '',
43
- alias: 't',
44
- },
45
- });
46
-
47
- // @ts-expect-error
48
- yargs.default('token', defaults.token, defaults.token ? '######' : '');
49
-
50
- yargs.example(`eik map my-map 1.0.0 ./import-map.json`);
51
- yargs.example(`eik map my-map 2.1.0 ./import-map.json --debug`);
52
- yargs.example(
53
- `eik map my-map 2.1.1 ./import-map.json --server https://assets.myeikserver.com`,
54
- );
14
+ return yargs
15
+ .positional("name", {
16
+ describe: "Import map name.",
17
+ type: "string",
18
+ })
19
+ .positional("version", {
20
+ describe: "Import map version.",
21
+ type: "string",
22
+ })
23
+ .positional("file", {
24
+ describe:
25
+ "Path to import map file on local disk relative to the current working directory.",
26
+ type: "string",
27
+ normalize: true,
28
+ })
29
+ .options({
30
+ server: {
31
+ alias: "s",
32
+ describe: "Eik server address, if different from configuration file",
33
+ },
34
+ token: {
35
+ describe: "JWT used for authentication, if not using eik login",
36
+ alias: "t",
37
+ },
38
+ })
39
+ .example("eik map my-map 1.0.0 ./import-map.json")
40
+ .example(
41
+ "eik map my-map 2.1.1 ./import-map.json --server https://assets.myeikserver.com",
42
+ )
43
+ .example("eik map my-map 1.0.0 ./import-map.json --token yourtoken");
55
44
  };
56
45
 
57
- export const handler = async (argv) => {
58
- const spinner = ora({ stream: process.stdout }).start('working...');
59
- const { debug, server, name, version } = argv;
60
-
61
- try {
62
- const log = logger(spinner, debug);
63
-
64
- await new PublishMap({ logger: log, ...argv }).run();
65
-
66
- let url = new URL(join('map', name), server);
67
- let res = await fetch(url);
68
- const pkgMeta = await res.json();
69
-
70
- url = new URL(join('map', name, version), server);
71
- res = await fetch(url);
72
-
73
- log.info(`Published import map "${name}" at version "${version}"`);
74
-
75
- spinner.text = '';
76
- spinner.stopAndPersist();
77
-
78
- const artifact = new Artifact(pkgMeta);
79
- const versions = new Map(pkgMeta.versions);
80
- artifact.versions = Array.from(versions.values());
81
- artifact.format(server);
82
-
83
- process.stdout.write('\n');
84
- } catch (err) {
85
- spinner.warn(err.message);
86
- spinner.text = '';
87
- spinner.stopAndPersist();
88
- process.exit(1);
89
- }
90
- };
46
+ export const handler = commandHandler(
47
+ { command, options: ["server"] },
48
+ async (argv, log) => {
49
+ const { debug, name, version, server, ...rest } = argv;
50
+
51
+ await new PublishMap({
52
+ logger: log,
53
+ debug,
54
+ name,
55
+ version,
56
+ server,
57
+ ...rest,
58
+ }).run();
59
+
60
+ let url = new URL(join("map", name), server);
61
+ let res = await fetch(url);
62
+ const pkgMeta = await res.json();
63
+
64
+ url = new URL(join("map", name, version), server);
65
+ res = await fetch(url);
66
+
67
+ log.info(`Published import map "${name}" at version "${version}"`);
68
+
69
+ const artifact = new Artifact(pkgMeta);
70
+ const versions = new Map(pkgMeta.versions);
71
+ artifact.versions = Array.from(versions.values());
72
+ artifact.format(server);
73
+
74
+ process.stdout.write("\n");
75
+ },
76
+ );
package/commands/meta.js CHANGED
@@ -1,60 +1,43 @@
1
- import ora from 'ora';
2
- import Meta from '../classes/meta.js';
3
- import { Artifact } from '../formatters/index.js';
4
- import { logger, getDefaults } from '../utils/index.js';
1
+ import Meta from "../classes/meta.js";
2
+ import { Artifact } from "../formatters/index.js";
3
+ import { commandHandler } from "../utils/command-handler.js";
5
4
 
6
- export const command = 'meta <name>';
5
+ export const command = "meta <name>";
7
6
 
8
- export const aliases = ['show'];
7
+ export const aliases = ["show"];
9
8
 
10
- export const describe = `Retrieve meta information by package, map or npm name.If a given name exists in several types (package and map for example), results will be returned and displayed from all matching types`;
9
+ export const describe = "Get information about a package";
11
10
 
11
+ /** @type {import('yargs').CommandBuilder} */
12
12
  export const builder = (yargs) => {
13
- const defaults = getDefaults(yargs.argv.config || yargs.argv.cwd);
14
-
15
- yargs.positional('name', {
16
- describe:
17
- 'Name matching one or more of package, npm or import map name',
18
- type: 'string',
19
- });
20
-
21
- yargs.options({
22
- server: {
23
- alias: 's',
24
- describe: 'Specify location of asset server.',
25
- // @ts-expect-error
26
- default: defaults.server,
27
- },
28
- });
29
-
30
- yargs.example(`eik meta lit-html`);
31
- yargs.example(`eik meta my-map --debug`);
32
- yargs.example(`eik meta my-app --server https://assets.myeikserver.com`);
13
+ return yargs
14
+ .positional("name", {
15
+ describe: "Name matching one or more of package, npm or import map name",
16
+ type: "string",
17
+ })
18
+ .options({
19
+ server: {
20
+ alias: "s",
21
+ describe: "Eik server address, if different from configuration file",
22
+ },
23
+ })
24
+ .example("eik meta lit-html")
25
+ .example("eik meta my-map --debug")
26
+ .example("eik meta my-app --server https://assets.myeikserver.com");
33
27
  };
34
28
 
35
- export const handler = async (argv) => {
36
- const spinner = ora({ stream: process.stdout }).start('working...');
37
- let meta = false;
38
- const { debug, server } = argv;
39
- const l = logger(spinner, debug);
40
-
41
- try {
42
- // @ts-expect-error
43
- meta = await new Meta({ logger: l, ...argv }).run();
44
- spinner.text = '';
45
- spinner.stopAndPersist();
46
- } catch (err) {
47
- spinner.text = '';
48
- spinner.stopAndPersist();
49
- l.warn(err.message);
50
- process.exit(1);
51
- }
52
-
53
- if (meta) {
54
- for (const m of Object.values(meta)) {
55
- const artifact = new Artifact(m);
56
- artifact.format(server);
57
- process.stdout.write(`\n`);
58
- }
59
- }
60
- };
29
+ export const handler = commandHandler(
30
+ { command, options: ["server"] },
31
+ async (argv, log) => {
32
+ const { debug, server, ...rest } = argv;
33
+
34
+ const meta = await new Meta({ logger: log, debug, server, ...rest }).run();
35
+ if (meta) {
36
+ for (const m of Object.values(meta)) {
37
+ const artifact = new Artifact(m);
38
+ artifact.format(server);
39
+ process.stdout.write(`\n`);
40
+ }
41
+ }
42
+ },
43
+ );
@@ -1,90 +1,65 @@
1
- // @deprecated in favor of `alias` command
1
+ import Alias from "../classes/alias.js";
2
+ import { Alias as AliasFormatter } from "../formatters/index.js";
3
+ import { commandHandler } from "../utils/command-handler.js";
2
4
 
3
- import ora from 'ora';
4
- import Alias from '../classes/alias.js';
5
- import { logger, getDefaults } from '../utils/index.js';
6
- import { Alias as AliasFormatter } from '../formatters/index.js';
5
+ export const command = "npm-alias <name> <version> <alias>";
7
6
 
8
- export const command = 'npm-alias <name> <version> <alias>';
7
+ export const aliases = ["na", "dep-alias", "dependency-alias"];
9
8
 
10
- export const aliases = ['na', 'dep-alias', 'dependency-alias'];
9
+ export const describe = "Create an alias for an NPM package";
11
10
 
12
- export const describe = `DEPRECATED: This command has been replaced by the alias command and will be removed in a future version. Create a semver major alias for an NPM package as identified by its name and version. An NPM package with the given name and version must already exist on the asset server. Alias should be the semver major part of the NPM package version. Eg. For an NPM package of version 5.4.3, you should use 5 as the alias`;
11
+ export const deprecated = "npm-alias has been replaced by alias";
13
12
 
13
+ /** @type {import('yargs').CommandBuilder} */
14
14
  export const builder = (yargs) => {
15
- const defaults = getDefaults(yargs.argv.config || yargs.argv.cwd);
16
-
17
- yargs
18
- .positional('name', {
19
- describe: 'Name matching NPM package name.',
20
- type: 'string',
21
- })
22
- .positional('version', {
23
- describe: 'Version matching NPM package version.',
24
- type: 'string',
25
- })
26
- .positional('alias', {
27
- describe:
28
- 'Alias for a semver version. Must be the semver major component of version.',
29
- type: 'string',
30
- });
31
-
32
- yargs.options({
33
- server: {
34
- alias: 's',
35
- describe: 'Specify location of asset server.',
36
- // @ts-expect-error
37
- default: defaults.server,
38
- },
39
- token: {
40
- describe:
41
- 'Provide a jwt token to be used to authenticate with the Eik server.',
42
- default: '',
43
- alias: 't',
44
- },
45
- });
46
-
47
- // @ts-expect-error
48
- yargs.default('token', defaults.token, defaults.token ? '######' : '');
49
-
50
- yargs.example(`eik npm lit-html 1.0.0 1`);
51
- yargs.example(`eik npm lit-html 1.3.5 1 --debug`);
52
- yargs.example(
53
- `eik npm lit-html 5.3.2 5 --server https://assets.myeikserver.com`,
54
- );
15
+ return yargs
16
+ .positional("name", {
17
+ describe: "Name matching NPM package name.",
18
+ type: "string",
19
+ })
20
+ .positional("version", {
21
+ describe: "Version matching NPM package version.",
22
+ type: "string",
23
+ })
24
+ .positional("alias", {
25
+ describe:
26
+ "Alias for a semver version. Must be the semver major component of version.",
27
+ type: "string",
28
+ })
29
+ .options({
30
+ server: {
31
+ alias: "s",
32
+ describe: "Eik server address, if different from configuration file",
33
+ },
34
+ token: {
35
+ describe: "JWT used for authentication, if not using eik login",
36
+ alias: "t",
37
+ },
38
+ })
39
+ .example("eik npm-alias lit-html 1.0.0 1")
40
+ .example(
41
+ "eik npm-alias lit-html 5.3.2 5 --server https://assets.myeikserver.com",
42
+ )
43
+ .example("eik npm-alias lit-html 1.0.0 1 --token yourtoken");
55
44
  };
56
45
 
57
- export const handler = async (argv) => {
58
- const spinner = ora({ stream: process.stdout }).start('working...');
59
- let success = false;
60
- const { debug, server } = argv;
61
- const log = logger(spinner, debug);
62
- let data = {};
46
+ export const handler = commandHandler(
47
+ { command, options: ["server"] },
48
+ async (argv, log) => {
49
+ const { debug, server, ...rest } = argv;
63
50
 
64
- try {
65
- data = await new Alias({
66
- type: 'npm',
67
- logger: log,
68
- ...argv,
69
- }).run();
70
-
71
- const createdOrUpdated = data.update ? 'Updated' : 'Created';
72
- log.info(
73
- `${createdOrUpdated} alias for package "${data.name}". ("${data.version}" => "v${data.alias}")`,
74
- );
75
- success = true;
76
- } catch (err) {
77
- log.warn(err.message);
78
- }
79
-
80
- spinner.text = '';
81
- spinner.stopAndPersist();
82
- if (success) {
83
- new AliasFormatter(data).format(server);
84
- } else {
85
- process.exit(1);
86
- }
87
- };
51
+ const data = await new Alias({
52
+ debug,
53
+ server,
54
+ ...rest,
55
+ type: "npm",
56
+ logger: log,
57
+ }).run();
88
58
 
89
- export const deprecated =
90
- '"npm-alias" will be removed in a future version. Please use "alias" instead';
59
+ const createdOrUpdated = data.update ? "Updated" : "Created";
60
+ log.info(
61
+ `${createdOrUpdated} alias for package "${data.name}". ("${data.version}" => "v${data.alias}")`,
62
+ );
63
+ new AliasFormatter(data).format(server);
64
+ },
65
+ );