WIP package-tool

This commit is contained in:
2026-04-04 09:03:01 +02:00
parent 50282fe023
commit 9b58aee54c
5 changed files with 93 additions and 10 deletions

3
.gitignore vendored
View File

@@ -1,2 +1,3 @@
build/
pnpm-workspace.yaml
node_modules/
package-lock.json

View File

@@ -1,8 +1,10 @@
build/:
mkdir -p build
rsync -aP source/ build/
#TODO - we should have a tool that figures out the deps based on manifest for all files so we only need to reprocess files that updated - similar to how gcc can export deps
build/packages:
mkdir -p $@
node tools/stage-for-pnpn.mjs package-manifest.yaml source $@
clean:
rm -rf build
.PHONY: clean
.PHONY: clean build/packages

View File

@@ -1,4 +1,13 @@
scope: '@efforting.tech'
packages:
errors:
path: source/errors.mjs
documentation: documentation/errors
description: Library wide error definitions
version: 0.1.0
wip-packages:
object-graph-storage:
path: source/object-graph-storage
documentation: documentation/object-graph-storage
@@ -11,8 +20,3 @@ packages:
description: Rule based visitors, transformers, resolvers, processors, operators, aggregators and such.
version: 0.1.0
errors:
path: source/errors.mjs
documentation: documentation/errors
description: Library wide error definitions
version: 0.1.0

5
tools/package.json Normal file
View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"yaml": "^2.8.3"
}
}

71
tools/stage-for-pnpn.mjs Normal file
View 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']
}