mirror of
https://github.com/pyscript/pyscript.git
synced 2026-02-15 13:00:34 -05:00
implement proposal for fetching paths and retaining structure of dirs and packages (#914)
* implement proposal * update docs and replace py-env * more docs * suggested proposal * update docs * add to_file parameter * remove comment from Makefile * suggested improvements * move tests from basic to py_config * retain leading slash from the first path
This commit is contained in:
39
pyscriptjs/src/plugins/fetch.ts
Normal file
39
pyscriptjs/src/plugins/fetch.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { joinPaths } from '../utils';
|
||||
import { FetchConfig } from "../pyconfig";
|
||||
|
||||
export function calculatePaths(fetch_cfg: FetchConfig[]) {
|
||||
const fetchPaths: string[] = [];
|
||||
const paths: string[] = [];
|
||||
fetch_cfg.forEach(function (each_fetch_cfg: FetchConfig) {
|
||||
const from = each_fetch_cfg.from || "";
|
||||
const to_folder = each_fetch_cfg.to_folder || ".";
|
||||
const to_file = each_fetch_cfg.to_file;
|
||||
const files = each_fetch_cfg.files;
|
||||
if (files !== undefined)
|
||||
{
|
||||
if (to_file !== undefined)
|
||||
{
|
||||
throw Error(`Cannot use 'to_file' and 'files' parameters together!`);
|
||||
}
|
||||
for (const each_f of files)
|
||||
{
|
||||
const each_fetch_path = joinPaths([from, each_f]);
|
||||
fetchPaths.push(each_fetch_path);
|
||||
const each_path = joinPaths([to_folder, each_f]);
|
||||
paths.push(each_path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fetchPaths.push(from);
|
||||
const filename = to_file || from.split('/').pop();
|
||||
if (filename === '') {
|
||||
throw Error(`Couldn't determine the filename from the path ${from}, supply ${to_file} parameter!`);
|
||||
}
|
||||
else {
|
||||
paths.push(joinPaths([to_folder, filename]));
|
||||
}
|
||||
}
|
||||
});
|
||||
return [paths, fetchPaths];
|
||||
}
|
||||
Reference in New Issue
Block a user