Updated install and packaging script
This commit is contained in:
@@ -52,9 +52,7 @@ function link_tree(src, dest) {
|
||||
}
|
||||
}
|
||||
|
||||
const workspace_manifest = {
|
||||
packages: [],
|
||||
};
|
||||
const published_packages = [];
|
||||
|
||||
const { scope, registry, author, version } = manifest;
|
||||
|
||||
@@ -68,17 +66,24 @@ const common_package_data = {
|
||||
};
|
||||
|
||||
const root_package = {
|
||||
name: path.join(scope, 'root'),
|
||||
name: path.join(scope, '_root'),
|
||||
dependencies: {},
|
||||
private: true,
|
||||
...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)) {
|
||||
const pkg = { name: package_name, ...package_data };
|
||||
|
||||
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 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');
|
||||
//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_script_lines = workspace_manifest.packages.map(
|
||||
//const publish_tool = 'pnpm publish --no-git-checks';
|
||||
const publish_tool = 'npm publish';
|
||||
const publish_script_lines = published_packages.map(
|
||||
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 = (
|
||||
'#!/usr/bin/env bash\n' +
|
||||
@@ -137,8 +148,19 @@ const publish_script = (
|
||||
`${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 dev_stage_script_path = path.join(output_directory, 'local-install.sh');
|
||||
writeFileSync(publish_script_path, publish_script, 'utf-8');
|
||||
writeFileSync(dev_stage_script_path, dev_stage_script, 'utf-8');
|
||||
chmodSync(publish_script_path, 0o755);
|
||||
chmodSync(dev_stage_script_path, 0o755);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user