This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
conditions = ["{{ 'package.json' | file }}"]
|
conditions = ["{{ 'package.json' | file }}"]
|
||||||
variables.use_nvm = "{{ (((('home' | env) + '/.nvm/nvm.sh') | file) and ('.nvmrc' | file)) | bool }}"
|
variables.use_nvm = "{{ (((('home' | env) + '/.nvm/nvm.sh') | file) and ('.nvmrc' | file)) | bool }}"
|
||||||
variables.nvm = "{{ '. ~/.nvm/nvm.sh && nvm use && ' if use_nvm | bool else '' }}"
|
variables.nvm = "{{ '. ~/.nvm/nvm.sh && nvm use && ' if use_nvm | bool else '' }}"
|
||||||
|
variables.npm_scripts = "{{ 'package.json' | read | get('scripts') | tojson }}"
|
||||||
|
|
||||||
# install
|
# install
|
||||||
[presets.nodejs.tasks.setup.npm]
|
[presets.nodejs.tasks.setup.npm]
|
||||||
@@ -13,20 +14,9 @@ commands = ["{{ nvm }}npm install-clean"]
|
|||||||
conditions = ["{{ not ('package-lock.json' | file) }}"]
|
conditions = ["{{ not ('package-lock.json' | file) }}"]
|
||||||
commands = ["{{ nvm }}npm install"]
|
commands = ["{{ nvm }}npm install"]
|
||||||
|
|
||||||
# test
|
# scripts
|
||||||
[presets.nodejs.tasks.test.jest]
|
[presets.nodejs.tasks."{{ npm_scripts | tojson }}".npm]
|
||||||
conditions = ["{{ 'node_modules/jest' | file }}"]
|
commands = ["{{ nvm }}npm run {{ task }}"]
|
||||||
commands = ["{{ nvm }}npx jest"]
|
|
||||||
|
|
||||||
# build
|
|
||||||
[presets.nodejs.tasks.build.npm]
|
|
||||||
conditions = ["{{ 'package.json' | read | get('scripts.build') }}"]
|
|
||||||
commands = ["{{ nvm }}npm run build"]
|
|
||||||
|
|
||||||
# publish
|
|
||||||
[presets.nodejs.tasks.publish.npm]
|
|
||||||
conditions = ["{{ 'package.json' | read | get('scripts.publish') }}"]
|
|
||||||
commands = ["{{ nvm }}npm run publish"]
|
|
||||||
|
|
||||||
# clean
|
# clean
|
||||||
[presets.nodejs.tasks.clean.node_modules]
|
[presets.nodejs.tasks.clean.node_modules]
|
||||||
@@ -36,4 +26,6 @@ commands = ["rm -rf node_modules"]
|
|||||||
# version
|
# version
|
||||||
[presets.nodejs.tasks.version.npm]
|
[presets.nodejs.tasks.version.npm]
|
||||||
conditions = ["{{ version }}"]
|
conditions = ["{{ version }}"]
|
||||||
commands = ["{{ nvm }}npm version {{ version }} --allow-same-version --commit-hooks false --git-tag-version false"]
|
commands = [
|
||||||
|
"{{ nvm }}npm version {{ version }} --allow-same-version --commit-hooks false --git-tag-version false",
|
||||||
|
]
|
||||||
|
|||||||
@@ -15,6 +15,21 @@ class PresetEntryDetector(EntryDetector):
|
|||||||
def __init__(self, preset_loader_config: PresetLoaderConfig | None = None):
|
def __init__(self, preset_loader_config: PresetLoaderConfig | None = None):
|
||||||
self._preset_loader_config = preset_loader_config
|
self._preset_loader_config = preset_loader_config
|
||||||
|
|
||||||
|
def _expand_section(
|
||||||
|
self,
|
||||||
|
section: str,
|
||||||
|
template: PathTemplate,
|
||||||
|
variables: Variables,
|
||||||
|
) -> dict[str, str | None]:
|
||||||
|
data = template.fill_template(section, variables)
|
||||||
|
try:
|
||||||
|
sections: dict[str, str | None] = json.loads(data)
|
||||||
|
if isinstance(sections, str):
|
||||||
|
sections = json.loads(sections)
|
||||||
|
except ValueError:
|
||||||
|
sections = {data: None}
|
||||||
|
return sections
|
||||||
|
|
||||||
# pylint:disable=too-many-locals,too-many-nested-blocks,too-many-branches
|
# pylint:disable=too-many-locals,too-many-nested-blocks,too-many-branches
|
||||||
def detect_entry(self, basepath: Path, rootpath: Path) -> Entry:
|
def detect_entry(self, basepath: Path, rootpath: Path) -> Entry:
|
||||||
template = PathTemplate(basepath)
|
template = PathTemplate(basepath)
|
||||||
@@ -46,33 +61,37 @@ class PresetEntryDetector(EntryDetector):
|
|||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
for task_name, task_pack in preset.tasks.items():
|
for task_name, task_pack in preset.tasks.items():
|
||||||
for sub_tag, task_preset in task_pack.items():
|
task_names = self._expand_section(task_name, template, preset_variables)
|
||||||
sub_tags = template.fill_template(sub_tag, preset_variables)
|
for i_task_name, i_task_value in task_names.items():
|
||||||
try:
|
if i_task_value:
|
||||||
sub_tags = json.loads(sub_tags)
|
preset_variables["task"] = i_task_name
|
||||||
except ValueError:
|
preset_variables["item"] = i_task_value
|
||||||
sub_tags = {sub_tags: None}
|
for sub_tag, task_preset in task_pack.items():
|
||||||
for i_sub_tag, i_sub_tag_value in sub_tags.items():
|
sub_tags = self._expand_section(
|
||||||
if i_sub_tag_value:
|
sub_tag, template, preset_variables
|
||||||
preset_variables["item"] = i_sub_tag_value
|
)
|
||||||
if not task_preset.conditions or template.check_conditions(
|
for i_sub_tag, i_sub_tag_value in sub_tags.items():
|
||||||
task_preset.conditions, preset_variables
|
if i_sub_tag_value:
|
||||||
):
|
preset_variables["sub_tag"] = i_sub_tag
|
||||||
variables = preset_variables.copy()
|
preset_variables["item"] = i_sub_tag_value
|
||||||
if task_preset.variables:
|
if not task_preset.conditions or template.check_conditions(
|
||||||
template.update_variables(
|
task_preset.conditions, preset_variables
|
||||||
task_preset.variables, variables
|
):
|
||||||
|
variables = preset_variables.copy()
|
||||||
|
if task_preset.variables:
|
||||||
|
template.update_variables(
|
||||||
|
task_preset.variables, variables
|
||||||
|
)
|
||||||
|
task = Task(
|
||||||
|
key=TaskKey(i_task_name, tag, i_sub_tag),
|
||||||
|
commands=[
|
||||||
|
template.fill_template(command, variables)
|
||||||
|
for command in task_preset.commands
|
||||||
|
],
|
||||||
|
priority=task_preset.priority,
|
||||||
|
cwd=task_preset.cwd,
|
||||||
)
|
)
|
||||||
task = Task(
|
tasks.append(task)
|
||||||
key=TaskKey(task_name, tag, i_sub_tag),
|
|
||||||
commands=[
|
|
||||||
template.fill_template(command, variables)
|
|
||||||
for command in task_preset.commands
|
|
||||||
],
|
|
||||||
priority=task_preset.priority,
|
|
||||||
cwd=task_preset.cwd,
|
|
||||||
)
|
|
||||||
tasks.append(task)
|
|
||||||
if tasks:
|
if tasks:
|
||||||
tasks = sorted(tasks, key=operator.attrgetter("priority"), reverse=True)
|
tasks = sorted(tasks, key=operator.attrgetter("priority"), reverse=True)
|
||||||
return Entry(tasks, entry_variables, basepath, rootpath)
|
return Entry(tasks, entry_variables, basepath, rootpath)
|
||||||
|
|||||||
Reference in New Issue
Block a user