Created
February 1, 2020 17:45
-
-
Save imaginamundo/99207abf9a638f1021501f622ad0f27b to your computer and use it in GitHub Desktop.
Deno read import map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { parse } from 'https://deno.land/std/flags/mod.ts'; | |
import readFileHelp from './read_file_help.ts'; | |
import readFileList from './read_file_list.ts'; | |
import readFileOutdated from './read_file_outdated.ts'; | |
import readFileUpdate from './read_file_update.ts'; | |
const args = parse(Deno.args); | |
let arg; | |
if (args.h || args.help) { | |
arg = 'help'; | |
} else { | |
arg = args._[0]; | |
} | |
const possibleFunctions = { | |
update: readFileUpdate, | |
outdated: readFileOutdated, | |
ls: readFileList, | |
help: readFileHelp | |
} | |
const currentFunction = possibleFunctions[arg]; | |
if (arg) { | |
currentFunction(); | |
} else { | |
console.log('Command not found, use -h or --help'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { yellow, bold } from 'https://deno.land/std/fmt/colors.ts'; | |
let command = 'deno read_file'; | |
export default function readFileHelp() { | |
return console.log(` | |
To verify outdated modules on Import Map, type: | |
${ bold(yellow(`${ command } importmap.json outdated`)) } | |
To update a Import Map, type: | |
${ bold(yellow(`${ command } importmap.json update`)) } | |
To list modules on Import Map, type: | |
${ bold(yellow(`${ command } importmap.json ls`)) } | |
`); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { dim, bold } from 'https://deno.land/std/fmt/colors.ts'; | |
import getImportMap from './get_import_map.ts'; | |
export default async function readFileList() { | |
const importmap = await getImportMap(); | |
const modules = Object.entries(importmap).map(([ key, value ]) => { | |
return `• ${ bold(key) } \t ${ bold('version:') } ${ dim('unknow') } \t ${ value }`; | |
}); | |
console.log('\n'); | |
console.log(modules.join('\n')); | |
console.log('\n'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import getImportMap from './get_import_map.ts'; | |
export default async function readFileVerify() { | |
const modules = { | |
Updated: [], | |
Outdated: [] | |
}; | |
const importmap = await getImportMap(); | |
Object.entries(importmap).forEach(([ module, url ], index) => { | |
// Demo logic to separate on table | |
if (index % 2 === 0) { | |
modules.Updated.push(module); | |
} else { | |
modules.Outdated.push(module); | |
} | |
}); | |
return console.table([ | |
modules | |
], [ 'Updated', 'Outdated' ]); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { red, green, bold } from 'https://deno.land/std/fmt/colors.ts'; | |
import { encode } from 'https://deno.land/std/strings/mod.ts'; | |
import { TextProtoReader } from 'https://deno.land/std/textproto/mod.ts'; | |
import { BufReader } from 'https://deno.land/std/io/bufio.ts'; | |
import getImportMap from './get_import_map.ts'; | |
export default async function readFileUpdate() { | |
const importmap = await getImportMap(); | |
const outdatedModules = [ Object.keys(importmap)[0] ]; | |
if (outdatedModules.length) { | |
console.log( | |
` | |
Do you want to update the module${ !outdatedModules.length ? 's' : '' } (Y/n): | |
${ outdatedModules.join(', ') } | |
` | |
); | |
const tpr = new TextProtoReader(new BufReader(Deno.stdin)); | |
while (true) { | |
await Deno.stdout.write(encode('> ')); | |
const line = await tpr.readLine(); | |
if (line === 'n' || line === 'no') { | |
console.log( | |
` | |
${ bold(red(`No updating module${ !outdatedModules.length ? 's' : '' }:`)) } | |
${ outdatedModules.join(', ') } | |
` | |
); | |
break; | |
} else { | |
console.log( | |
` | |
${ bold(green(`Updating module${ !outdatedModules.length ? 's' : '' }:`)) } | |
${ outdatedModules.join(', ') } | |
` | |
); | |
break; | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment