5 changed files with 1171 additions and 37 deletions
-
6package.json
-
91src/commands/clone.ts
-
2src/commands/wallhaven/wallhaven.ts
-
37src/extensions/clone.ts
-
1072yarn.lock
@ -0,0 +1,91 @@ |
|||
import { GluegunToolbox } from 'gluegun' |
|||
|
|||
module.exports = { |
|||
name: 'clone', |
|||
alias: ['c'], |
|||
run: async (toolbox: GluegunToolbox) => { |
|||
const { |
|||
parameters, |
|||
print: { info, error, spin }, |
|||
utils: { verboseDebug }, |
|||
prompt: { ask }, |
|||
clone: { getWorkScopes, cloneUrlInScope, getCloneDirectory } |
|||
} = toolbox |
|||
|
|||
const showHelp = () => { |
|||
info('Usage: nbx clone [url]') |
|||
info('') |
|||
info('Options') |
|||
info(' -s, --scope Scope') |
|||
info(' -t, --type Type (git, expr, doc)') |
|||
info(' -h, --help Output usage information') |
|||
info(' -v, --verbose Verbose output') |
|||
} |
|||
const o = parameters.options |
|||
let props = { |
|||
url: parameters.first, |
|||
scope: o.s || o.scope, |
|||
type: o.t || o.type, |
|||
help: Boolean(o.h || o.help), |
|||
verbose: Boolean(o.v || o.verbose) |
|||
} |
|||
|
|||
verboseDebug(props, 'Params') |
|||
|
|||
if (props.help) { |
|||
showHelp() |
|||
return |
|||
} |
|||
|
|||
if (!props.url) { |
|||
error('You must provide a url to clone\n') |
|||
showHelp() |
|||
process.exit(0) |
|||
} |
|||
|
|||
let questions = [] |
|||
|
|||
if (!props.type) { |
|||
questions = [ |
|||
...questions, |
|||
{ |
|||
choices: ['git', 'expr', 'docs'], |
|||
default: 'git', |
|||
name: 'type', |
|||
message: 'Witch type of project are you gonna clone ?', |
|||
type: 'list' |
|||
} |
|||
] |
|||
} |
|||
if (!props.scope) { |
|||
const workScopes = await getWorkScopes() |
|||
questions = [ |
|||
...questions, |
|||
{ |
|||
choices: ['perso', 'fac', ...workScopes], |
|||
default: 'perso', |
|||
name: 'scope', |
|||
message: 'In what scope do you want to clone into', |
|||
type: 'list' |
|||
} |
|||
] |
|||
} |
|||
|
|||
if (questions.length) { |
|||
const res = await ask(questions) |
|||
props = { |
|||
...props, |
|||
...res |
|||
} |
|||
} |
|||
verboseDebug(props, 'Params') |
|||
const dir = await getCloneDirectory(props.scope, props.type); |
|||
const spinner = spin(`Cloning into ${dir}`) |
|||
try { |
|||
const path = await cloneUrlInScope(props.url, dir) |
|||
spinner.succeed('Cloned into ' + path); |
|||
} catch (e) { |
|||
spinner.fail(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
import { GluegunToolbox } from 'gluegun' |
|||
|
|||
module.exports = (toolbox: GluegunToolbox) => { |
|||
|
|||
const getWorkScopes = async (): Promise<string[]> => { |
|||
const files = await toolbox.filesystem.list(toolbox.filesystem.homedir() + toolbox.filesystem.separator + 'work'); |
|||
return files || []; |
|||
} |
|||
|
|||
const cloneUrlInScope = async (gitUrl: string, directory: string): Promise<string> => { |
|||
const folderBefore = (await toolbox.filesystem.list(directory)) as string[]; |
|||
|
|||
await toolbox.system.exec(`git clone ${gitUrl}`, { cwd: directory }) |
|||
|
|||
const folderAfter = (await toolbox.filesystem.list(directory)) as string[]; |
|||
|
|||
const newFolder = folderAfter.filter(val => !folderBefore.includes(val)); |
|||
toolbox.utils.verboseDebug(newFolder, 'newFolder ?'); |
|||
return directory + toolbox.filesystem.separator + newFolder[0]; |
|||
} |
|||
|
|||
const getCloneDirectory = async (scope: string, type: string): Promise<string> => { |
|||
const endPart = scope + toolbox.filesystem.separator + type; |
|||
let directory = toolbox.filesystem.homedir() + toolbox.filesystem.separator + 'work' + toolbox.filesystem.separator + endPart; |
|||
if (['fac', 'perso'].includes(scope)) { |
|||
directory = toolbox.filesystem.homedir() + scope + toolbox.filesystem.separator + endPart; |
|||
} |
|||
return directory; |
|||
} |
|||
|
|||
|
|||
toolbox.clone = { |
|||
getWorkScopes, |
|||
cloneUrlInScope, |
|||
getCloneDirectory, |
|||
} |
|||
} |
|||
1072
yarn.lock
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue