Skip to content

Commit

Permalink
✨ Feature: supporting install specific version of plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed Jan 31, 2021
1 parent 36ad778 commit 35e15b0
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,17 @@ export const getProcessPluginName = (nameOrPath: string, logger: ILogger | Conso
* 4. /absolutePath/.../picgo-plugin-xxx -> picgo-plugin-xxx
* 5. an exception: [package.json's name] !== [folder name]
* then use [package.json's name], usually match the scope package.
* 6. if plugin name has version: [email protected] then remove the version
* @param nameOrPath
*/
export const getNormalPluginName = (nameOrPath: string, logger: ILogger | Console = console): string => {
const pluginNameType = getPluginNameType(nameOrPath)
switch (pluginNameType) {
case 'normal':
case 'scope':
return nameOrPath
return removePluginVersion(nameOrPath)
case 'simple':
return handleCompletePluginName(nameOrPath)
return removePluginVersion(handleCompletePluginName(nameOrPath))
default: {
// now, the nameOrPath must be path
// the nameOrPath here will be ensured with unix style
Expand Down Expand Up @@ -282,3 +283,22 @@ export const handleUnixStylePath = (pathStr: string): string => {
const pathArr = pathStr.split(path.sep)
return pathArr.join('/')
}

/**
* remove plugin version when register plugin name
* 1. [email protected] -> picgo-plugin-xxx
* @param nameOrPath
*/
export const removePluginVersion = (nameOrPath: string): string => {
if (!nameOrPath.includes('@')) {
return nameOrPath
} else {
const matchArr = nameOrPath.match(/(.+\/)?(picgo-plugin-\w+)(@.+)*/)
if (!matchArr) {
console.warn('can not remove plugin version')
return nameOrPath
} else {
return matchArr[2]
}
}
}

0 comments on commit 35e15b0

Please sign in to comment.