11const esbuild = require ( 'esbuild' ) ;
22const { execSync } = require ( 'child_process' ) ;
3- const { readFileSync, writeFileSync } = require ( 'fs' ) ;
3+ const { readFileSync, writeFileSync, existsSync } = require ( 'fs' ) ;
44
55const project = process . env . NX_TASK_TARGET_PROJECT ;
6- const isPublishable = project !== 'testing-utils' ;
7- const projectPath = isPublishable ? `packages/${ project } ` : project ;
6+ const projectPath =
7+ project === 'testing-utils'
8+ ? 'testing-utils'
9+ : project === 'examples-plugins'
10+ ? 'examples/plugins'
11+ : `packages/${ project } ` ;
812
913esbuild . build ( {
1014 plugins : [
@@ -24,44 +28,56 @@ esbuild.build({
2428 } ) ;
2529 } ,
2630 } ,
27- ...( isPublishable
28- ? [
29- {
30- name : 'PackageJSON' ,
31- setup ( build ) {
32- build . onEnd ( result => {
33- if ( result . errors . length > 0 ) return ;
31+ {
32+ name : 'PackageJSON' ,
33+ setup ( build ) {
34+ build . onEnd ( result => {
35+ if ( result . errors . length > 0 ) return ;
36+
37+ if ( ! existsSync ( `${ projectPath } /package.json` ) ) {
38+ /** @type {import('type-fest').PackageJson } */
39+ const newPackageJson = {
40+ name : `@code-pushup/${ project } ` ,
41+ private : true ,
42+ type : 'module' ,
43+ main : 'index.js' ,
44+ types : 'src/index.d.ts' ,
45+ } ;
46+ writeFileSync (
47+ `dist/${ projectPath } /package.json` ,
48+ JSON . stringify ( newPackageJson , null , 2 ) ,
49+ ) ;
50+ return ;
51+ }
3452
35- /** @type {import('type-fest').PackageJson } */
36- const rootPackageJson = JSON . parse (
37- readFileSync ( `${ __dirname } /package.json` ) . toString ( ) ,
38- ) ;
53+ /** @type {import('type-fest').PackageJson } */
54+ const packageJson = JSON . parse (
55+ readFileSync ( `${ projectPath } /package.json` ) . toString ( ) ,
56+ ) ;
3957
40- /** @type {import('type-fest').PackageJson } */
41- const packageJson = JSON . parse (
42- readFileSync ( ` ${ projectPath } / package.json` ) . toString ( ) ,
43- ) ;
58+ /** @type {import('type-fest').PackageJson } */
59+ const rootPackageJson = JSON . parse (
60+ readFileSync ( ' package.json' ) . toString ( ) ,
61+ ) ;
4462
45- packageJson . license = rootPackageJson . license ;
46- packageJson . homepage = rootPackageJson . homepage ;
47- packageJson . bugs = rootPackageJson . bugs ;
48- packageJson . repository = {
49- ...rootPackageJson . repository ,
50- directory : projectPath ,
51- } ;
52- packageJson . contributors = rootPackageJson . contributors ;
53- packageJson . type = 'module' ;
54- packageJson . main = './index.js' ;
55- packageJson . types = './src/index.d.ts' ;
63+ packageJson . license = rootPackageJson . license ;
64+ packageJson . homepage = rootPackageJson . homepage ;
65+ packageJson . bugs = rootPackageJson . bugs ;
66+ packageJson . repository = {
67+ ...rootPackageJson . repository ,
68+ directory : projectPath ,
69+ } ;
70+ packageJson . contributors = rootPackageJson . contributors ;
71+ packageJson . type = 'module' ;
72+ packageJson . main = './index.js' ;
73+ packageJson . types = './src/index.d.ts' ;
5674
57- writeFileSync (
58- `dist/${ projectPath } /package.json` ,
59- JSON . stringify ( packageJson , null , 2 ) ,
60- ) ;
61- } ) ;
62- } ,
63- } ,
64- ]
65- : [ ] ) ,
75+ writeFileSync (
76+ `dist/${ projectPath } /package.json` ,
77+ JSON . stringify ( packageJson , null , 2 ) ,
78+ ) ;
79+ } ) ;
80+ } ,
81+ } ,
6682 ] ,
6783} ) ;
0 commit comments