fix
This commit is contained in:
55
libs/ui/scripts/finalize-generators-dist.cjs
Normal file
55
libs/ui/scripts/finalize-generators-dist.cjs
Normal file
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* `ng-packagr` (el `build`/`package` de `ui`) solo empaqueta lo alcanzable
|
||||
* desde `src/index.ts` — los generadores (`src/generators/`) son Node/Nx
|
||||
* plugin, no Angular, así que ng-packagr los ignora por completo. Este script
|
||||
* los deja listos en `dist/libs/ui/` (ya compilados por
|
||||
* `tsc -p tsconfig.generators.json`, que corre antes que este script) para
|
||||
* que `generators.json` publicado apunte a ficheros que de verdad existen en
|
||||
* el tarball — si no, `nx g @pi/ui:theme` funcionaría dentro de este
|
||||
* monorepo pero fallaría para quien instale el paquete desde el registry.
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const libRoot = path.join(__dirname, '..');
|
||||
const distRoot = path.join(libRoot, '..', '..', 'dist', 'libs', 'ui');
|
||||
|
||||
const sourceManifest = JSON.parse(
|
||||
fs.readFileSync(path.join(libRoot, 'generators.json'), 'utf8'),
|
||||
);
|
||||
|
||||
/** `./src/generators/theme/generator.cts` (fuente) -> `./generators/theme/generator.cjs` (dist). */
|
||||
function toDistPath(sourcePath) {
|
||||
return sourcePath.replace('./src/generators/', './generators/').replace(/\.cts$/, '.cjs');
|
||||
}
|
||||
|
||||
const distManifest = {
|
||||
...sourceManifest,
|
||||
generators: Object.fromEntries(
|
||||
Object.entries(sourceManifest.generators).map(([name, config]) => [
|
||||
name,
|
||||
{
|
||||
...config,
|
||||
factory: toDistPath(config.factory),
|
||||
schema: toDistPath(config.schema),
|
||||
},
|
||||
]),
|
||||
),
|
||||
};
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(distRoot, 'generators.json'),
|
||||
JSON.stringify(distManifest, null, 2) + '\n',
|
||||
);
|
||||
|
||||
for (const { schema } of Object.values(sourceManifest.generators)) {
|
||||
const sourceSchemaPath = path.join(libRoot, schema);
|
||||
const destSchemaPath = path.join(distRoot, toDistPath(schema));
|
||||
fs.mkdirSync(path.dirname(destSchemaPath), { recursive: true });
|
||||
fs.copyFileSync(sourceSchemaPath, destSchemaPath);
|
||||
}
|
||||
|
||||
console.log('✔ generators.json + schemas listos en dist/libs/ui/');
|
||||
Reference in New Issue
Block a user