@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,102 +1,70 @@
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 semver from 'semver';
5
- import Alias from '../classes/alias.js';
6
- import { logger, getDefaults } from '../utils/index.js';
7
- import { Alias as AliasFormatter } from '../formatters/index.js';
5
+ export const command = "package-alias [name] [version] [alias]";
8
6
 
9
- export const command = 'package-alias [name] [version] [alias]';
7
+ export const aliases = ["pkg-alias", "pa"];
10
8
 
11
- export const aliases = ['pkg-alias', 'pa'];
9
+ export const describe = "Create an alias for a package";
12
10
 
13
- 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 a package as identified by its name and version. A package with the given name and version must already exist on asset server. 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`;
11
+ export const deprecated = "package-alias has been replaced by alias";
14
12
 
13
+ /** @type {import('yargs').CommandBuilder} */
15
14
  export const builder = (yargs) => {
16
- const defaults = getDefaults(yargs.argv.config || yargs.argv.cwd);
17
-
18
- yargs
19
- .positional('name', {
20
- describe: 'Name matching existing name for a package on Eik server',
21
- type: 'string',
22
- // @ts-expect-error
23
- default: defaults.name,
24
- })
25
- .positional('version', {
26
- describe:
27
- 'Version matching existing version for a package on Eik server',
28
- type: 'string',
29
- // @ts-expect-error
30
- default: defaults.version,
31
- })
32
- .positional('alias', {
33
- describe:
34
- 'Alias for a semver version. Must be the semver major component of version. Eg. 1.0.0 should be given as 1',
35
- type: 'string',
36
- // @ts-expect-error
37
- default: defaults.version ? semver.major(defaults.version) : null,
38
- });
39
-
40
- yargs.options({
41
- server: {
42
- alias: 's',
43
- describe: 'Specify location of Eik asset server.',
44
- // @ts-expect-error
45
- default: defaults.server,
46
- },
47
- token: {
48
- describe:
49
- 'Provide a jwt token to be used to authenticate with the Eik server.',
50
- default: '',
51
- alias: 't',
52
- },
53
- });
54
-
55
- // @ts-expect-error
56
- yargs.default('token', defaults.token, defaults.token ? '######' : '');
57
-
58
- yargs.example(`eik package-alias my-app 1.0.0 1`);
59
- yargs.example(`eik package-alias my-app 1.7.3 1`);
60
- yargs.example(`eik package-alias my-app 6.3.1 6`);
61
- yargs.example(
62
- `eik package-alias my-app 6.3.1 6 --server https://assets.myeikserver.com`,
63
- );
64
- yargs.example(`eik package-alias my-app 4.2.2 4 --debug`);
15
+ return yargs
16
+ .positional("name", {
17
+ describe: "Name matching existing name for a package on Eik server",
18
+ type: "string",
19
+ })
20
+ .positional("version", {
21
+ describe: "Version matching existing version for a package on Eik server",
22
+ type: "string",
23
+ })
24
+ .positional("alias", {
25
+ describe:
26
+ "Alias for a semver version. Must be the semver major component of version. Eg. 1.0.0 should be given as 1",
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 package-alias my-app 1.0.0 1")
40
+ .example("eik package-alias my-app 1.7.3 1")
41
+ .example("eik package-alias my-app 6.3.1 6")
42
+ .example(
43
+ "eik package-alias my-app 6.3.1 6 --server https://assets.myeikserver.com",
44
+ )
45
+ .example("eik package-alias my-app 4.2.2 4 --token yourtoken");
65
46
  };
66
47
 
67
- export const handler = async (argv) => {
68
- const spinner = ora({ stream: process.stdout }).start('working...');
69
- let success = false;
70
- const { debug, server } = argv;
71
- const log = logger(spinner, debug);
72
- let af;
73
-
74
- try {
75
- const data = await new Alias({
76
- type: 'pkg',
77
- logger: log,
78
- ...argv,
79
- }).run();
48
+ export const handler = commandHandler(
49
+ { command, options: ["server"] },
50
+ async (argv, log) => {
51
+ const { debug, server, ...rest } = argv;
80
52
 
81
- af = new AliasFormatter(data);
53
+ const data = await new Alias({
54
+ debug,
55
+ server,
56
+ ...rest,
57
+ type: "pkg",
58
+ logger: log,
59
+ }).run();
82
60
 
83
- const createdOrUpdated = data.update ? 'Updated' : 'Created';
84
- log.info(
85
- `${createdOrUpdated} alias for package "${data.name}". ("${data.version}" => "v${data.alias}")`,
86
- );
87
- success = true;
88
- } catch (err) {
89
- log.warn(err.message);
90
- }
61
+ const af = new AliasFormatter(data);
91
62
 
92
- spinner.text = '';
93
- spinner.stopAndPersist();
94
- if (success) {
95
- af?.format(server);
96
- } else {
97
- process.exit(1);
98
- }
99
- };
63
+ const createdOrUpdated = data.update ? "Updated" : "Created";
64
+ log.info(
65
+ `${createdOrUpdated} alias for package "${data.name}". ("${data.version}" => "v${data.alias}")`,
66
+ );
100
67
 
101
- export const deprecated =
102
- '"package-alias" will be removed in a future version. Please use "alias" instead';
68
+ af.format(server);
69
+ },
70
+ );
package/commands/ping.js CHANGED
@@ -1,38 +1,27 @@
1
- import ora from 'ora';
2
- import Ping from '../classes/ping.js';
3
- import { logger, getDefaults } from '../utils/index.js';
1
+ import Ping from "../classes/ping.js";
2
+ import { commandHandler } from "../utils/command-handler.js";
4
3
 
5
- export const command = 'ping [server]';
4
+ // TODO: replace positional argument with --server to be in line with other commands
5
+ export const command = "ping [server]";
6
6
 
7
7
  export const aliases = [];
8
8
 
9
- export const describe = `Ping an Eik server to check that it is responding.`;
9
+ export const describe = "Check that the Eik server is responding";
10
10
 
11
+ /** @type {import('yargs').CommandBuilder} */
11
12
  export const builder = (yargs) => {
12
- const defaults = getDefaults(yargs.argv.config || yargs.argv.cwd);
13
-
14
- yargs.positional('server', {
15
- describe: 'Specify location of Eik server to ping.',
16
- // @ts-expect-error
17
- default: defaults.server,
18
- });
19
-
20
- yargs.example(`eik ping`);
21
- yargs.example(`eik ping http://assets.myeikserver.com`);
22
- yargs.example(`eik ping http://assets.myeikserver.com --debug`);
13
+ return yargs
14
+ .positional("server", {
15
+ describe: "Specify location of Eik server to check against.",
16
+ })
17
+ .example("eik ping")
18
+ .example("eik ping http://assets.myeikserver.com");
23
19
  };
24
20
 
25
- export const handler = async (argv) => {
26
- const spinner = ora({ stream: process.stdout }).start('working...');
27
- const { debug, server } = argv;
28
-
29
- try {
30
- await new Ping({ logger: logger(spinner, debug), server }).run();
31
- } catch (err) {
32
- // @ts-expect-error
33
- logger.warn(err.message);
34
- }
35
-
36
- spinner.text = '';
37
- spinner.stopAndPersist();
38
- };
21
+ export const handler = commandHandler(
22
+ { command, options: ["server"] },
23
+ async (argv, logger) => {
24
+ const { server } = argv;
25
+ await new Ping({ logger, server }).run();
26
+ },
27
+ );
@@ -1,134 +1,124 @@
1
- import { join } from 'path';
2
- import ora from 'ora';
3
- import chalk from 'chalk';
4
- import PublishPackage from '../classes/publish/package/index.js';
5
- import { logger, getDefaults, typeSlug, typeTitle } from '../utils/index.js';
6
- import { Artifact } from '../formatters/index.js';
1
+ import { join } from "path";
2
+ import chalk from "chalk";
3
+ import PublishPackage from "../classes/publish/package/index.js";
4
+ import { typeSlug, typeTitle } from "../utils/index.js";
5
+ import { Artifact } from "../formatters/index.js";
6
+ import { EikCliError, errors } from "../utils/error.js";
7
+ import { commandHandler } from "../utils/command-handler.js";
7
8
 
8
- export const command = 'publish';
9
+ export const command = "publish";
9
10
 
10
- export const aliases = ['pkg', 'package', 'pub'];
11
+ export const aliases = ["pkg", "package", "pub"];
11
12
 
12
- export const describe = `Publish an app package to an Eik server. Reads configuration from eik.json or package.json files. See https://eik.dev for more details.`;
13
+ export const describe = "Publish an app package to an Eik server";
13
14
 
15
+ /** @type {import('yargs').CommandBuilder} */
14
16
  export const builder = (yargs) => {
15
- const defaults = getDefaults(yargs.argv.config || yargs.argv.cwd);
16
-
17
- yargs.options({
18
- dryRun: {
19
- alias: 'd',
20
- describe:
21
- 'Terminates the publish early (before upload) and provides information about created bundles for inspection.',
22
- default: false,
23
- type: 'boolean',
24
- },
25
- token: {
26
- describe: `Provide a jwt token to be used to authenticate with the Eik server. Automatically determined if authenticated (via eik login)`,
27
- type: 'string',
28
- alias: 't',
29
- },
30
- });
31
-
32
- // @ts-expect-error
33
- yargs.default('token', defaults.token, defaults.token ? '######' : '');
34
-
35
- yargs.example(`eik publish`);
36
- yargs.example(`eik package`);
37
- yargs.example(`eik pub --dry-run`);
38
- yargs.example(`eik pkg --token ######`);
39
- yargs.example(`eik pkg --debug`);
17
+ return yargs
18
+ .options({
19
+ dryRun: {
20
+ alias: "d",
21
+ describe: "Log details about the operation and skip upload",
22
+ type: "boolean",
23
+ },
24
+ token: {
25
+ describe: "JWT used for authentication, if not using eik login",
26
+ type: "string",
27
+ alias: "t",
28
+ },
29
+ })
30
+ .example("eik publish")
31
+ .example("eik publish --dry-run")
32
+ .example("eik publish --token yourtoken");
40
33
  };
41
34
 
42
- export const handler = async (argv) => {
43
- const spinner = ora({ stream: process.stdout }).start('working...');
44
- const { debug, dryRun, cwd, token, config } = argv;
45
- // @ts-expect-error
46
- const { name, version, server, map, out, files, type } = getDefaults(
47
- config || cwd,
48
- );
49
-
50
- if (type === 'map') {
51
- spinner.warn(
52
- '"type" is set to "map", which is not supported by the publish command. Please use the "eik map" command instead',
53
- );
54
- process.stdout.write('\n');
55
- process.exit(0);
56
- }
57
-
58
- try {
59
- const options = {
60
- logger: logger(spinner, debug),
61
- cwd,
62
- token,
63
- dryRun,
64
- debug,
65
- name,
66
- server,
67
- version,
68
- type,
69
- map,
70
- out,
71
- files,
72
- };
73
-
74
- const publish = await new PublishPackage(options).run();
75
-
76
- if (!publish) {
77
- spinner.warn(
78
- 'Version in eik.json has not changed since last publish, publishing is not necessary',
79
- );
80
- process.stdout.write('\n');
81
- process.exit(0);
82
- }
83
-
84
- const { files: fls } = publish;
85
-
86
- if (!dryRun) {
87
- let url = new URL(join(typeSlug(type), name), server);
88
- let res = await fetch(url);
89
- const pkgMeta = await res.json();
90
-
91
- url = new URL(join(typeSlug(type), name, version), server);
92
- res = await fetch(url);
93
- const pkgVersionMeta = await res.json();
94
-
95
- const artifact = new Artifact(pkgMeta);
96
- artifact.versions = [pkgVersionMeta];
97
-
98
- spinner.text = '';
99
- spinner.stopAndPersist();
100
-
101
- artifact.format(server);
102
- process.stdout.write('\n');
103
- } else {
104
- spinner.text = '';
105
- spinner.stopAndPersist();
106
-
107
- process.stdout.write(
108
- `:: ${chalk.bgYellow.white.bold(
109
- typeTitle(type),
110
- )} > ${chalk.green(name)} | ${chalk.bold('dry run')}`,
111
- );
112
- process.stdout.write('\n\n');
113
- process.stdout.write(' files (local temporary):\n');
114
- for (const file of fls) {
115
- process.stdout.write(
116
- ` - ${chalk.bold('type')}: ${file.type}\n`,
117
- );
118
- process.stdout.write(
119
- ` ${chalk.bold('path')}: ${file.pathname}\n\n`,
120
- );
121
- }
122
- process.stdout.write(
123
- ` ${chalk.bold(
124
- 'No files were published to remote server',
125
- )}\n\n`,
126
- );
127
- }
128
- } catch (err) {
129
- spinner.warn(err.message);
130
- spinner.text = '';
131
- spinner.stopAndPersist();
132
- process.exit(1);
133
- }
134
- };
35
+ export const handler = commandHandler(
36
+ { command, options: ["server"] },
37
+ async (argv, log, spinner) => {
38
+ const {
39
+ debug,
40
+ dryRun,
41
+ cwd,
42
+ token,
43
+ name,
44
+ version,
45
+ server,
46
+ map,
47
+ out,
48
+ files,
49
+ type,
50
+ } = argv;
51
+
52
+ if (type === "map") {
53
+ throw new EikCliError(
54
+ errors.ERR_WRONG_TYPE,
55
+ '"type" is set to "map", which is not supported by the publish command. Please use the "eik map" command instead',
56
+ );
57
+ }
58
+
59
+ const options = {
60
+ logger: log,
61
+ cwd,
62
+ token,
63
+ dryRun,
64
+ debug,
65
+ name,
66
+ server,
67
+ version,
68
+ type,
69
+ map,
70
+ out,
71
+ files,
72
+ };
73
+
74
+ const publish = await new PublishPackage(options).run();
75
+
76
+ if (!publish) {
77
+ throw new EikCliError(
78
+ errors.ERR_VERSION_EXISTS,
79
+ "Version in eik.json has not changed since last publish, publishing is not necessary",
80
+ );
81
+ }
82
+
83
+ const { files: fls } = publish;
84
+
85
+ if (!dryRun) {
86
+ let url = new URL(join(typeSlug(type), name), server);
87
+ let res = await fetch(url);
88
+ const pkgMeta = await res.json();
89
+
90
+ url = new URL(join(typeSlug(type), name, version), server);
91
+ res = await fetch(url);
92
+ const pkgVersionMeta = await res.json();
93
+
94
+ const artifact = new Artifact(pkgMeta);
95
+ artifact.versions = [pkgVersionMeta];
96
+
97
+ spinner.text = "";
98
+ spinner.stopAndPersist();
99
+
100
+ artifact.format(server);
101
+ process.stdout.write("\n");
102
+ } else {
103
+ spinner.text = "";
104
+ spinner.stopAndPersist();
105
+
106
+ process.stdout.write(
107
+ `:: ${chalk.bgYellow.white.bold(
108
+ typeTitle(type),
109
+ )} > ${chalk.green(name)} | ${chalk.bold("dry run")}`,
110
+ );
111
+ process.stdout.write("\n\n");
112
+ process.stdout.write(" files (local temporary):\n");
113
+ for (const file of fls) {
114
+ process.stdout.write(` - ${chalk.bold("type")}: ${file.type}\n`);
115
+ process.stdout.write(
116
+ ` ${chalk.bold("path")}: ${file.pathname}\n\n`,
117
+ );
118
+ }
119
+ process.stdout.write(
120
+ ` ${chalk.bold("No files were published to remote server")}\n\n`,
121
+ );
122
+ }
123
+ },
124
+ );