@eik/cli 3.1.4 → 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.
- package/CHANGELOG.md +7 -0
- package/classes/alias.js +1 -1
- package/commands/alias.js +35 -69
- package/commands/init.js +75 -88
- package/commands/integrity.js +20 -33
- package/commands/login.js +51 -70
- package/commands/map-alias.js +41 -61
- package/commands/map.js +34 -48
- package/commands/meta.js +31 -47
- package/commands/npm-alias.js +32 -57
- package/commands/package-alias.js +35 -66
- package/commands/ping.js +17 -28
- package/commands/publish.js +50 -56
- package/commands/version.js +36 -42
- package/index.js +52 -48
- package/package.json +3 -3
- package/readme.md +1 -1
- package/types/classes/alias.d.ts +2 -2
- package/types/utils/defaults.d.ts +22 -0
- package/types/utils/error.d.ts +19 -0
- package/types/utils/index.d.ts +2 -2
- package/utils/command-handler.js +72 -0
- package/utils/defaults.js +79 -0
- package/utils/error.js +42 -0
- package/utils/index.js +3 -2
- package/commands/index.js +0 -27
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [3.1.5](https://github.com/eik-lib/cli/compare/v3.1.4...v3.1.5) (2024-08-29)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* handle relative and absolute paths to config, improve error messages, edit help for brevity ([06e9951](https://github.com/eik-lib/cli/commit/06e9951a6efe6b3f37600f6f0477417e708dcf08))
|
7
|
+
|
1
8
|
## [3.1.4](https://github.com/eik-lib/cli/compare/v3.1.3...v3.1.4) (2024-08-26)
|
2
9
|
|
3
10
|
|
package/classes/alias.js
CHANGED
@@ -9,7 +9,7 @@ import { joinUrlPathname } from "../utils/url.js";
|
|
9
9
|
* @typedef {object} AliasOptions
|
10
10
|
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
11
11
|
* @property {string} server
|
12
|
-
* @property {"package" | "npm" | "map"} [type="package"]
|
12
|
+
* @property {"package" | "npm" | "image" | "map"} [type="package"]
|
13
13
|
* @property {string} name
|
14
14
|
* @property {string} version
|
15
15
|
* @property {string} alias
|
package/commands/alias.js
CHANGED
@@ -1,105 +1,71 @@
|
|
1
|
-
import ora from "ora";
|
2
|
-
import semver from "semver";
|
3
1
|
import Alias from "../classes/alias.js";
|
4
|
-
import { logger, getDefaults } from "../utils/index.js";
|
5
2
|
import { Alias as AliasFormatter } from "../formatters/index.js";
|
3
|
+
import { commandHandler } from "../utils/command-handler.js";
|
6
4
|
|
7
5
|
export const command = "alias [name] [version] [alias]";
|
8
6
|
|
9
7
|
export const aliases = ["a"];
|
10
8
|
|
11
|
-
export const describe =
|
9
|
+
export const describe =
|
10
|
+
"Create or update a semver major alias for a package or map";
|
12
11
|
|
12
|
+
/** @type {import('yargs').CommandBuilder} */
|
13
13
|
export const builder = (yargs) => {
|
14
|
-
|
15
|
-
|
16
|
-
yargs
|
14
|
+
return yargs
|
17
15
|
.positional("name", {
|
18
16
|
describe: "Name matching a package or import map on the Eik server",
|
19
17
|
type: "string",
|
20
|
-
// @ts-expect-error
|
21
|
-
default: defaults.name,
|
22
18
|
})
|
23
19
|
.positional("version", {
|
24
20
|
describe: "The version the alias should redirect to",
|
25
21
|
type: "string",
|
26
|
-
// @ts-expect-error
|
27
|
-
default: defaults.version,
|
28
22
|
})
|
29
23
|
.positional("alias", {
|
30
24
|
describe:
|
31
25
|
"Alias, should be the semver major component of version. Eg. 1.0.0 should be given the alias 1",
|
32
26
|
type: "string",
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
default: "",
|
54
|
-
alias: "t",
|
55
|
-
},
|
56
|
-
});
|
57
|
-
|
58
|
-
// @ts-expect-error
|
59
|
-
yargs.default("token", defaults.token, defaults.token ? "######" : "");
|
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`);
|
27
|
+
})
|
28
|
+
.options({
|
29
|
+
server: {
|
30
|
+
alias: "s",
|
31
|
+
describe: "Eik server address, if different from configuration file",
|
32
|
+
},
|
33
|
+
type: {
|
34
|
+
describe:
|
35
|
+
"Alter the alias type. Default is detected from eik.json. Valid values are `package`, `npm`, 'image', or `map` Eg. --type npm",
|
36
|
+
},
|
37
|
+
token: {
|
38
|
+
describe: "JWT used for authentication, if not using eik login",
|
39
|
+
alias: "t",
|
40
|
+
},
|
41
|
+
})
|
42
|
+
.example("eik alias my-app 1.0.0 1")
|
43
|
+
.example("eik alias my-app 1.7.3 1")
|
44
|
+
.example("eik alias my-app 6.3.1 6 --server https://assets.myeikserver.com")
|
45
|
+
.example("eik alias my-app 6.3.1 6 --token yourtoken")
|
46
|
+
.example("eik alias my-app 4.2.2 4 --type package");
|
69
47
|
};
|
70
48
|
|
71
|
-
export const handler =
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
const log = logger(spinner, debug);
|
76
|
-
let af;
|
77
|
-
|
78
|
-
try {
|
49
|
+
export const handler = commandHandler(
|
50
|
+
{ command, options: ["server", "type"] },
|
51
|
+
async (argv, log) => {
|
52
|
+
const { debug, server, type, ...rest } = argv;
|
79
53
|
const data = await new Alias({
|
80
54
|
type,
|
55
|
+
server,
|
81
56
|
logger: log,
|
82
|
-
...
|
57
|
+
...rest,
|
83
58
|
}).run();
|
84
59
|
|
85
60
|
// TODO: get rid of this rediculous formatter class idea that past me put here to irk present and future me.
|
86
61
|
// Smells like DRY silliness
|
87
|
-
af = new AliasFormatter(data);
|
62
|
+
const af = new AliasFormatter(data);
|
88
63
|
|
89
64
|
const createdOrUpdated = data.update ? "Updated" : "Created";
|
90
65
|
log.info(
|
91
66
|
`${createdOrUpdated} alias for "${type}" "${data.name}". ("${data.version}" => "v${data.alias}")`,
|
92
67
|
);
|
93
|
-
success = true;
|
94
|
-
} catch (err) {
|
95
|
-
log.warn(err.message);
|
96
|
-
}
|
97
68
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
af?.format(server);
|
102
|
-
} else {
|
103
|
-
process.exit(1);
|
104
|
-
}
|
105
|
-
};
|
69
|
+
af.format(server);
|
70
|
+
},
|
71
|
+
);
|
package/commands/init.js
CHANGED
@@ -1,115 +1,102 @@
|
|
1
1
|
import { join } from "path";
|
2
2
|
import fs from "fs";
|
3
|
-
import
|
4
|
-
import { logger } from "../utils/index.js";
|
3
|
+
import { commandHandler } from "../utils/command-handler.js";
|
5
4
|
|
6
5
|
const command = "init";
|
7
6
|
|
8
7
|
const aliases = ["i"];
|
9
8
|
|
10
|
-
const describe =
|
9
|
+
const describe = "Create an eik.json file";
|
11
10
|
|
11
|
+
/** @type {import('yargs').CommandBuilder} */
|
12
12
|
const builder = (yargs) => {
|
13
|
-
yargs
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
}
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
default: "",
|
36
|
-
},
|
37
|
-
});
|
13
|
+
return yargs
|
14
|
+
.options({
|
15
|
+
server: {
|
16
|
+
alias: "s",
|
17
|
+
describe: "Eik server address, if different from configuration file",
|
18
|
+
},
|
19
|
+
version: {
|
20
|
+
alias: "v",
|
21
|
+
describe:
|
22
|
+
'Specify the semver version field in "eik.json". Eg. --version 1.0.0',
|
23
|
+
default: "1.0.0",
|
24
|
+
},
|
25
|
+
name: {
|
26
|
+
alias: "n",
|
27
|
+
describe:
|
28
|
+
'Specify the app name field in "eik.json". Eg. --name my-great-app',
|
29
|
+
},
|
30
|
+
})
|
31
|
+
.example("eik init")
|
32
|
+
.example(
|
33
|
+
"eik init --server https://assets.myserver.com --version 2.0.0 --name my-app",
|
34
|
+
);
|
38
35
|
};
|
39
36
|
|
40
|
-
const handler = async (argv) => {
|
41
|
-
let { name, version } = argv;
|
42
|
-
const { server, cwd, debug } = argv;
|
43
|
-
const pathname = join(cwd, "./eik.json");
|
37
|
+
const handler = commandHandler({ command }, async (argv, log) => {
|
38
|
+
let { cwd, server, name, version } = argv;
|
44
39
|
|
45
|
-
const
|
46
|
-
|
40
|
+
const pathname = join(cwd, "./eik.json");
|
41
|
+
log.debug(`Checking for existing ${pathname}`);
|
47
42
|
|
43
|
+
let eikJsonExists = false;
|
48
44
|
try {
|
49
|
-
|
45
|
+
const st = fs.statSync(pathname);
|
46
|
+
if (st.isFile()) {
|
47
|
+
eikJsonExists = true;
|
48
|
+
}
|
49
|
+
} catch (err) {
|
50
|
+
// noop
|
51
|
+
}
|
52
|
+
if (eikJsonExists) {
|
53
|
+
throw new Error(
|
54
|
+
`An "eik.json" file already exists in directory. File will not be written`,
|
55
|
+
);
|
56
|
+
}
|
50
57
|
|
51
|
-
|
58
|
+
if (!name || !version || version === "1.0.0") {
|
59
|
+
log.debug("Looking for default from package.json");
|
52
60
|
try {
|
53
|
-
|
54
|
-
|
55
|
-
|
61
|
+
let packageJson = fs.readFileSync(join(cwd, "package.json"), "utf-8");
|
62
|
+
packageJson = JSON.parse(packageJson);
|
63
|
+
if (!name) {
|
64
|
+
name = packageJson.name;
|
65
|
+
log.debug(`Using ${name} from package.json as default name`);
|
56
66
|
}
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
if (eikJsonExists) {
|
61
|
-
throw new Error(
|
62
|
-
`An "eik.json" file already exists in directory. File will not be written`,
|
63
|
-
);
|
64
|
-
}
|
65
|
-
|
66
|
-
if (!name || !version || version === "1.0.0") {
|
67
|
-
log.debug("Looking for default from package.json");
|
68
|
-
try {
|
69
|
-
let packageJson = fs.readFileSync(join(cwd, "package.json"), "utf-8");
|
70
|
-
packageJson = JSON.parse(packageJson);
|
71
|
-
if (!name) {
|
72
|
-
name = packageJson.name;
|
73
|
-
log.debug(`Using ${name} from package.json as default name`);
|
74
|
-
}
|
75
|
-
if (!version || version === "1.0.0") {
|
76
|
-
version = packageJson.version;
|
77
|
-
log.debug(`Using ${version} from package.json as default version`);
|
78
|
-
}
|
79
|
-
} catch (e) {
|
80
|
-
// noop
|
67
|
+
if (!version || version === "1.0.0") {
|
68
|
+
version = packageJson.version;
|
69
|
+
log.debug(`Using ${version} from package.json as default version`);
|
81
70
|
}
|
82
|
-
}
|
83
|
-
|
71
|
+
} catch (e) {
|
72
|
+
// noop
|
84
73
|
}
|
74
|
+
} else {
|
75
|
+
log.debug(`Got ${name} and ${version}, skipping package.json`);
|
76
|
+
}
|
85
77
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
78
|
+
log.debug(`Writing to ${pathname}`);
|
79
|
+
|
80
|
+
const output = JSON.stringify(
|
81
|
+
{
|
82
|
+
$schema:
|
83
|
+
"https://raw.githubusercontent.com/eik-lib/common/main/lib/schemas/eikjson.schema.json",
|
84
|
+
name,
|
85
|
+
version,
|
86
|
+
server,
|
87
|
+
files: "./public",
|
88
|
+
"import-map": [],
|
89
|
+
},
|
90
|
+
null,
|
91
|
+
2,
|
92
|
+
);
|
93
|
+
fs.writeFileSync(pathname, output);
|
102
94
|
|
103
|
-
|
95
|
+
log.info(`Wrote to ${pathname}
|
104
96
|
|
105
97
|
${output}
|
106
98
|
|
107
99
|
Read more about configuring Eik on https://eik.dev/docs/reference/eik-json`);
|
108
|
-
|
109
|
-
log.warn(err.message);
|
110
|
-
}
|
111
|
-
spinner.text = "";
|
112
|
-
spinner.stopAndPersist();
|
113
|
-
};
|
100
|
+
});
|
114
101
|
|
115
102
|
export { command, aliases, describe, builder, handler };
|
package/commands/integrity.js
CHANGED
@@ -1,42 +1,34 @@
|
|
1
1
|
import { join } from "path";
|
2
|
-
import ora from "ora";
|
3
2
|
import Integrity from "../classes/integrity.js";
|
4
|
-
import { logger, getDefaults } from "../utils/index.js";
|
5
3
|
import json from "../utils/json/index.js";
|
4
|
+
import { commandHandler } from "../utils/command-handler.js";
|
6
5
|
|
7
6
|
export const command = "integrity [name] [version]";
|
8
7
|
|
9
8
|
export const aliases = ["int"];
|
10
9
|
|
11
|
-
export const describe =
|
10
|
+
export const describe = "Get file integrity information";
|
12
11
|
|
12
|
+
/** @type {import('yargs').CommandBuilder} */
|
13
13
|
export const builder = (yargs) => {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
});
|
24
|
-
|
25
|
-
yargs.example(`eik integrity`);
|
26
|
-
yargs.example(`eik integrity --debug`);
|
14
|
+
return yargs
|
15
|
+
.options({
|
16
|
+
server: {
|
17
|
+
alias: "s",
|
18
|
+
describe: "Eik server address, if different from configuration file",
|
19
|
+
},
|
20
|
+
})
|
21
|
+
.example("eik integrity")
|
22
|
+
.example("eik integrity --server https://assets.myserver.com");
|
27
23
|
};
|
28
24
|
|
29
|
-
export const handler =
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
const l = logger(spinner, debug);
|
34
|
-
// @ts-expect-error
|
35
|
-
const { name, version, server, out, type } = getDefaults(config || cwd);
|
25
|
+
export const handler = commandHandler(
|
26
|
+
{ command, options: ["server"] },
|
27
|
+
async (argv, log, spinner) => {
|
28
|
+
const { name, version, server, out, type, cwd, debug } = argv;
|
36
29
|
|
37
|
-
|
38
|
-
|
39
|
-
logger: l,
|
30
|
+
const integrity = await new Integrity({
|
31
|
+
logger: log,
|
40
32
|
name,
|
41
33
|
version,
|
42
34
|
server,
|
@@ -53,10 +45,5 @@ export const handler = async (argv) => {
|
|
53
45
|
);
|
54
46
|
process.stdout.write("\n");
|
55
47
|
}
|
56
|
-
}
|
57
|
-
|
58
|
-
spinner.stopAndPersist();
|
59
|
-
l.warn(err.message);
|
60
|
-
process.exit(1);
|
61
|
-
}
|
62
|
-
};
|
48
|
+
},
|
49
|
+
);
|
package/commands/login.js
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
import os from "os";
|
2
2
|
import readline from "readline";
|
3
|
-
import ora from "ora";
|
4
3
|
import Login from "../classes/login.js";
|
5
|
-
import { logger, getDefaults } from "../utils/index.js";
|
6
4
|
import json from "../utils/json/index.js";
|
5
|
+
import { commandHandler } from "../utils/command-handler.js";
|
7
6
|
|
8
7
|
const homedir = os.homedir();
|
9
8
|
|
@@ -11,72 +10,67 @@ export const command = "login";
|
|
11
10
|
|
12
11
|
export const aliases = [];
|
13
12
|
|
14
|
-
export const describe =
|
13
|
+
export const describe = "Log in to an Eik server";
|
15
14
|
|
15
|
+
/** @type {import('yargs').CommandBuilder} */
|
16
16
|
export const builder = (yargs) => {
|
17
|
-
yargs
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
}
|
30
|
-
|
31
|
-
|
32
|
-
describe: `Login access key. This is a passkey for a given user account and needs to be configured on the server. If this flag is not specifed, a prompt will be used to ask for the key to be input. Eg. --key ########`,
|
33
|
-
type: "string",
|
34
|
-
default: "",
|
35
|
-
},
|
36
|
-
});
|
17
|
+
return yargs
|
18
|
+
.options({
|
19
|
+
server: {
|
20
|
+
alias: "s",
|
21
|
+
describe: "Eik server address, if different from configuration file",
|
22
|
+
type: "string",
|
23
|
+
},
|
24
|
+
key: {
|
25
|
+
alias: "k",
|
26
|
+
describe: "Login access key",
|
27
|
+
type: "string",
|
28
|
+
},
|
29
|
+
})
|
30
|
+
.example("eik login --server https://assets.myserver.com")
|
31
|
+
.example("eik login --server https://assets.myserver.com --key yourkey");
|
37
32
|
};
|
38
33
|
|
39
|
-
export const handler =
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
let s = server;
|
44
|
-
let rl = null;
|
34
|
+
export const handler = commandHandler(
|
35
|
+
{ command, options: ["server"] },
|
36
|
+
async (argv, logger) => {
|
37
|
+
const { key, server } = argv;
|
45
38
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
output: process.stdout,
|
50
|
-
});
|
51
|
-
}
|
39
|
+
let k = key;
|
40
|
+
let s = server;
|
41
|
+
let rl = null;
|
52
42
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
// @ts-expect-error
|
58
|
-
resolve();
|
43
|
+
if (!s || !k) {
|
44
|
+
rl = readline.createInterface({
|
45
|
+
input: process.stdin,
|
46
|
+
output: process.stdout,
|
59
47
|
});
|
60
|
-
}
|
61
|
-
}
|
48
|
+
}
|
62
49
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
50
|
+
if (!s) {
|
51
|
+
await new Promise((resolve) => {
|
52
|
+
rl?.question("Enter Eik server address > ", (input) => {
|
53
|
+
s = input;
|
54
|
+
// @ts-expect-error
|
55
|
+
resolve();
|
56
|
+
});
|
69
57
|
});
|
70
|
-
}
|
71
|
-
}
|
58
|
+
}
|
72
59
|
|
73
|
-
|
60
|
+
if (!k) {
|
61
|
+
await new Promise((resolve) => {
|
62
|
+
rl?.question(`Enter login key for ${s} > `, (input) => {
|
63
|
+
k = input;
|
64
|
+
// @ts-expect-error
|
65
|
+
resolve();
|
66
|
+
});
|
67
|
+
});
|
68
|
+
}
|
74
69
|
|
75
|
-
|
70
|
+
if (rl) rl.close();
|
76
71
|
|
77
|
-
try {
|
78
72
|
const token = await new Login({
|
79
|
-
logger
|
73
|
+
logger,
|
80
74
|
key: k,
|
81
75
|
server: s,
|
82
76
|
}).run();
|
@@ -91,19 +85,6 @@ export const handler = async (argv) => {
|
|
91
85
|
meta.tokens = Array.from(tokens);
|
92
86
|
|
93
87
|
await json.write(meta, { cwd: homedir, filename: ".eikrc" });
|
94
|
-
success = true;
|
95
88
|
}
|
96
|
-
}
|
97
|
-
|
98
|
-
logger.warn(err.message);
|
99
|
-
}
|
100
|
-
|
101
|
-
if (success) {
|
102
|
-
spinner.text = "";
|
103
|
-
spinner.stopAndPersist();
|
104
|
-
} else {
|
105
|
-
spinner.text = "";
|
106
|
-
spinner.stopAndPersist();
|
107
|
-
process.exit(1);
|
108
|
-
}
|
109
|
-
};
|
89
|
+
},
|
90
|
+
);
|