2024-09-24 08:25:55 +00:00
|
|
|
__package__ = 'archivebox.pkg_plugins.npm'
|
2024-09-03 07:58:50 +00:00
|
|
|
|
2024-09-21 08:52:36 +00:00
|
|
|
from pathlib import Path
|
2024-09-06 08:48:18 +00:00
|
|
|
from typing import List, Optional
|
2024-09-03 07:58:50 +00:00
|
|
|
|
2024-09-10 07:00:41 +00:00
|
|
|
from django.conf import settings
|
2024-09-21 11:00:54 +00:00
|
|
|
from pydantic import InstanceOf
|
2024-09-21 08:52:36 +00:00
|
|
|
|
|
|
|
from pydantic_pkgr import BinProvider, NpmProvider, BinName, PATHStr, BinProviderName
|
2024-09-03 07:58:50 +00:00
|
|
|
|
2024-09-06 08:48:18 +00:00
|
|
|
from plugantic.base_plugin import BasePlugin
|
2024-09-21 11:00:54 +00:00
|
|
|
from plugantic.base_configset import BaseConfigSet
|
2024-09-06 08:48:18 +00:00
|
|
|
from plugantic.base_binary import BaseBinary, BaseBinProvider, env, apt, brew
|
|
|
|
from plugantic.base_hook import BaseHook
|
2024-09-03 07:58:50 +00:00
|
|
|
|
2024-09-21 08:52:36 +00:00
|
|
|
|
2024-09-03 07:58:50 +00:00
|
|
|
from ...config import CONFIG
|
|
|
|
|
|
|
|
###################### Config ##########################
|
|
|
|
|
|
|
|
|
|
|
|
class NpmDependencyConfigs(BaseConfigSet):
|
2024-09-21 11:00:54 +00:00
|
|
|
# section: ConfigSectionName = 'DEPENDENCY_CONFIG'
|
2024-09-03 07:58:50 +00:00
|
|
|
|
2024-09-21 11:00:54 +00:00
|
|
|
# USE_NPM: bool = True
|
|
|
|
# NPM_BINARY: str = Field(default='npm')
|
|
|
|
# NPM_ARGS: Optional[List[str]] = Field(default=None)
|
|
|
|
# NPM_EXTRA_ARGS: List[str] = []
|
|
|
|
# NPM_DEFAULT_ARGS: List[str] = []
|
|
|
|
pass
|
2024-09-03 07:58:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_GLOBAL_CONFIG = {
|
|
|
|
}
|
|
|
|
NPM_CONFIG = NpmDependencyConfigs(**DEFAULT_GLOBAL_CONFIG)
|
|
|
|
|
|
|
|
|
2024-09-21 08:52:36 +00:00
|
|
|
class SystemNpmProvider(NpmProvider, BaseBinProvider):
|
2024-09-21 11:00:54 +00:00
|
|
|
name: BinProviderName = "sys_npm"
|
2024-09-03 07:58:50 +00:00
|
|
|
PATH: PATHStr = str(CONFIG.NODE_BIN_PATH)
|
2024-09-21 08:52:36 +00:00
|
|
|
|
|
|
|
npm_prefix: Optional[Path] = None
|
|
|
|
|
|
|
|
class LibNpmProvider(NpmProvider, BaseBinProvider):
|
|
|
|
name: BinProviderName = "lib_npm"
|
|
|
|
PATH: PATHStr = str(CONFIG.NODE_BIN_PATH)
|
|
|
|
|
|
|
|
npm_prefix: Optional[Path] = settings.CONFIG.LIB_DIR / 'npm'
|
|
|
|
|
2024-09-03 07:58:50 +00:00
|
|
|
|
2024-09-21 08:52:36 +00:00
|
|
|
SYS_NPM_BINPROVIDER = SystemNpmProvider()
|
|
|
|
LIB_NPM_BINPROVIDER = LibNpmProvider()
|
|
|
|
npm = LIB_NPM_BINPROVIDER
|
2024-09-03 07:58:50 +00:00
|
|
|
|
|
|
|
class NpmBinary(BaseBinary):
|
|
|
|
name: BinName = 'npm'
|
2024-09-03 10:22:37 +00:00
|
|
|
binproviders_supported: List[InstanceOf[BinProvider]] = [apt, brew, env]
|
2024-09-03 07:58:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
NPM_BINARY = NpmBinary()
|
|
|
|
|
2024-09-03 10:22:37 +00:00
|
|
|
class NodeBinary(BaseBinary):
|
|
|
|
name: BinName = 'node'
|
|
|
|
binproviders_supported: List[InstanceOf[BinProvider]] = [apt, brew, env]
|
|
|
|
|
|
|
|
|
|
|
|
NODE_BINARY = NodeBinary()
|
|
|
|
|
2024-09-03 07:58:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NpmPlugin(BasePlugin):
|
|
|
|
app_label: str = 'npm'
|
|
|
|
verbose_name: str = 'NPM'
|
2024-09-06 08:48:18 +00:00
|
|
|
|
|
|
|
hooks: List[InstanceOf[BaseHook]] = [
|
|
|
|
NPM_CONFIG,
|
2024-09-21 08:52:36 +00:00
|
|
|
SYS_NPM_BINPROVIDER,
|
|
|
|
LIB_NPM_BINPROVIDER,
|
2024-09-06 08:48:18 +00:00
|
|
|
NODE_BINARY,
|
|
|
|
NPM_BINARY,
|
|
|
|
]
|
2024-09-03 07:58:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
PLUGIN = NpmPlugin()
|
2024-09-10 07:00:41 +00:00
|
|
|
PLUGIN.register(settings)
|
2024-09-03 07:58:50 +00:00
|
|
|
DJANGO_APP = PLUGIN.AppConfig
|