-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Feature: supporting install specific version of plugin
- Loading branch information
1 parent
36ad778
commit 35e15b0
Showing
1 changed file
with
22 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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] | ||
} | ||
} | ||
} |