vpm: replace `-` in author names with `_` (#5583)
parent
34ddc9240e
commit
d40334fe9d
|
@ -8,12 +8,12 @@ import vhelp
|
||||||
import v.vmod
|
import v.vmod
|
||||||
|
|
||||||
const (
|
const (
|
||||||
default_vpm_server_urls = ['https://vpm.best', 'https://vpm.vlang.io']
|
default_vpm_server_urls = ['https://vpm.best', 'https://vpm.vlang.io']
|
||||||
valid_vpm_commands = ['help', 'search', 'install', 'update', 'remove']
|
valid_vpm_commands = ['help', 'search', 'install', 'update', 'remove']
|
||||||
excluded_dirs = ['cache', 'vlib']
|
excluded_dirs = ['cache', 'vlib']
|
||||||
supported_vcs_systems = ['git', 'hg']
|
supported_vcs_systems = ['git', 'hg']
|
||||||
supported_vcs_folders = ['.git', '.hg']
|
supported_vcs_folders = ['.git', '.hg']
|
||||||
supported_vcs_update_cmds = {
|
supported_vcs_update_cmds = {
|
||||||
'git': 'git pull'
|
'git': 'git pull'
|
||||||
'hg': 'hg pull --update'
|
'hg': 'hg pull --update'
|
||||||
}
|
}
|
||||||
|
@ -66,10 +66,8 @@ fn main() {
|
||||||
manifest := vmod.from_file('./v.mod') or {
|
manifest := vmod.from_file('./v.mod') or {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
module_names = manifest.dependencies
|
module_names = manifest.dependencies
|
||||||
}
|
}
|
||||||
|
|
||||||
vpm_install(module_names)
|
vpm_install(module_names)
|
||||||
}
|
}
|
||||||
'update' {
|
'update' {
|
||||||
|
@ -121,7 +119,7 @@ fn vpm_search(keywords []string) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println('\nUse "v install author.module_name" to install the module')
|
println('\nUse "v install author_name.module_name" to install the module')
|
||||||
if index == 0 {
|
if index == 0 {
|
||||||
println('No module(s) found for "$joined"')
|
println('No module(s) found for "$joined"')
|
||||||
}
|
}
|
||||||
|
@ -141,7 +139,7 @@ fn vpm_install(module_names []string) {
|
||||||
name := n.trim_space()
|
name := n.trim_space()
|
||||||
mod := get_module_meta_info(name) or {
|
mod := get_module_meta_info(name) or {
|
||||||
errors++
|
errors++
|
||||||
println('Errors while retrieving meta data for module ${name}:')
|
println('Errors while retrieving meta data for module $name:')
|
||||||
println(err)
|
println(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -154,14 +152,15 @@ fn vpm_install(module_names []string) {
|
||||||
println('Skipping module "$name", since it uses an unsupported VCS {$vcs} .')
|
println('Skipping module "$name", since it uses an unsupported VCS {$vcs} .')
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
final_module_path := os.real_path(os.join_path(settings.vmodules_path,mod.name.replace('.', os.path_separator)))
|
mod_name_as_path := mod.name.replace('.', os.path_separator).replace('-', '_')
|
||||||
|
final_module_path := os.real_path(os.join_path(settings.vmodules_path, mod_name_as_path))
|
||||||
if os.exists(final_module_path) {
|
if os.exists(final_module_path) {
|
||||||
vpm_update([name])
|
vpm_update([name])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
println('Installing module "$name" from $mod.url to $final_module_path ...')
|
println('Installing module "$name" from $mod.url to $final_module_path ...')
|
||||||
vcs_install_cmd := supported_vcs_install_cmds[vcs]
|
vcs_install_cmd := supported_vcs_install_cmds[vcs]
|
||||||
cmd := '${vcs_install_cmd} "${mod.url}" "${final_module_path}"'
|
cmd := '$vcs_install_cmd "$mod.url" "$final_module_path"'
|
||||||
verbose_println(' command: $cmd')
|
verbose_println(' command: $cmd')
|
||||||
cmdres := os.exec(cmd) or {
|
cmdres := os.exec(cmd) or {
|
||||||
errors++
|
errors++
|
||||||
|
@ -173,8 +172,8 @@ fn vpm_install(module_names []string) {
|
||||||
if cmdres.exit_code != 0 {
|
if cmdres.exit_code != 0 {
|
||||||
errors++
|
errors++
|
||||||
println('Failed installing module "$name" to "$final_module_path" .')
|
println('Failed installing module "$name" to "$final_module_path" .')
|
||||||
verbose_println('Failed command: ${cmd}')
|
verbose_println('Failed command: $cmd')
|
||||||
verbose_println('Failed command output:\n${cmdres.output}')
|
verbose_println('Failed command output:\n$cmdres.output')
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
resolve_dependencies(name, final_module_path, module_names)
|
resolve_dependencies(name, final_module_path, module_names)
|
||||||
|
@ -206,18 +205,18 @@ fn vpm_update(m []string) {
|
||||||
}
|
}
|
||||||
vcs_cmd := supported_vcs_update_cmds[vcs[0]]
|
vcs_cmd := supported_vcs_update_cmds[vcs[0]]
|
||||||
verbose_println(' command: $vcs_cmd')
|
verbose_println(' command: $vcs_cmd')
|
||||||
vcs_res := os.exec('${vcs_cmd}') or {
|
vcs_res := os.exec('$vcs_cmd') or {
|
||||||
errors++
|
errors++
|
||||||
println('Could not update module "$name".')
|
println('Could not update module "$name".')
|
||||||
verbose_println('Error command: ${vcs_cmd}')
|
verbose_println('Error command: $vcs_cmd')
|
||||||
verbose_println('Error details:\n$err')
|
verbose_println('Error details:\n$err')
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if vcs_res.exit_code != 0 {
|
if vcs_res.exit_code != 0 {
|
||||||
errors++
|
errors++
|
||||||
println('Failed updating module "${name}".')
|
println('Failed updating module "$name".')
|
||||||
verbose_println('Failed command: ${vcs_cmd}')
|
verbose_println('Failed command: $vcs_cmd')
|
||||||
verbose_println('Failed details:\n${vcs_res.output}')
|
verbose_println('Failed details:\n$vcs_res.output')
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
resolve_dependencies(name, final_module_path, module_names)
|
resolve_dependencies(name, final_module_path, module_names)
|
||||||
|
@ -245,7 +244,7 @@ fn vpm_remove(module_names []string) {
|
||||||
os.rmdir_all(final_module_path)
|
os.rmdir_all(final_module_path)
|
||||||
// delete author directory if it is empty
|
// delete author directory if it is empty
|
||||||
author := name.split('.')[0]
|
author := name.split('.')[0]
|
||||||
author_dir := os.real_path(os.join_path(settings.vmodules_path,author))
|
author_dir := os.real_path(os.join_path(settings.vmodules_path, author))
|
||||||
if os.is_dir_empty(author_dir) {
|
if os.is_dir_empty(author_dir) {
|
||||||
verbose_println('removing author folder $author_dir')
|
verbose_println('removing author folder $author_dir')
|
||||||
os.rmdir(author_dir)
|
os.rmdir(author_dir)
|
||||||
|
@ -254,7 +253,8 @@ fn vpm_remove(module_names []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn valid_final_path_of_existing_module(name string) ?string {
|
fn valid_final_path_of_existing_module(name string) ?string {
|
||||||
name_of_vmodules_folder := os.join_path(settings.vmodules_path,name.replace('.', os.path_separator))
|
mod_name_as_path := name.replace('.', os.path_separator).replace('-', '_')
|
||||||
|
name_of_vmodules_folder := os.join_path(settings.vmodules_path, mod_name_as_path)
|
||||||
final_module_path := os.real_path(name_of_vmodules_folder)
|
final_module_path := os.real_path(name_of_vmodules_folder)
|
||||||
if !os.exists(final_module_path) {
|
if !os.exists(final_module_path) {
|
||||||
println('No module with name "$name" exists at $name_of_vmodules_folder')
|
println('No module with name "$name" exists at $name_of_vmodules_folder')
|
||||||
|
@ -287,7 +287,7 @@ fn vpm_help() {
|
||||||
fn vcs_used_in_dir(dir string) ?[]string {
|
fn vcs_used_in_dir(dir string) ?[]string {
|
||||||
mut vcs := []string{}
|
mut vcs := []string{}
|
||||||
for repo_subfolder in supported_vcs_folders {
|
for repo_subfolder in supported_vcs_folders {
|
||||||
checked_folder := os.real_path(os.join_path(dir,repo_subfolder))
|
checked_folder := os.real_path(os.join_path(dir, repo_subfolder))
|
||||||
if os.is_dir(checked_folder) {
|
if os.is_dir(checked_folder) {
|
||||||
vcs << repo_subfolder.replace('.', '')
|
vcs << repo_subfolder.replace('.', '')
|
||||||
}
|
}
|
||||||
|
@ -304,11 +304,11 @@ fn get_installed_modules() []string {
|
||||||
}
|
}
|
||||||
mut modules := []string{}
|
mut modules := []string{}
|
||||||
for dir in dirs {
|
for dir in dirs {
|
||||||
adir := os.join_path(settings.vmodules_path,dir)
|
adir := os.join_path(settings.vmodules_path, dir)
|
||||||
if dir in excluded_dirs || !os.is_dir(adir) {
|
if dir in excluded_dirs || !os.is_dir(adir) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if os.exists( os.join_path(adir, 'v.mod') ) && os.exists( os.join_path(adir, '.git', 'config') ){
|
if os.exists(os.join_path(adir, 'v.mod')) && os.exists(os.join_path(adir, '.git', 'config')) {
|
||||||
// an official vlang module with a short module name, like `vsl`, `ui` or `markdown`
|
// an official vlang module with a short module name, like `vsl`, `ui` or `markdown`
|
||||||
modules << dir
|
modules << dir
|
||||||
continue
|
continue
|
||||||
|
@ -318,7 +318,7 @@ fn get_installed_modules() []string {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for m in mods {
|
for m in mods {
|
||||||
vcs_used_in_dir(os.join_path(adir,m)) or {
|
vcs_used_in_dir(os.join_path(adir, m)) or {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
modules << '${author}.$m'
|
modules << '${author}.$m'
|
||||||
|
@ -366,7 +366,7 @@ fn get_all_modules() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_dependencies(name, module_path string, module_names []string) {
|
fn resolve_dependencies(name, module_path string, module_names []string) {
|
||||||
vmod_path := os.join_path(module_path,'v.mod')
|
vmod_path := os.join_path(module_path, 'v.mod')
|
||||||
if !os.exists(vmod_path) {
|
if !os.exists(vmod_path) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -382,7 +382,7 @@ fn resolve_dependencies(name, module_path string, module_names []string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if deps.len > 0 {
|
if deps.len > 0 {
|
||||||
println('Resolving ${deps.len} dependencies for module "$name"...')
|
println('Resolving $deps.len dependencies for module "$name"...')
|
||||||
verbose_println('Found dependencies: $deps')
|
verbose_println('Found dependencies: $deps')
|
||||||
vpm_install(deps)
|
vpm_install(deps)
|
||||||
}
|
}
|
||||||
|
@ -391,8 +391,8 @@ fn resolve_dependencies(name, module_path string, module_names []string) {
|
||||||
fn parse_vmod(data string) Vmod {
|
fn parse_vmod(data string) Vmod {
|
||||||
keys := ['name', 'version', 'deps']
|
keys := ['name', 'version', 'deps']
|
||||||
mut m := {
|
mut m := {
|
||||||
'name': '',
|
'name': ''
|
||||||
'version': '',
|
'version': ''
|
||||||
'deps': ''
|
'deps': ''
|
||||||
}
|
}
|
||||||
for key in keys {
|
for key in keys {
|
||||||
|
@ -400,7 +400,8 @@ fn parse_vmod(data string) Vmod {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
key_index += key.len + 1
|
key_index += key.len + 1
|
||||||
m[key] = data[key_index..data.index_after('\n', key_index)].trim_space().replace("'", '').replace('[', '').replace(']', '')
|
m[key] = data[key_index..data.index_after('\n', key_index)].trim_space().replace("'",
|
||||||
|
'').replace('[', '').replace(']', '')
|
||||||
}
|
}
|
||||||
mut vmod := Vmod{}
|
mut vmod := Vmod{}
|
||||||
vmod.name = m['name']
|
vmod.name = m['name']
|
||||||
|
@ -439,7 +440,7 @@ const (
|
||||||
|
|
||||||
fn init_settings() {
|
fn init_settings() {
|
||||||
mut s := &VpmSettings(0)
|
mut s := &VpmSettings(0)
|
||||||
unsafe{
|
unsafe {
|
||||||
s = settings
|
s = settings
|
||||||
}
|
}
|
||||||
s.is_help = '-h' in os.args || '--help' in os.args || 'help' in os.args
|
s.is_help = '-h' in os.args || '--help' in os.args || 'help' in os.args
|
||||||
|
@ -469,7 +470,8 @@ fn get_module_meta_info(name string) ?Mod {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if r.status_code != 200 {
|
if r.status_code != 200 {
|
||||||
errors << 'Skipping module "$name", since $server_url responded with $r.status_code http status code. Please try again later.'
|
errors <<
|
||||||
|
'Skipping module "$name", since $server_url responded with $r.status_code http status code. Please try again later.'
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
s := r.text
|
s := r.text
|
||||||
|
@ -478,7 +480,7 @@ fn get_module_meta_info(name string) ?Mod {
|
||||||
errors << s.trim_space().limit(100) + '...'
|
errors << s.trim_space().limit(100) + '...'
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mod := json.decode(Mod,s) or {
|
mod := json.decode(Mod, s) or {
|
||||||
errors << 'Skipping module "$name", since its information is not in json format.'
|
errors << 'Skipping module "$name", since its information is not in json format.'
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue