2026-09-18 02:13:11 +02:00
|
|
|
/*
|
|
|
|
|
This file is part of »ivaldi«.
|
|
|
|
|
|
|
|
|
|
Copyright 2025 'Fenris Wolf' <fenris@folksprak.org>
|
|
|
|
|
|
|
|
|
|
»ivaldi« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»ivaldi« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »ivaldi«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace _ivaldi
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
export function command_log(
|
|
|
|
|
content : string
|
|
|
|
|
) : string
|
|
|
|
|
{
|
|
|
|
|
return lib_plankton.string.coin(
|
|
|
|
|
"echo '-- {{content}}'",
|
|
|
|
|
{
|
|
|
|
|
"content": content,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
export function command_delete(
|
|
|
|
|
path : string
|
|
|
|
|
) : string
|
|
|
|
|
{
|
|
|
|
|
return lib_plankton.string.coin(
|
|
|
|
|
"rm --recursive --force {{path}}",
|
|
|
|
|
{
|
|
|
|
|
"path": path,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
export function command_mkdir(
|
|
|
|
|
path : string
|
|
|
|
|
) : string
|
|
|
|
|
{
|
|
|
|
|
return lib_plankton.string.coin(
|
|
|
|
|
"mkdir --parents {{path}}",
|
|
|
|
|
{
|
|
|
|
|
"path": path,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
export function command_cat(
|
|
|
|
|
source_paths : Array<string>,
|
|
|
|
|
target_path : string,
|
|
|
|
|
{
|
|
|
|
|
"append": append = false,
|
|
|
|
|
}
|
|
|
|
|
:
|
|
|
|
|
{
|
|
|
|
|
append ?: boolean;
|
|
|
|
|
}
|
|
|
|
|
=
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
) : string
|
|
|
|
|
{
|
|
|
|
|
return lib_plankton.string.coin(
|
|
|
|
|
"cat {{source_paths}} {{operator}} {{target_path}}",
|
|
|
|
|
{
|
|
|
|
|
"source_paths": source_paths.join(" "),
|
|
|
|
|
"operator": (append ? ">>" : ">"),
|
|
|
|
|
"target_path": target_path,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
export function command_copy(
|
|
|
|
|
source_path : string,
|
|
|
|
|
target_path : string
|
|
|
|
|
) : string
|
|
|
|
|
{
|
|
|
|
|
return lib_plankton.string.coin(
|
|
|
|
|
"cp -r -u {{source_path}} {{target_path}}",
|
|
|
|
|
{
|
|
|
|
|
"source_path": source_path,
|
|
|
|
|
"target_path": target_path,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
export function command_ptk_bundle(
|
|
|
|
|
target : string,
|
|
|
|
|
modules : Array<string>
|
|
|
|
|
) : string
|
|
|
|
|
{
|
|
|
|
|
return lib_plankton.string.coin(
|
|
|
|
|
"ptk bundle {{target}} {{modules}}",
|
|
|
|
|
{
|
|
|
|
|
"target": target,
|
|
|
|
|
"modules": modules.join(" "),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
export function command_npm_install(
|
|
|
|
|
modules : Array<string>
|
|
|
|
|
) : string
|
|
|
|
|
{
|
|
|
|
|
return lib_plankton.string.coin(
|
|
|
|
|
"npm install {{modules}}",
|
|
|
|
|
{
|
|
|
|
|
"modules": modules.join(" "),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
export function command_tsc(
|
|
|
|
|
source_paths : Array<string>,
|
|
|
|
|
target_path : string,
|
|
|
|
|
{
|
|
|
|
|
"declaration": declaration = false,
|
|
|
|
|
"libs": libs = [],
|
2026-09-18 02:31:28 +02:00
|
|
|
"head": head = "tsc"
|
2026-09-18 02:13:11 +02:00
|
|
|
}
|
|
|
|
|
:
|
|
|
|
|
{
|
|
|
|
|
declaration ?: boolean;
|
|
|
|
|
libs ?: Array<string>;
|
2026-09-18 02:31:28 +02:00
|
|
|
head ?: string;
|
2026-09-18 02:13:11 +02:00
|
|
|
}
|
|
|
|
|
=
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
) : string
|
|
|
|
|
{
|
|
|
|
|
return lib_plankton.string.coin(
|
2026-09-18 02:31:28 +02:00
|
|
|
"{{head}}{{libs}} {{source_paths}} --outFile {{target_path}}{{declaration}}",
|
2026-09-18 02:13:11 +02:00
|
|
|
{
|
2026-09-18 02:31:28 +02:00
|
|
|
"head": head,
|
2026-09-18 02:13:11 +02:00
|
|
|
"libs": (
|
|
|
|
|
libs
|
|
|
|
|
.map(
|
|
|
|
|
name => lib_plankton.string.coin(
|
|
|
|
|
" --lib {{name}}",
|
|
|
|
|
{"name": name}
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
.join("")
|
|
|
|
|
),
|
|
|
|
|
"source_paths": source_paths.join(" "),
|
|
|
|
|
"target_path": target_path,
|
|
|
|
|
"declaration": (declaration ? " --declaration" : ""),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-18 09:53:28 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @todo outsource
|
|
|
|
|
*/
|
|
|
|
|
export function execute(
|
|
|
|
|
command : string,
|
|
|
|
|
{
|
|
|
|
|
"log_only": log_only = false,
|
|
|
|
|
"working_directory": working_directory = null,
|
|
|
|
|
} : {
|
|
|
|
|
log_only ?: boolean;
|
|
|
|
|
working_directory ?: (null | string);
|
|
|
|
|
} = {
|
|
|
|
|
}
|
|
|
|
|
) : Promise<
|
|
|
|
|
{
|
|
|
|
|
code : int;
|
|
|
|
|
stdout : string;
|
|
|
|
|
stderr : string;
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{
|
|
|
|
|
const nm_child_process = require("child_process");
|
|
|
|
|
return (
|
|
|
|
|
new Promise(
|
|
|
|
|
(resolve, reject) => {
|
|
|
|
|
lib_plankton.log._info(
|
|
|
|
|
"execute",
|
|
|
|
|
{
|
|
|
|
|
"details": {
|
|
|
|
|
"command": command,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
if (log_only) {
|
|
|
|
|
resolve(
|
|
|
|
|
{
|
|
|
|
|
"code": 0,
|
|
|
|
|
"stdout": "",
|
|
|
|
|
"stderr": "",
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
nm_child_process.exec(
|
|
|
|
|
command,
|
|
|
|
|
{
|
|
|
|
|
"cwd": ((working_directory === null) ? undefined : working_directory),
|
|
|
|
|
},
|
|
|
|
|
(error, stdout, stderr) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
reject(error);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
resolve(
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @todo assign correct value
|
|
|
|
|
*/
|
|
|
|
|
"code": 0,
|
|
|
|
|
"stdout": stdout,
|
|
|
|
|
"stderr": stderr,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-18 02:13:11 +02:00
|
|
|
}
|