@ -22,7 +22,8 @@ const requiredManifestKeys = [ 'name', 'version', 'description', 'author' ];
const ErrorTypes = Object . freeze ( {
ADDON _ALREADY _INSTALLED : 'ADDON_ALREADY_INSTALLED' ,
ADDON _ALREADY _INSTALLING : 'ADDON_ALREADY_INSTALLING' ,
DIRECTORY _ALREADY _EXISTS : 'DIRECTORY_ALREADY_EXISTS'
} ) ;
/ * *
@ -338,6 +339,13 @@ export default class AddonManager extends Events {
const ignore = existsSync ( ignorePath ) ? readFileSync ( ignorePath , 'utf-8' ) . trim ( ) . split ( /\r?\n/ ) : [ ] ;
const files = readdirSync ( this . dir ) . sort ( this . _sortBuiltins ) ;
for ( const filename of files ) {
/ * *
* Remove any leftover addons that were being installed .
* /
if ( filename . startsWith ( '__installing__' ) ) {
await removeDirRecursive ( resolve ( this . dir , filename ) ) ;
continue ;
}
addonId = filename ;
// If it's a file or listed in .vzignore, skip it
if ( lstatSync ( join ( this . dir , addonId ) ) . isFile ( ) || ignore . includes ( addonId ) ) {
@ -546,23 +554,17 @@ export default class AddonManager extends Events {
* /
async install ( addonId ) {
try {
console . log ( addonId ) ;
let git ;
if ( vizality . manager . community [ toPlural ( this . type ) ] . has ( addonId ) ) {
console . log ( 'uh' ) ;
( { git } = vizality . manager . community [ toPlural ( this . type ) ] . get ( addonId ) ) ;
}
console . log ( 'okay' ) ;
if ( ! new RegExp ( /^(((https?:\/\/)(((([a-zA-Z0-9][a-zA-Z0-9\-_]{1,252})\.){1,8}[a-zA-Z]{2,63})\/))|((ssh:\/\/)?git@)(((([a-zA-Z0-9][a-zA-Z0-9\-_]{1,252})\.){1,8}[a-zA-Z]{2,63})(:)))([a-zA-Z0-9][a-zA-Z0-9_-]{1,36})(\/)([a-zA-Z0-9][a-zA-Z0-9_-]{1,36})((\.git)?)$/ ) . test ( git || addonId ) ) {
console . log ( 'yes' ) ;
throw new Error ( 'You must provide a valid GitHub repository URL or an addon ID from https://github.com/vizality-community!' ) ;
} else {
console . log ( 'no' ) ;
git = addonId ;
} else if ( vizality . manager . community . plugins . has ( addonId ) ) {
git = ` https://github.com/vizality-community/ ${ addonId } ` ;
}
console . log ( 'here' , git ) ;
/ * *
* The URL must end in git to get processed by isomorphic - git below .
* /
@ -573,8 +575,6 @@ export default class AddonManager extends Events {
addonId = git . split ( '.git' ) [ 0 ] . split ( '/' ) [ git . split ( '.git' ) [ 0 ] . split ( '/' ) . length - 1 ] ;
addonId = toKebabCase ( addonId ) ;
console . log ( git ) ;
console . log ( addonId ) ;
if ( this . isInstalled ( addonId ) ) {
throw {
name : ErrorTypes . ADDON _ALREADY _INSTALLED ,
@ -584,12 +584,22 @@ export default class AddonManager extends Events {
} ;
}
if ( existsSync ( join ( this . dir , ` __installing__ ${ addonId } ` ) ) && lstatSync ( join ( this . dir , addonId ) ) ? . isDirectory ( ) ) {
throw new Error ( ` ${ toTitleCase ( this . type ) } " ${ addonId } " looks like it's already being installed! ` ) ;
if ( existsSync ( join ( this . dir , ` __installing__ ${ addonId } ` ) ) && lstatSync ( join ( this . dir , ` __installing__ ${ addonId } ` ) ) ? . isDirectory ( ) ) {
throw {
name : ErrorTypes . ADDON _ALREADY _INSTALLING ,
message : Messages . VIZALITY _ADDON _ALREADY _INSTALLING _DESC . format ( { type : this . type , addonId } ) ,
stack : ` \n ${ ( new Error ( ) ) . stack . replace ( 'Error\n' , '' ) } ` ,
addonId
} ;
}
if ( existsSync ( join ( this . dir , addonId ) ) && lstatSync ( join ( this . dir , addonId ) ) ? . isDirectory ( ) ) {
throw new Error ( ` ${ toTitleCase ( this . type ) } directory " ${ addonId } " already exists! ` ) ;
throw {
name : ErrorTypes . DIRECTORY _ALREADY _EXISTS ,
message : Messages . VIZALITY _ADDON _DIRECTORY _ALREADY _EXISTS _DESC . format ( { type : this . type , addonId } ) ,
stack : ` \n ${ ( new Error ( ) ) . stack . replace ( 'Error\n' , '' ) } ` ,
addonId
} ;
}
try {
@ -612,24 +622,30 @@ export default class AddonManager extends Events {
await removeDirRecursive ( resolve ( this . dir , addonId ) ) ;
throw new Error ( ` There was a problem while attempting to install " ${ addonId } "! ` , err ) ;
}
renameSync ( join ( this . dir , ` __installing__ ${ addonId } ` ) , join ( this . dir , addonId ) ) ;
console . log ( 'hello?' ) ;
try {
renameSync ( join ( this . dir , ` __installing__ ${ addonId } ` ) , join ( this . dir , addonId ) ) ;
} catch ( err ) {
console . log ( err ) ;
}
console . log ( 'okay' ) ;
/ * *
* Send a success toast .
* /
vizality . api . notifications . sendToast ( {
id : ErrorTypes . ADDON _ALREADY _INSTALLED ,
id : 'addon-installed' ,
header : Messages . VIZALITY _ADDON _SUCCESSFULLY _INSTALLED . format ( { type : toTitleCase ( this . type ) } ) ,
content : < AddonInfoMessage addon = { addon } message = { Messages . VIZALITY _ADDON _SUCCESSFULLY _INSTALLED _DESC . format ( { type : toTitleCase ( this . type ) } ) } / > ,
content : < AddonInfoMessage addon = { this . get ( addon Id) } message = { Messages . VIZALITY _ADDON _SUCCESSFULLY _INSTALLED _DESC . format ( { type : toTitleCase ( this . type ) } ) } / > ,
icon : toTitleCase ( this . type ) ,
buttons : [
{
text : 'View' ,
onClick : ( ) => vizality . api . routes . navigateTo ( ` / ${ toPlural ( this . type ) } / ${ addon . addonId } ` )
onClick : ( ) => vizality . api . routes . navigateTo ( ` / vizality/ ${ this . type } / ${ addonId } ` )
}
]
} ) ;
} catch ( err ) {
console . warn ( err ) ;
let addon ;
if ( err . addonId ) {
addon = this . get ( err . addonId ) ;
@ -642,7 +658,7 @@ export default class AddonManager extends Events {
this . _error ( err . message , err . addonId , err . stack ) ;
vizality . api . notifications . sendToast ( {
id : ErrorTypes . ADDON _ALREADY _INSTALLED ,
header : Messages . VIZALITY _ADDON _ALREADY _INSTALLED . format ( { type : toTitleCase ( this . type ) } ) ,
header : Messages . VIZALITY _ADDON _ALREADY _INSTALLED _DESC . format ( { type : toTitleCase ( this . type ) } ) ,
content : < AddonInfoMessage addon = { addon } message = { err . message } / > ,
icon : toTitleCase ( this . type ) ,
buttons : [
@ -660,13 +676,44 @@ export default class AddonManager extends Events {
}
]
} ) ;
break ;
}
/ * *
* Addon Already Install ed
* Addon Already Install ing
* /
// case ErrorTypes.ADDON_ALREADY_INSTALLED: {
// }
case ErrorTypes . ADDON _ALREADY _INSTALLING : {
this . _error ( err . message , err . addonId , err . stack ) ;
vizality . api . notifications . sendToast ( {
id : ErrorTypes . ADDON _ALREADY _INSTALLING ,
header : Messages . VIZALITY _ADDON _ALREADY _INSTALLING _DESC . format ( { type : toTitleCase ( this . type ) } ) ,
content : < AddonInfoMessage addon = { addon } message = { err . message } / > ,
icon : toTitleCase ( this . type ) ,
buttons : [
{
text : 'Cancel' ,
color : 'red' ,
onClick : async ( ) => {
vizality . api . notifications . closeToast ( ErrorTypes . ADDON _ALREADY _INSTALLING ) ;
await removeDirRecursive ( resolve ( this . dir , ` __installing__ ${ err . addonId } ` ) ) ;
}
}
]
} ) ;
break ;
}
/ * *
* Addon Directory Already Exists
* /
case ErrorTypes . ADDON _DIRECTORY _ALREADY _EXISTS : {
this . _error ( err . message , err . addonId , err . stack ) ;
vizality . api . notifications . sendToast ( {
id : ErrorTypes . ADDON _DIRECTORY _ALREADY _EXISTS ,
header : Messages . ADDON _DIRECTORY _ALREADY _EXISTS _DESC . format ( { type : toTitleCase ( this . type ) } ) ,
content : < AddonInfoMessage addon = { addon } message = { err . message } / > ,
icon : toTitleCase ( this . type )
} ) ;
break ;
}
}
}
}