Added resolvers, unified package versioning and author section to fit with mono repo style
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { parse as parse_yaml, stringify as format_yaml } from 'yaml';
|
||||
import { unlinkSync, linkSync, chmodSync, readFileSync, writeFileSync, readdirSync, mkdirSync, symlinkSync, statSync, readlinkSync } from 'node:fs';
|
||||
import { unlinkSync, linkSync, chmodSync, readFileSync, writeFileSync, readdirSync, mkdirSync, statSync, readlinkSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const [manifest_file, source, output_directory] = process.argv.slice(2);
|
||||
@@ -7,49 +7,6 @@ const manifest = parse_yaml(readFileSync(manifest_file, 'utf-8'));
|
||||
|
||||
//TODO: We must test this with a non-single-file type package
|
||||
|
||||
|
||||
//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];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function link_tree(src, dest) {
|
||||
mkdirSync(dest, { recursive: true });
|
||||
if (statSync(src).isDirectory()) {
|
||||
@@ -79,7 +36,7 @@ function link_tree(src, dest) {
|
||||
} else {
|
||||
const link_dest = path.join(dest, path.basename(src));
|
||||
const link_src = src;
|
||||
//console.log('SYMLINK', link_src, link_dest);
|
||||
//console.log('LINK', link_src, link_dest);
|
||||
//TODO: make a utility function for this
|
||||
try {
|
||||
linkSync(link_src, link_dest);
|
||||
@@ -99,26 +56,34 @@ const workspace_manifest = {
|
||||
packages: [],
|
||||
};
|
||||
|
||||
const root_package = {
|
||||
name: path.join(manifest.scope, 'root'),
|
||||
version: '0.1.0', //TODO: Not hardcode? What does this version even represent?
|
||||
const { scope, registry, author, version } = manifest;
|
||||
|
||||
const common_package_data = {
|
||||
author,
|
||||
version,
|
||||
type: 'module',
|
||||
dependencies: {},
|
||||
publishConfig: {
|
||||
registry: 'https://npm.efforting.tech/', //TODO: Get from manifest
|
||||
registry
|
||||
},
|
||||
author: 'mikael-lovqvist', //TODO: Get from manifest
|
||||
};
|
||||
|
||||
const root_package = {
|
||||
name: path.join(scope, 'root'),
|
||||
dependencies: {},
|
||||
...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(manifest.scope, pkg.name);
|
||||
const pkg_scope_path = path.join(scope, pkg.name);
|
||||
workspace_manifest.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));
|
||||
const linked_docs = link_tree(pkg.documentation, pkg_dir).map(p => path.relative(pkg_dir, p));
|
||||
// Docs are optional for now
|
||||
const linked_docs = pkg.documentation ? link_tree(pkg.documentation, pkg_dir).map(p => path.relative(pkg_dir, p)) : [];
|
||||
//console.log('DOCS', { linked_docs });
|
||||
|
||||
const exports_map = {};
|
||||
@@ -128,16 +93,12 @@ for (const [package_name, package_data] of Object.entries(manifest.packages)) {
|
||||
exports_map[key] = `./${file}`;
|
||||
}
|
||||
|
||||
const { version, description } = pkg;
|
||||
const { description } = pkg;
|
||||
const pkg_json = JSON.stringify({
|
||||
name: pkg_scope_path,
|
||||
version, description,
|
||||
type: 'module',
|
||||
description,
|
||||
exports: exports_map,
|
||||
author: 'mikael-lovqvist', //TODO: Get from manifest
|
||||
publishConfig: {
|
||||
registry: 'https://npm.efforting.tech/', //TODO: Get from manifest
|
||||
},
|
||||
...common_package_data,
|
||||
}, null, ' ');
|
||||
|
||||
writeFileSync(path.join(pkg_dir, 'package.json'), pkg_json, 'utf-8');
|
||||
|
||||
Reference in New Issue
Block a user