mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-21 11:15:36 -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:
@@ -17,11 +17,18 @@ export interface AppConfig extends Record<string, any> {
|
||||
autoclose_loader?: boolean;
|
||||
runtimes?: RuntimeConfig[];
|
||||
packages?: string[];
|
||||
paths?: string[];
|
||||
fetch?: FetchConfig[];
|
||||
plugins?: string[];
|
||||
pyscript?: PyScriptMetadata;
|
||||
}
|
||||
|
||||
export type FetchConfig = {
|
||||
from?: string;
|
||||
to_folder?: string;
|
||||
to_file?: string;
|
||||
files?: string[];
|
||||
};
|
||||
|
||||
export type RuntimeConfig = {
|
||||
src?: string;
|
||||
name?: string;
|
||||
@@ -37,7 +44,7 @@ const allKeys = {
|
||||
string: ['name', 'description', 'version', 'type', 'author_name', 'author_email', 'license'],
|
||||
number: ['schema_version'],
|
||||
boolean: ['autoclose_loader'],
|
||||
array: ['runtimes', 'packages', 'paths', 'plugins'],
|
||||
array: ['runtimes', 'packages', 'fetch', 'plugins'],
|
||||
};
|
||||
|
||||
export const defaultConfig: AppConfig = {
|
||||
@@ -52,7 +59,7 @@ export const defaultConfig: AppConfig = {
|
||||
},
|
||||
],
|
||||
packages: [],
|
||||
paths: [],
|
||||
fetch: [],
|
||||
plugins: [],
|
||||
};
|
||||
|
||||
@@ -183,9 +190,9 @@ function validateConfig(configText: string, configType = 'toml') {
|
||||
if (validateParamInConfig(item, keyType, config)) {
|
||||
if (item === 'runtimes') {
|
||||
finalConfig[item] = [];
|
||||
const runtimes = config[item] as object[];
|
||||
runtimes.forEach(function (eachRuntime: object) {
|
||||
const runtimeConfig: object = {};
|
||||
const runtimes = config[item] as RuntimeConfig[];
|
||||
runtimes.forEach(function (eachRuntime: RuntimeConfig) {
|
||||
const runtimeConfig: RuntimeConfig = {};
|
||||
for (const eachRuntimeParam in eachRuntime) {
|
||||
if (validateParamInConfig(eachRuntimeParam, 'string', eachRuntime)) {
|
||||
runtimeConfig[eachRuntimeParam] = eachRuntime[eachRuntimeParam];
|
||||
@@ -193,7 +200,22 @@ function validateConfig(configText: string, configType = 'toml') {
|
||||
}
|
||||
finalConfig[item].push(runtimeConfig);
|
||||
});
|
||||
} else {
|
||||
}
|
||||
else if (item === 'fetch') {
|
||||
finalConfig[item] = [];
|
||||
const fetchList = config[item] as FetchConfig[];
|
||||
fetchList.forEach(function (eachFetch: FetchConfig) {
|
||||
const eachFetchConfig: FetchConfig = {};
|
||||
for (const eachFetchConfigParam in eachFetch) {
|
||||
const targetType = eachFetchConfigParam === 'files' ? 'array' : 'string';
|
||||
if (validateParamInConfig(eachFetchConfigParam, targetType, eachFetch)) {
|
||||
eachFetchConfig[eachFetchConfigParam] = eachFetch[eachFetchConfigParam];
|
||||
}
|
||||
}
|
||||
finalConfig[item].push(eachFetchConfig);
|
||||
});
|
||||
}
|
||||
else {
|
||||
finalConfig[item] = config[item];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user