60 lines
2.1 KiB
Text
60 lines
2.1 KiB
Text
|
### External dependencies
|
||
|
|
||
|
The dyna3 program depends on some externally-maintained JavaScript
|
||
|
libraries/modules. The package uses npm to track these external dependencies.
|
||
|
A module externals.js is automatically generated from the package_lock.json file
|
||
|
created by npm to load the necessary modules at runtime.
|
||
|
|
||
|
The generation is performed by pkglock_to_externals.litcoffee, which also
|
||
|
records the main importable file within the library, as there does not seem
|
||
|
to be a systematic way to generate that filename from the module name.
|
||
|
```javascript
|
||
|
|
||
|
importable = { three: 'build/three.module.js' }
|
||
|
|
||
|
```
|
||
|
Currently, dyna3 makes use of the following external libraries:
|
||
|
```javascript
|
||
|
|
||
|
if process.argv.length < 3
|
||
|
header =
|
||
|
"""
|
||
|
/* External module loader for dyna3
|
||
|
* Generated automatically from package-lock.json by
|
||
|
* helpers/pkglock_to_externals.litcoffee
|
||
|
*/
|
||
|
|
||
|
"""
|
||
|
process.stdout.write header
|
||
|
fs = require 'fs'
|
||
|
pl = fs.readFileSync 'package-lock.json'
|
||
|
pdata = JSON.parse pl
|
||
|
for dep in Object.keys pdata.dependencies
|
||
|
if process.argv.length > 2
|
||
|
process.stdout.write "* #{dep}\n"
|
||
|
else
|
||
|
block =
|
||
|
"""
|
||
|
export var #{dep};
|
||
|
export var #{dep}Loaded = new Promise(async function(resolve, reject) {
|
||
|
var success = false;
|
||
|
try {
|
||
|
#{dep} = await import('https://cdn.jsdelivr.net/npm/#{dep}@#{pdata.dependencies[dep].version}/#{importable[dep]}');
|
||
|
console.log('CDN import of #{dep} module OK');
|
||
|
success = true;
|
||
|
} catch(err) {
|
||
|
try {
|
||
|
#{dep} = await import('./node_modules/#{dep}/#{importable[dep]}');
|
||
|
success = true;
|
||
|
} catch(err) {
|
||
|
}
|
||
|
console.log('Used local fallback for #{dep} module');
|
||
|
}
|
||
|
if (success) { resolve(); } else { reject(); }
|
||
|
});
|
||
|
|
||
|
"""
|
||
|
process.stdout.write block
|
||
|
|
||
|
```
|