mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-08 08:01:05 -05:00
Support configurable mod locations
This commit is contained in:
Generated
+6
@@ -13,6 +13,7 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"json-colorizer": "^3.0.1",
|
"json-colorizer": "^3.0.1",
|
||||||
|
"string-template": "^1.0.0",
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -10783,6 +10784,11 @@
|
|||||||
"url": "https://github.com/chalk/strip-ansi?sponsor=1"
|
"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": {
|
"node_modules/string-width": {
|
||||||
"version": "4.2.3",
|
"version": "4.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"json-colorizer": "^3.0.1",
|
"json-colorizer": "^3.0.1",
|
||||||
|
"string-template": "^1.0.0",
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,7 +198,9 @@ class Kernel extends AdvancedBase {
|
|||||||
const mod_dirnames = fs.readdirSync(mods_dirpath);
|
const mod_dirnames = fs.readdirSync(mods_dirpath);
|
||||||
for ( const mod_dirname of mod_dirnames ) {
|
for ( const mod_dirname of mod_dirnames ) {
|
||||||
const mod_path = path_.join(mods_dirpath, mod_dirname);
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ const mod_paths = ({ path_checks }) => ({ path_ }) => [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
get 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 ],
|
checks: [ path_checks.skip_if_not_exists ],
|
||||||
},
|
},
|
||||||
@@ -191,6 +191,7 @@ class RuntimeEnvironment extends AdvancedBase {
|
|||||||
fs: require('node:fs'),
|
fs: require('node:fs'),
|
||||||
path_: require('node:path'),
|
path_: require('node:path'),
|
||||||
crypto: require('node:crypto'),
|
crypto: require('node:crypto'),
|
||||||
|
format: require('string-template'),
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor ({ logger }) {
|
constructor ({ logger }) {
|
||||||
@@ -213,6 +214,12 @@ class RuntimeEnvironment extends AdvancedBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init_ () {
|
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_(
|
const config_path_entry = this.get_first_suitable_path_(
|
||||||
{ pathFor: 'configuration' },
|
{ pathFor: 'configuration' },
|
||||||
this.config_paths,
|
this.config_paths,
|
||||||
@@ -299,14 +306,26 @@ class RuntimeEnvironment extends AdvancedBase {
|
|||||||
// console.log({ ...config.services });
|
// console.log({ ...config.services });
|
||||||
|
|
||||||
const mod_paths = [];
|
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);
|
mod_paths.push(mods_path_entry.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
// If configured, add a user-specified mod path
|
||||||
mod_paths,
|
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) {
|
get_first_suitable_path_ (meta, paths, last_checks) {
|
||||||
|
|||||||
Reference in New Issue
Block a user