Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: installer #489

Merged
merged 28 commits into from
Jun 14, 2019
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c689f8e
Add installer
syumai Jun 9, 2019
38aea3d
Update README of deno_install
syumai Jun 9, 2019
8f78c9d
replace wget with fetch
bartlomieju Jun 13, 2019
c865227
more prompts, handle situation without shebang, prompt on overwrite
bartlomieju Jun 13, 2019
b64f0a6
better prompt
bartlomieju Jun 13, 2019
a8d0f63
even better prompt
bartlomieju Jun 13, 2019
8435486
lint & fmt
bartlomieju Jun 13, 2019
fd4d530
remove shebang parsing
bartlomieju Jun 13, 2019
4ff7fec
add help prompt
bartlomieju Jun 13, 2019
ffd3af8
fix arg parsing
bartlomieju Jun 13, 2019
0331109
add uninstall command
bartlomieju Jun 13, 2019
aabd191
don't show PATH prompt if dir in path
bartlomieju Jun 13, 2019
86a6e4e
install local scripts
bartlomieju Jun 14, 2019
86bd510
lint
bartlomieju Jun 14, 2019
1dda37e
add simple test case
bartlomieju Jun 14, 2019
0576c4c
lint
bartlomieju Jun 14, 2019
75ab128
reset CI
bartlomieju Jun 14, 2019
cbd05ea
add env permission
bartlomieju Jun 14, 2019
29d891e
add debug statement
bartlomieju Jun 14, 2019
25b9ae5
remove debug statement
bartlomieju Jun 14, 2019
84143ca
Add missing await
bartlomieju Jun 14, 2019
b7a703b
properly parse script flags
bartlomieju Jun 14, 2019
77c37db
add more tests for installer
bartlomieju Jun 14, 2019
81030d6
fix windows test
bartlomieju Jun 14, 2019
b77746c
update README
bartlomieju Jun 14, 2019
6137f6e
explicitly require name for installed executable
bartlomieju Jun 14, 2019
637a6f3
s/deno_install/deno_installer/
bartlomieju Jun 14, 2019
09ac618
remove installer/deno_installer.ts
bartlomieju Jun 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
add help prompt
  • Loading branch information
bartlomieju committed Jun 13, 2019
commit 4ff7fec6e42e50bfa8554b2245c8a508bfe0b319
52 changes: 38 additions & 14 deletions installer/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,20 @@ async function fetchModule(url: string): Promise<string> {
return decoder.decode(body);
}

async function main(): Promise<void> {
function showHelp(): void {
console.log(`USAGE:
deno https://deno.land/std/installer/mod.ts SCRIPT [FLAGS...]

ARGS:
SCRIPT URL of script to install
[FLAGS...] List of flags for script
`);
}

async function install(moduleUrl: string, flags: string[]): Promise<void> {
let installerDir = getInstallerDir();
createDirIfNotExists(installerDir);

const moduleUrl: string = args[1];
// TODO: handle local modules as well
if (!moduleUrl.startsWith("http")) {
throw new Error("Only remote modules are supported.");
Expand Down Expand Up @@ -169,7 +178,7 @@ async function main(): Promise<void> {

const grantedPermissions: Permission[] = [];

for (const flag of args.slice(2)) {
for (const flag of flags) {
const permission = getPermissionFromFlag(flag);
if (permission === Permission.Unknown) {
continue;
Expand All @@ -192,7 +201,7 @@ async function main(): Promise<void> {
await makeExecutable.status();
makeExecutable.close();

console.log(`✅ Successfully installed ${moduleName}.\n`);
console.log(`✅ Successfully installed ${moduleName}.\n`);
// TODO: display this prompt only if `installerDir` not in PATH
// TODO: add Windows version
console.log("ℹ️ Add ~/.deno/bin to PATH");
Expand All @@ -201,15 +210,30 @@ async function main(): Promise<void> {
);
}

// TODO: refactor
try {
main();
} catch (e) {
const err = e as Error;
if (err.message) {
console.log(err.message);
} else {
console.log(e);
async function main(): Promise<void> {
if (args.length < 2) {
return showHelp();
}

const moduleUrl = args[1];
const flags = args.slice(2);

if (moduleUrl == "-h" || "--help") {
return showHelp();
}

// TODO: refactor
try {
await install(moduleUrl, flags);
} catch (e) {
const err = e as Error;
if (err.message) {
console.log(err.message);
} else {
console.log(e);
}
exit(1);
}
exit(1);
}

main();