WIP package-tool
This commit is contained in:
5
tools/package.json
Normal file
5
tools/package.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"yaml": "^2.8.3"
|
||||
}
|
||||
}
|
||||
71
tools/stage-for-pnpn.mjs
Normal file
71
tools/stage-for-pnpn.mjs
Normal file
@@ -0,0 +1,71 @@
|
||||
import { parse as parse_yaml } from 'yaml';
|
||||
import { readFileSync, readdirSync, mkdirSync, symlinkSync, statSync, readlinkSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const [manifest_file, source, output_directory] = process.argv.slice(2);
|
||||
const manifest = parse_yaml(readFileSync(manifest_file, 'utf-8'));
|
||||
|
||||
|
||||
|
||||
//NOTE: For now we will simply symlink files over from source which is fine as long as we are
|
||||
// not preprocecessing source, in that case symlinks would be from the processed items
|
||||
// and rapid iteration becomes trickier,
|
||||
// though of course we can hook up make to a file event watcher.
|
||||
function symlink_tree(src, dest) {
|
||||
mkdirSync(dest, { recursive: true });
|
||||
if (statSync(src).isDirectory()) {
|
||||
for (const entry of readdirSync(src, { withFileTypes: true })) {
|
||||
|
||||
throw new Error('This branch is clanker-suggested and wanted to do absolute symlinks - fix it when needed')
|
||||
|
||||
const src_path = path.resolve(join(src, entry.name));
|
||||
const dest_path = path.join(dest, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
symlink_tree(src_path, dest_path);
|
||||
} else {
|
||||
console.log('NOT IMPLEMENTED SYMLINK', src_path, dest_path);
|
||||
//symlinkSync(src_path, dest_path);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const symlink_dest = path.join(dest, path.basename(src));
|
||||
const symlink_src = path.relative(dest, src);
|
||||
//console.log('SYMLINK', symlink_src, symlink_dest);
|
||||
//TODO: make a utility function for this
|
||||
try {
|
||||
symlinkSync(symlink_src, symlink_dest);
|
||||
} catch (e) {
|
||||
if (e.code === 'EEXIST') {
|
||||
if (readlinkSync(symlink_dest) !== symlink_src) {
|
||||
unlinkSync(symlink_dest);
|
||||
symlinkSync(symlink_src, symlink_dest);
|
||||
}
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return [symlink_dest];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for (const [package_name, package_data] of Object.entries(manifest.packages)) {
|
||||
const pkg = { name: package_name, ...package_data };
|
||||
|
||||
const pkg_dir = path.join(output_directory, pkg.name);
|
||||
const symlinked_files = symlink_tree(pkg.path, pkg_dir).map(p => path.relative(pkg_dir, p));
|
||||
|
||||
const { version, description } = pkg;
|
||||
const pkg_json = JSON.stringify({
|
||||
name: path.join(manifest.scope, pkg.name),
|
||||
version, description,
|
||||
type: 'module',
|
||||
|
||||
}, null, ' ');
|
||||
|
||||
console.log(pkg_json);
|
||||
console.log({symlinked_files}); // ['errors.mjs']
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user