arcadible 0.0.1 → 0.1.1
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/README.md +3 -0
- package/bin/arc-default.js +57 -0
- package/bin/arc-deploy.js +117 -0
- package/bin/arc-init.js +196 -0
- package/bin/arc-inspect.js +107 -0
- package/bin/arc-login.js +127 -0
- package/bin/arc-logout.js +58 -0
- package/bin/arc-pack.js +126 -0
- package/bin/arc-validate.js +114 -0
- package/bin/arc-whoami.js +111 -0
- package/bin/arc.js +64 -0
- package/package.json +49 -1
- package/src/action/deploy/tool.js +11 -0
- package/src/action/deploy-git/git.js +23 -0
- package/src/action/deploy-git/release.js +74 -0
- package/src/action/deploy-git/tool.js +11 -0
- package/src/action/init/tool.js +44 -0
- package/src/action/inspect/tool.js +25 -0
- package/src/action/login/flow.js +94 -0
- package/src/action/login/tool.js +16 -0
- package/src/action/logout/tool.js +15 -0
- package/src/action/pack/tool.js +60 -0
- package/src/action/validate/tool.js +39 -0
- package/src/action/whoami/tool.js +15 -0
- package/src/api.js +39 -0
- package/src/cli/deploy.js +17 -0
- package/src/cli/index.js +25 -0
- package/src/cli/init.js +15 -0
- package/src/cli/inspect.js +15 -0
- package/src/cli/login.js +15 -0
- package/src/cli/logout.js +15 -0
- package/src/cli/pack.js +15 -0
- package/src/cli/validate.js +15 -0
- package/src/cli/whoami.js +15 -0
- package/src/config/audience.js +5 -0
- package/src/config/game.js +5 -0
- package/src/config/genre.js +22 -0
- package/src/config/html.js +27 -0
- package/src/config/input.js +14 -0
- package/src/config/orientation.js +14 -0
- package/src/config/uri.js +14 -0
- package/src/config/url.js +17 -0
- package/src/config/visibility.js +5 -0
- package/src/config/workflow.js +5 -0
- package/src/parser/manifest.js +46 -0
- package/src/parser/media.js +96 -0
- package/src/parser/project.js +55 -0
- package/src/parser/readme.js +144 -0
- package/src/prompt/project.js +10 -0
- package/src/prompt/template.js +37 -0
- package/src/schema/game.js +324 -0
- package/src/schema/workflow.js +119 -0
- package/src/user.js +91 -0
- package/src/util/dom.js +27 -0
- package/src/util/log.js +99 -0
- package/src/util/md.js +24 -0
- package/src/util/objs.js +28 -0
- package/src/util/os.js +24 -0
- package/src/util/output.js +46 -0
- package/src/util/promise.js +29 -0
- package/src/util/rc.js +41 -0
- package/src/util/request.js +62 -0
- package/src/util/schema.js +25 -0
- package/src/util/strs.js +21 -0
- package/src/util/time.js +79 -0
- package/src/util/zip.js +59 -0
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// [import]
|
|
5
|
+
|
|
6
|
+
const hideBin = require("yargs/helpers").hideBin;
|
|
7
|
+
const yargs = require("yargs/yargs");
|
|
8
|
+
|
|
9
|
+
// [import]
|
|
10
|
+
|
|
11
|
+
const pkg = require("../package.json");
|
|
12
|
+
|
|
13
|
+
// [declare]
|
|
14
|
+
|
|
15
|
+
const CMD = "arc";
|
|
16
|
+
|
|
17
|
+
// [function]
|
|
18
|
+
|
|
19
|
+
const parse = function (cli) {
|
|
20
|
+
const argv = cli.parse();
|
|
21
|
+
if (!argv._.length) {
|
|
22
|
+
cli.showHelp();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// [function]
|
|
27
|
+
|
|
28
|
+
const main = function (argv) {
|
|
29
|
+
return parse(
|
|
30
|
+
yargs(hideBin(argv))
|
|
31
|
+
.scriptName(CMD)
|
|
32
|
+
.usage("$0 <command> [options]")
|
|
33
|
+
.command("deploy", "Deploy to Arcadible")
|
|
34
|
+
.command("init", "Initialize a project")
|
|
35
|
+
.command("inspect", "Inspect project metadata")
|
|
36
|
+
.command("login", "Log in to Arcadible")
|
|
37
|
+
.command("logout", "Log out of Arcadible")
|
|
38
|
+
.command("pack", "Package for distribution")
|
|
39
|
+
.command("validate", "Validate workspace")
|
|
40
|
+
.command("whoami", "Show current account")
|
|
41
|
+
.help("help")
|
|
42
|
+
.alias("help", "h")
|
|
43
|
+
.version(pkg.version)
|
|
44
|
+
.alias("version", "v")
|
|
45
|
+
.strict(),
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// [main]
|
|
50
|
+
|
|
51
|
+
if (require.main === module) {
|
|
52
|
+
main(process.argv);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// [export]
|
|
56
|
+
|
|
57
|
+
module.exports = { main };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// [import]
|
|
5
|
+
|
|
6
|
+
const path = require("node:path");
|
|
7
|
+
|
|
8
|
+
// [import]
|
|
9
|
+
|
|
10
|
+
const hideBin = require("yargs/helpers").hideBin;
|
|
11
|
+
const yargs = require("yargs/yargs");
|
|
12
|
+
|
|
13
|
+
// [import]
|
|
14
|
+
|
|
15
|
+
const deploy = require("../src/cli/deploy");
|
|
16
|
+
const log = require("../src/util/log");
|
|
17
|
+
const output = require("../src/util/output");
|
|
18
|
+
const pkg = require("../package.json");
|
|
19
|
+
const rc = require("../src/util/rc");
|
|
20
|
+
|
|
21
|
+
// [use]
|
|
22
|
+
|
|
23
|
+
const findRc = rc.findRc;
|
|
24
|
+
const print = output.print;
|
|
25
|
+
const resolve = path.resolve;
|
|
26
|
+
|
|
27
|
+
// [declare]
|
|
28
|
+
|
|
29
|
+
const CMD = "arc";
|
|
30
|
+
const SUBCMD = "deploy";
|
|
31
|
+
|
|
32
|
+
// [define]
|
|
33
|
+
|
|
34
|
+
const conf = {
|
|
35
|
+
git: false,
|
|
36
|
+
json: false,
|
|
37
|
+
production: false,
|
|
38
|
+
quiet: false,
|
|
39
|
+
...findRc(CMD, SUBCMD, process.argv, ["--cwd", "-C"]),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// [function]
|
|
43
|
+
|
|
44
|
+
const start = function (argv) {
|
|
45
|
+
const json = argv.json;
|
|
46
|
+
return deploy({
|
|
47
|
+
git: argv.git,
|
|
48
|
+
pre: !argv.production,
|
|
49
|
+
preId: "rc",
|
|
50
|
+
quiet: argv.quiet,
|
|
51
|
+
root: resolve(process.cwd(), argv.cwd),
|
|
52
|
+
}).catch((ex) => {
|
|
53
|
+
const message = ex.message;
|
|
54
|
+
if (json) {
|
|
55
|
+
print({ error: { message } });
|
|
56
|
+
} else {
|
|
57
|
+
log.hd("Deploy aborted.");
|
|
58
|
+
log.p(message);
|
|
59
|
+
}
|
|
60
|
+
process.exit(1);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// [function]
|
|
65
|
+
|
|
66
|
+
const main = function (argv) {
|
|
67
|
+
return start(
|
|
68
|
+
yargs(hideBin(argv))
|
|
69
|
+
.scriptName(`${CMD} ${SUBCMD}`)
|
|
70
|
+
.usage("$0 [options]")
|
|
71
|
+
.option("production", {
|
|
72
|
+
alias: "p",
|
|
73
|
+
default: conf.production,
|
|
74
|
+
describe: "Deploy to production.",
|
|
75
|
+
type: "boolean",
|
|
76
|
+
})
|
|
77
|
+
.option("git", {
|
|
78
|
+
default: conf.git,
|
|
79
|
+
describe: "Deploy using Git.",
|
|
80
|
+
type: "boolean",
|
|
81
|
+
})
|
|
82
|
+
.option("json", {
|
|
83
|
+
alias: "j",
|
|
84
|
+
default: conf.json,
|
|
85
|
+
describe: "Format output as JSON.",
|
|
86
|
+
type: "boolean",
|
|
87
|
+
})
|
|
88
|
+
.option("quiet", {
|
|
89
|
+
alias: "q",
|
|
90
|
+
default: conf.quiet,
|
|
91
|
+
describe: "Output only errors.",
|
|
92
|
+
type: "boolean",
|
|
93
|
+
})
|
|
94
|
+
.option("cwd", {
|
|
95
|
+
alias: "C",
|
|
96
|
+
default: ".",
|
|
97
|
+
describe: "Set the working directory.",
|
|
98
|
+
type: "string",
|
|
99
|
+
})
|
|
100
|
+
.help("help")
|
|
101
|
+
.alias("help", "h")
|
|
102
|
+
.version(pkg.version)
|
|
103
|
+
.alias("version", "v")
|
|
104
|
+
.strict()
|
|
105
|
+
.parse(),
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// [main]
|
|
110
|
+
|
|
111
|
+
if (require.main === module) {
|
|
112
|
+
main(process.argv);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// [export]
|
|
116
|
+
|
|
117
|
+
module.exports = { main };
|
package/bin/arc-init.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// [import]
|
|
5
|
+
|
|
6
|
+
const path = require("node:path");
|
|
7
|
+
|
|
8
|
+
// [import]
|
|
9
|
+
|
|
10
|
+
const hideBin = require("yargs/helpers").hideBin;
|
|
11
|
+
const prompts = require("@inquirer/prompts");
|
|
12
|
+
const yargs = require("yargs/yargs");
|
|
13
|
+
|
|
14
|
+
// [import]
|
|
15
|
+
|
|
16
|
+
const cfgurl = require("../src/config/url");
|
|
17
|
+
const init = require("../src/cli/init");
|
|
18
|
+
const log = require("../src/util/log");
|
|
19
|
+
const output = require("../src/util/output");
|
|
20
|
+
const pkg = require("../package.json");
|
|
21
|
+
const project = require("../src/prompt/project");
|
|
22
|
+
const rc = require("../src/util/rc");
|
|
23
|
+
const template = require("../src/prompt/template");
|
|
24
|
+
|
|
25
|
+
// [use]
|
|
26
|
+
|
|
27
|
+
const findRc = rc.findRc;
|
|
28
|
+
const input = prompts.input;
|
|
29
|
+
const print = output.print;
|
|
30
|
+
const relative = path.relative;
|
|
31
|
+
const resolve = path.resolve;
|
|
32
|
+
const select = prompts.select;
|
|
33
|
+
|
|
34
|
+
// [declare]
|
|
35
|
+
|
|
36
|
+
const CMD = "arc";
|
|
37
|
+
const SUBCMD = "init";
|
|
38
|
+
|
|
39
|
+
// [define]
|
|
40
|
+
|
|
41
|
+
const conf = {
|
|
42
|
+
force: false,
|
|
43
|
+
json: false,
|
|
44
|
+
quiet: false,
|
|
45
|
+
yes: false,
|
|
46
|
+
...findRc(CMD, SUBCMD, process.argv, ["--cwd", "-C"]),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// [function]
|
|
50
|
+
|
|
51
|
+
const handler = function ({ json, quiet }) {
|
|
52
|
+
return {
|
|
53
|
+
onBegin() {
|
|
54
|
+
if (!json && !quiet) {
|
|
55
|
+
log.p("Initializing project...");
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
onInfo() {},
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// [function]
|
|
63
|
+
|
|
64
|
+
const start = function (argv) {
|
|
65
|
+
const json = argv.json;
|
|
66
|
+
const quiet = argv.quiet;
|
|
67
|
+
const root = resolve(process.cwd(), argv.cwd);
|
|
68
|
+
return init({
|
|
69
|
+
force: argv.force,
|
|
70
|
+
handler: handler({ json, quiet }),
|
|
71
|
+
project: argv.project,
|
|
72
|
+
root,
|
|
73
|
+
template: argv.template,
|
|
74
|
+
})
|
|
75
|
+
.then((data) => {
|
|
76
|
+
const dir = relative(root, data.path);
|
|
77
|
+
if (json) {
|
|
78
|
+
print({ project: data });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (!quiet) {
|
|
82
|
+
log.hsnl("Initialized.");
|
|
83
|
+
log.h("Next steps:");
|
|
84
|
+
log.pnl(
|
|
85
|
+
[data.path === root ? null : `cd ${dir}`, "npm install", "arc deploy"]
|
|
86
|
+
.filter(Boolean)
|
|
87
|
+
.join(" && "),
|
|
88
|
+
);
|
|
89
|
+
log.h("Getting started:");
|
|
90
|
+
log.p(cfgurl.GETTING_STARTED);
|
|
91
|
+
}
|
|
92
|
+
// degit sometimes hangs
|
|
93
|
+
process.exit(0);
|
|
94
|
+
})
|
|
95
|
+
.catch((ex) => {
|
|
96
|
+
const message = ex.message;
|
|
97
|
+
if (json) {
|
|
98
|
+
print({ error: { message } });
|
|
99
|
+
} else {
|
|
100
|
+
log.hd("Init aborted.");
|
|
101
|
+
log.p(message);
|
|
102
|
+
}
|
|
103
|
+
process.exit(1);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// [function]
|
|
108
|
+
|
|
109
|
+
const prompt = async function ({ yes, ...argv }) {
|
|
110
|
+
const opts = { ...argv };
|
|
111
|
+
if (yes) {
|
|
112
|
+
opts.project ??= project.input.default;
|
|
113
|
+
opts.template ??= template.select.default;
|
|
114
|
+
return opts;
|
|
115
|
+
}
|
|
116
|
+
if (!argv.project) {
|
|
117
|
+
opts.project = await input(project.input);
|
|
118
|
+
}
|
|
119
|
+
if (!argv.template) {
|
|
120
|
+
opts.template = await select(template.select);
|
|
121
|
+
}
|
|
122
|
+
return opts;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// [function]
|
|
126
|
+
|
|
127
|
+
const main = function (argv) {
|
|
128
|
+
return prompt(
|
|
129
|
+
yargs(hideBin(argv))
|
|
130
|
+
.scriptName(`${CMD} ${SUBCMD}`)
|
|
131
|
+
.usage("$0 <project> [options]")
|
|
132
|
+
.command("$0 <project>", false, (cli) =>
|
|
133
|
+
cli.positional("project", {
|
|
134
|
+
describe: "Set the project directory.",
|
|
135
|
+
type: "string",
|
|
136
|
+
}),
|
|
137
|
+
)
|
|
138
|
+
.option("template", {
|
|
139
|
+
alias: "t",
|
|
140
|
+
describe: "Select a project template.",
|
|
141
|
+
type: "string",
|
|
142
|
+
})
|
|
143
|
+
.option("yes", {
|
|
144
|
+
alias: "y",
|
|
145
|
+
default: conf.yes,
|
|
146
|
+
describe: "Answer prompts using default values.",
|
|
147
|
+
type: "boolean",
|
|
148
|
+
})
|
|
149
|
+
.option("force", {
|
|
150
|
+
alias: "f",
|
|
151
|
+
default: conf.force,
|
|
152
|
+
describe: "Overwrite an existing directory.",
|
|
153
|
+
type: "boolean",
|
|
154
|
+
})
|
|
155
|
+
.option("json", {
|
|
156
|
+
alias: "j",
|
|
157
|
+
default: conf.json,
|
|
158
|
+
describe: "Format output as JSON.",
|
|
159
|
+
type: "boolean",
|
|
160
|
+
})
|
|
161
|
+
.option("quiet", {
|
|
162
|
+
alias: "q",
|
|
163
|
+
default: conf.quiet,
|
|
164
|
+
describe: "Output only errors.",
|
|
165
|
+
type: "boolean",
|
|
166
|
+
})
|
|
167
|
+
.option("cwd", {
|
|
168
|
+
alias: "C",
|
|
169
|
+
default: ".",
|
|
170
|
+
describe: "Set the working directory.",
|
|
171
|
+
type: "string",
|
|
172
|
+
})
|
|
173
|
+
.help("help")
|
|
174
|
+
.alias("help", "h")
|
|
175
|
+
.version(pkg.version)
|
|
176
|
+
.alias("version", "v")
|
|
177
|
+
.strict()
|
|
178
|
+
.parse(),
|
|
179
|
+
)
|
|
180
|
+
.then(start)
|
|
181
|
+
.catch((ex) => {
|
|
182
|
+
if (ex && ex.name === "ExitPromptError") {
|
|
183
|
+
process.exit(0);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// [main]
|
|
189
|
+
|
|
190
|
+
if (require.main === module) {
|
|
191
|
+
main(process.argv);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// [export]
|
|
195
|
+
|
|
196
|
+
module.exports = { main };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// [import]
|
|
5
|
+
|
|
6
|
+
const path = require("node:path");
|
|
7
|
+
|
|
8
|
+
// [import]
|
|
9
|
+
|
|
10
|
+
const hideBin = require("yargs/helpers").hideBin;
|
|
11
|
+
const yargs = require("yargs/yargs");
|
|
12
|
+
|
|
13
|
+
// [import]
|
|
14
|
+
|
|
15
|
+
const inspect = require("../src/cli/inspect");
|
|
16
|
+
const log = require("../src/util/log");
|
|
17
|
+
const output = require("../src/util/output");
|
|
18
|
+
const pkg = require("../package.json");
|
|
19
|
+
const rc = require("../src/util/rc");
|
|
20
|
+
|
|
21
|
+
// [use]
|
|
22
|
+
|
|
23
|
+
const findRc = rc.findRc;
|
|
24
|
+
const print = output.print;
|
|
25
|
+
const resolve = path.resolve;
|
|
26
|
+
|
|
27
|
+
// [declare]
|
|
28
|
+
|
|
29
|
+
const CMD = "arc";
|
|
30
|
+
const SUBCMD = "inspect";
|
|
31
|
+
|
|
32
|
+
// [define]
|
|
33
|
+
|
|
34
|
+
const conf = {
|
|
35
|
+
json: false,
|
|
36
|
+
key: "",
|
|
37
|
+
...findRc(CMD, SUBCMD, process.argv, ["--cwd", "-C"]),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// [function]
|
|
41
|
+
|
|
42
|
+
const start = function (argv) {
|
|
43
|
+
const json = argv.json;
|
|
44
|
+
const key = argv.key;
|
|
45
|
+
return inspect({
|
|
46
|
+
key,
|
|
47
|
+
root: resolve(process.cwd(), argv.cwd),
|
|
48
|
+
})
|
|
49
|
+
.then((data) => {
|
|
50
|
+
print(data, { key, toml: !json });
|
|
51
|
+
})
|
|
52
|
+
.catch((ex) => {
|
|
53
|
+
const message = ex.message;
|
|
54
|
+
if (json) {
|
|
55
|
+
print({ error: { message } });
|
|
56
|
+
} else {
|
|
57
|
+
log.hd("Inspect aborted.");
|
|
58
|
+
log.p(message);
|
|
59
|
+
}
|
|
60
|
+
process.exit(1);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// [function]
|
|
65
|
+
|
|
66
|
+
const main = function (argv) {
|
|
67
|
+
return start(
|
|
68
|
+
yargs(hideBin(argv))
|
|
69
|
+
.scriptName(`${CMD} ${SUBCMD}`)
|
|
70
|
+
.usage("$0 [key] [options]")
|
|
71
|
+
.command("$0 [key]", false, (cli) =>
|
|
72
|
+
cli.positional("key", {
|
|
73
|
+
default: conf.key,
|
|
74
|
+
describe: "Select a metadata key.",
|
|
75
|
+
type: "string",
|
|
76
|
+
}),
|
|
77
|
+
)
|
|
78
|
+
.option("json", {
|
|
79
|
+
alias: "j",
|
|
80
|
+
default: conf.json,
|
|
81
|
+
describe: "Format output as JSON.",
|
|
82
|
+
type: "boolean",
|
|
83
|
+
})
|
|
84
|
+
.option("cwd", {
|
|
85
|
+
alias: "C",
|
|
86
|
+
default: ".",
|
|
87
|
+
describe: "Set the working directory.",
|
|
88
|
+
type: "string",
|
|
89
|
+
})
|
|
90
|
+
.help("help")
|
|
91
|
+
.alias("help", "h")
|
|
92
|
+
.version(pkg.version)
|
|
93
|
+
.alias("version", "v")
|
|
94
|
+
.strict()
|
|
95
|
+
.parse(),
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// [main]
|
|
100
|
+
|
|
101
|
+
if (require.main === module) {
|
|
102
|
+
main(process.argv);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// [export]
|
|
106
|
+
|
|
107
|
+
module.exports = { main };
|
package/bin/arc-login.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// [import]
|
|
5
|
+
|
|
6
|
+
const hideBin = require("yargs/helpers").hideBin;
|
|
7
|
+
const open = require("open");
|
|
8
|
+
const yargs = require("yargs/yargs");
|
|
9
|
+
|
|
10
|
+
// [import]
|
|
11
|
+
|
|
12
|
+
const log = require("../src/util/log");
|
|
13
|
+
const login = require("../src/cli/login");
|
|
14
|
+
const pkg = require("../package.json");
|
|
15
|
+
const rc = require("../src/util/rc");
|
|
16
|
+
|
|
17
|
+
// [use]
|
|
18
|
+
|
|
19
|
+
const findRc = rc.findRc;
|
|
20
|
+
|
|
21
|
+
// [declare]
|
|
22
|
+
|
|
23
|
+
const CMD = "arc";
|
|
24
|
+
const SUBCMD = "login";
|
|
25
|
+
|
|
26
|
+
// [define]
|
|
27
|
+
|
|
28
|
+
const conf = {
|
|
29
|
+
browser: true,
|
|
30
|
+
...findRc(CMD, SUBCMD, process.argv, ["--cwd", "-C"]),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// [function]
|
|
34
|
+
|
|
35
|
+
const onEnter = function (fn) {
|
|
36
|
+
const stdin = process.stdin;
|
|
37
|
+
if (!stdin.isTTY) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const cleanup = function () {
|
|
41
|
+
stdin.setRawMode(false);
|
|
42
|
+
stdin.pause();
|
|
43
|
+
stdin.removeAllListeners("data");
|
|
44
|
+
};
|
|
45
|
+
stdin.setRawMode(true);
|
|
46
|
+
stdin.resume();
|
|
47
|
+
stdin.once("data", (buf) => {
|
|
48
|
+
cleanup();
|
|
49
|
+
if (buf[0] === 3) {
|
|
50
|
+
process.kill(process.pid, "SIGINT");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (buf[0] === 13) {
|
|
54
|
+
fn();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// [function]
|
|
60
|
+
|
|
61
|
+
const handler = function ({ browser }) {
|
|
62
|
+
return {
|
|
63
|
+
onCreated({ code, url }) {
|
|
64
|
+
log.p(url);
|
|
65
|
+
log.h(code.toUpperCase());
|
|
66
|
+
if (browser) {
|
|
67
|
+
log.p("");
|
|
68
|
+
log.p("Press Enter to open the URL.");
|
|
69
|
+
onEnter(() => {
|
|
70
|
+
open(url).catch(() => {});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
onPoll() {},
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// [function]
|
|
79
|
+
|
|
80
|
+
const start = function (argv) {
|
|
81
|
+
const browser = argv.browser;
|
|
82
|
+
log.pnl("Starting login...");
|
|
83
|
+
return login({ handler: handler({ browser }) })
|
|
84
|
+
.then(({ profile }) => {
|
|
85
|
+
process.stdin.pause();
|
|
86
|
+
log.p("");
|
|
87
|
+
log.p("Logged in as:");
|
|
88
|
+
log.hs(profile.display_name);
|
|
89
|
+
})
|
|
90
|
+
.catch((ex) => {
|
|
91
|
+
process.stdin.pause();
|
|
92
|
+
log.hd("Login aborted.");
|
|
93
|
+
log.p(ex.message);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// [function]
|
|
99
|
+
|
|
100
|
+
const main = function (argv) {
|
|
101
|
+
return start(
|
|
102
|
+
yargs(hideBin(argv))
|
|
103
|
+
.scriptName(`${CMD} ${SUBCMD}`)
|
|
104
|
+
.usage("$0 [options]")
|
|
105
|
+
.option("browser", {
|
|
106
|
+
default: conf.browser,
|
|
107
|
+
describe: "Open a web browser automatically.",
|
|
108
|
+
type: "boolean",
|
|
109
|
+
})
|
|
110
|
+
.help("help")
|
|
111
|
+
.alias("help", "h")
|
|
112
|
+
.version(pkg.version)
|
|
113
|
+
.alias("version", "v")
|
|
114
|
+
.strict()
|
|
115
|
+
.parse(),
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// [main]
|
|
120
|
+
|
|
121
|
+
if (require.main === module) {
|
|
122
|
+
main(process.argv);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// [export]
|
|
126
|
+
|
|
127
|
+
module.exports = { main };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// [import]
|
|
5
|
+
|
|
6
|
+
const hideBin = require("yargs/helpers").hideBin;
|
|
7
|
+
const yargs = require("yargs/yargs");
|
|
8
|
+
|
|
9
|
+
// [import]
|
|
10
|
+
|
|
11
|
+
const log = require("../src/util/log");
|
|
12
|
+
const logout = require("../src/cli/logout");
|
|
13
|
+
const pkg = require("../package.json");
|
|
14
|
+
|
|
15
|
+
// [declare]
|
|
16
|
+
|
|
17
|
+
const CMD = "arc";
|
|
18
|
+
const SUBCMD = "logout";
|
|
19
|
+
|
|
20
|
+
// [function]
|
|
21
|
+
|
|
22
|
+
const start = function () {
|
|
23
|
+
return logout()
|
|
24
|
+
.then(() => {
|
|
25
|
+
log.hs("Logged out.");
|
|
26
|
+
})
|
|
27
|
+
.catch((ex) => {
|
|
28
|
+
log.hd("Logout aborted.");
|
|
29
|
+
log.p(ex.message);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// [function]
|
|
35
|
+
|
|
36
|
+
const main = function (argv) {
|
|
37
|
+
return start(
|
|
38
|
+
yargs(hideBin(argv))
|
|
39
|
+
.scriptName(`${CMD} ${SUBCMD}`)
|
|
40
|
+
.usage("$0 [options]")
|
|
41
|
+
.help("help")
|
|
42
|
+
.alias("help", "h")
|
|
43
|
+
.version(pkg.version)
|
|
44
|
+
.alias("version", "v")
|
|
45
|
+
.strict()
|
|
46
|
+
.parse(),
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// [main]
|
|
51
|
+
|
|
52
|
+
if (require.main === module) {
|
|
53
|
+
main(process.argv);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// [export]
|
|
57
|
+
|
|
58
|
+
module.exports = { main };
|