Updated install and packaging script

This commit is contained in:
2026-04-12 01:11:43 +02:00
parent 8442383fc3
commit c903e7bfa0
3 changed files with 33 additions and 25 deletions

View File

@@ -1,9 +0,0 @@
{
"name": "experiments",
"type": "module",
"dependencies": {
"@efforting.tech/errors": "link:../build/packages/errors",
"@efforting.tech/rule-processing": "link:../build/packages/rule-processing",
"@efforting.tech/data": "link:../build/packages/data"
}
}

View File

@@ -1,5 +0,0 @@
{
"dependencies": {
"experiments": "^0.3.0"
}
}

View File

@@ -52,9 +52,7 @@ function link_tree(src, dest) {
} }
} }
const workspace_manifest = { const published_packages = [];
packages: [],
};
const { scope, registry, author, version } = manifest; const { scope, registry, author, version } = manifest;
@@ -68,17 +66,24 @@ const common_package_data = {
}; };
const root_package = { const root_package = {
name: path.join(scope, 'root'), name: path.join(scope, '_root'),
dependencies: {}, dependencies: {},
private: true,
...common_package_data, ...common_package_data,
}; };
const local_dev_package = {
name: path.join(scope, '_dev'),
dependencies: {},
private: true,
...common_package_data,
};
for (const [package_name, package_data] of Object.entries(manifest.packages)) { for (const [package_name, package_data] of Object.entries(manifest.packages)) {
const pkg = { name: package_name, ...package_data }; const pkg = { name: package_name, ...package_data };
const pkg_scope_path = path.join(scope, pkg.name); const pkg_scope_path = path.join(scope, pkg.name);
workspace_manifest.packages.push(pkg.name); published_packages.push(pkg.name);
const pkg_dir = path.join(output_directory, pkg.name); const pkg_dir = path.join(output_directory, pkg.name);
const linked_sources = link_tree(pkg.path, pkg_dir).map(p => path.relative(pkg_dir, p)); const linked_sources = link_tree(pkg.path, pkg_dir).map(p => path.relative(pkg_dir, p));
@@ -116,20 +121,26 @@ for (const [package_name, package_data] of Object.entries(manifest.packages)) {
writeFileSync(path.join(pkg_dir, 'package.json'), pkg_json, 'utf-8'); writeFileSync(path.join(pkg_dir, 'package.json'), pkg_json, 'utf-8');
//console.log({linked_sources}); // ['errors.mjs'] //console.log({linked_sources}); // ['errors.mjs']
root_package.dependencies[pkg_scope_path] = version;
} }
const root_pkg_json = JSON.stringify(root_package, null, ' ');
writeFileSync(path.join(output_directory, 'package.json'), root_pkg_json, 'utf-8');
writeFileSync(path.join(output_directory, 'pnpm-workspace.yaml'), format_yaml(workspace_manifest), 'utf-8');
const publish_tool = 'pnpm publish --no-git-checks'; //const publish_tool = 'pnpm publish --no-git-checks';
const publish_script_lines = workspace_manifest.packages.map( const publish_tool = 'npm publish';
const publish_script_lines = published_packages.map(
pkg => `${publish_tool} ${pkg}` pkg => `${publish_tool} ${pkg}`
); );
const dev_stage_script_lines = published_packages.map(
pkg => `ln -sf "${path.resolve(output_directory, pkg)}" "${path.resolve(output_directory, 'node_modules', path.join(scope, pkg))}"`
);
const dev_stage_mkdir_lines = [...new Set(published_packages.map(
pkg => `mkdir -p "${path.dirname(path.resolve(output_directory, 'node_modules', path.join(scope, pkg)))}"`
))];
const publish_script = ( const publish_script = (
'#!/usr/bin/env bash\n' + '#!/usr/bin/env bash\n' +
@@ -137,8 +148,19 @@ const publish_script = (
`${publish_script_lines.join('\n')}\n` `${publish_script_lines.join('\n')}\n`
); );
const dev_stage_script = (
'#!/usr/bin/env bash\n' +
'set -e\n' +
`${dev_stage_mkdir_lines.join('\n')}\n` +
`${dev_stage_script_lines.join('\n')}\n`
);
const publish_script_path = path.join(output_directory, 'publish-all.sh'); const publish_script_path = path.join(output_directory, 'publish-all.sh');
const dev_stage_script_path = path.join(output_directory, 'local-install.sh');
writeFileSync(publish_script_path, publish_script, 'utf-8'); writeFileSync(publish_script_path, publish_script, 'utf-8');
writeFileSync(dev_stage_script_path, dev_stage_script, 'utf-8');
chmodSync(publish_script_path, 0o755); chmodSync(publish_script_path, 0o755);
chmodSync(dev_stage_script_path, 0o755);