From 9b58aee54c32613875bcef0f3b8660259eabb0fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20L=C3=B6vqvist?= Date: Sat, 4 Apr 2026 09:03:01 +0200 Subject: [PATCH] WIP package-tool --- .gitignore | 3 +- Makefile | 10 +++--- package-manifest.yaml | 14 +++++--- tools/package.json | 5 +++ tools/stage-for-pnpn.mjs | 71 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 tools/package.json create mode 100644 tools/stage-for-pnpn.mjs diff --git a/.gitignore b/.gitignore index 81a4951..85191cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build/ -pnpm-workspace.yaml \ No newline at end of file +node_modules/ +package-lock.json \ No newline at end of file diff --git a/Makefile b/Makefile index f443eb0..880f07d 100644 --- a/Makefile +++ b/Makefile @@ -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 \ No newline at end of file +.PHONY: clean build/packages \ No newline at end of file diff --git a/package-manifest.yaml b/package-manifest.yaml index 016d1b5..3ce591d 100644 --- a/package-manifest.yaml +++ b/package-manifest.yaml @@ -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 diff --git a/tools/package.json b/tools/package.json new file mode 100644 index 0000000..baeef88 --- /dev/null +++ b/tools/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "yaml": "^2.8.3" + } +} diff --git a/tools/stage-for-pnpn.mjs b/tools/stage-for-pnpn.mjs new file mode 100644 index 0000000..e417ce7 --- /dev/null +++ b/tools/stage-for-pnpn.mjs @@ -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'] + +} \ No newline at end of file