mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 14:03:42 +00:00
Support configurable mod locations
This commit is contained in:
parent
8d22276f13
commit
684b0dc059
6
package-lock.json
generated
6
package-lock.json
generated
@ -13,6 +13,7 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"json-colorizer": "^3.0.1",
|
||||
"string-template": "^1.0.0",
|
||||
"uuid": "^9.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -10783,6 +10784,11 @@
|
||||
"url": "https://github.com/chalk/strip-ansi?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/string-template": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/string-template/-/string-template-1.0.0.tgz",
|
||||
"integrity": "sha512-SLqR3GBUXuoPP5MmYtD7ompvXiG87QjT6lzOszyXjTM86Uu7At7vNnt2xgyTLq5o9T4IxTYFyGxcULqpsmsfdg=="
|
||||
},
|
||||
"node_modules/string-width": {
|
||||
"version": "4.2.3",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
||||
|
@ -43,6 +43,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"json-colorizer": "^3.0.1",
|
||||
"string-template": "^1.0.0",
|
||||
"uuid": "^9.0.1"
|
||||
}
|
||||
}
|
||||
|
@ -198,7 +198,9 @@ class Kernel extends AdvancedBase {
|
||||
const mod_dirnames = fs.readdirSync(mods_dirpath);
|
||||
for ( const mod_dirname of mod_dirnames ) {
|
||||
const mod_path = path_.join(mods_dirpath, mod_dirname);
|
||||
if ( ! fs.lstatSync(mod_path).isDirectory() ) {
|
||||
|
||||
const stat = fs.statSync(mod_path);
|
||||
if ( ! stat.isDirectory() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ const mod_paths = ({ path_checks }) => ({ path_ }) => [
|
||||
},
|
||||
{
|
||||
get path () {
|
||||
return path_.join(original_cwd, 'mods');
|
||||
return path_.join(path_.dirname(require.main.filename), '../mods');
|
||||
},
|
||||
checks: [ path_checks.skip_if_not_exists ],
|
||||
},
|
||||
@ -191,6 +191,7 @@ class RuntimeEnvironment extends AdvancedBase {
|
||||
fs: require('node:fs'),
|
||||
path_: require('node:path'),
|
||||
crypto: require('node:crypto'),
|
||||
format: require('string-template'),
|
||||
}
|
||||
|
||||
constructor ({ logger }) {
|
||||
@ -213,6 +214,12 @@ class RuntimeEnvironment extends AdvancedBase {
|
||||
}
|
||||
|
||||
init_ () {
|
||||
// This variable, called "environment", will be passed back to Kernel
|
||||
// with some helpful values. A partial-population of this object later
|
||||
// in this function will be used when evaluating configured paths.
|
||||
const environment = {};
|
||||
environment.source = this.modules.path_.dirname(require.main.filename);
|
||||
|
||||
const config_path_entry = this.get_first_suitable_path_(
|
||||
{ pathFor: 'configuration' },
|
||||
this.config_paths,
|
||||
@ -299,14 +306,26 @@ class RuntimeEnvironment extends AdvancedBase {
|
||||
// console.log({ ...config.services });
|
||||
|
||||
const mod_paths = [];
|
||||
environment.mod_paths = mod_paths;
|
||||
|
||||
if ( mods_path_entry ) {
|
||||
// TODO: implement `get_all_suitable_paths_` so we can load mods
|
||||
// from multiple locations. Note: we'll need to carefully consider
|
||||
// how this is configured.
|
||||
if ( false ) if ( mods_path_entry ) {
|
||||
mod_paths.push(mods_path_entry.path);
|
||||
}
|
||||
|
||||
return {
|
||||
mod_paths,
|
||||
};
|
||||
// If configured, add a user-specified mod path
|
||||
if ( config.mod_directories ) {
|
||||
for ( const dir of config.mod_directories ) {
|
||||
const mods_directory = this.modules.format(
|
||||
dir, environment,
|
||||
);
|
||||
mod_paths.push(mods_directory);
|
||||
}
|
||||
}
|
||||
|
||||
return environment;
|
||||
}
|
||||
|
||||
get_first_suitable_path_ (meta, paths, last_checks) {
|
||||
|
Loading…
Reference in New Issue
Block a user