1
+ /* eslint-disable no-unused-vars */
1
2
/* eslint-disable no-console */
2
- const path = require ( ' path' ) ;
3
- const fse = require ( ' fs-extra' ) ;
4
- const glob = require ( ' fast-glob' ) ;
3
+ const path = require ( " path" ) ;
4
+ const fse = require ( " fs-extra" ) ;
5
+ const glob = require ( " fast-glob" ) ;
5
6
6
7
const packagePath = process . cwd ( ) ;
7
- const buildPath = path . join ( packagePath , ' ./dist' ) ;
8
- const srcPath = path . join ( packagePath , ' ./src' ) ;
8
+ const buildPath = path . join ( packagePath , " ./dist" ) ;
9
+ const srcPath = path . join ( packagePath , " ./src" ) ;
9
10
10
11
async function createModulePackages ( { from, to } ) {
11
12
const directoryPackages = glob
12
- . sync ( ' */index.{js,ts,tsx}' , { cwd : from } )
13
+ . sync ( " */index.{js,ts,tsx}" , { cwd : from } )
13
14
. map ( path . dirname ) ;
14
15
15
16
await Promise . all (
16
17
directoryPackages . map ( async ( directoryPackage ) => {
17
- const packageJsonPath = path . join ( to , directoryPackage , ' package.json' ) ;
18
+ const packageJsonPath = path . join ( to , directoryPackage , " package.json" ) ;
18
19
19
20
const packageJson = {
20
21
sideEffects : false ,
21
- module : ' ./index.js' ,
22
- main : ' ./index.js' ,
23
- types : ' ./index.d.ts' ,
22
+ module : " ./index.js" ,
23
+ main : " ./index.js" ,
24
+ types : " ./index.d.ts" ,
24
25
} ;
25
26
26
27
const [ typingsEntryExist , moduleEntryExists , mainEntryExists ] = await Promise . all ( [
@@ -55,7 +56,7 @@ async function createModulePackages({ from, to }) {
55
56
if ( manifestErrorMessages . length > 0 ) {
56
57
// TODO: AggregateError
57
58
throw new Error (
58
- `${ packageJsonPath } :\n${ manifestErrorMessages . join ( '\n' ) } ` ,
59
+ `${ packageJsonPath } :\n${ manifestErrorMessages . join ( "\n" ) } ` ,
59
60
) ;
60
61
}
61
62
@@ -64,7 +65,7 @@ async function createModulePackages({ from, to }) {
64
65
) ;
65
66
}
66
67
67
- const packageIncludes = [ ' expressionparser' , ' @babel/runtime' , ' lodash.isequal' ] ;
68
+ const packageIncludes = [ " expressionparser" , " @babel/runtime" , " lodash.isequal" , "react-dnd" , "react-dnd-html5-backend" ] ;
68
69
69
70
async function includeFileInBuild ( file ) {
70
71
const sourcePath = path . resolve ( packagePath , file ) ;
@@ -88,11 +89,15 @@ async function includeFileInBuild(file) {
88
89
89
90
async function createPackageFile ( ) {
90
91
const packageData = await fse . readFile (
91
- path . resolve ( packagePath , ' ./package.json' ) ,
92
- ' utf8' ,
92
+ path . resolve ( packagePath , " ./package.json" ) ,
93
+ " utf8" ,
93
94
) ;
94
95
const {
95
- nyc, scripts, devDependencies, workspaces, ...packageDataOther
96
+ nyc,
97
+ scripts,
98
+ devDependencies,
99
+ workspaces,
100
+ ...packageDataOther
96
101
} = JSON . parse ( packageData ) ;
97
102
98
103
const { dependencies } = packageDataOther ;
@@ -105,30 +110,30 @@ async function createPackageFile() {
105
110
private : false ,
106
111
...( packageDataOther . main
107
112
? {
108
- main : ' ./index.js' ,
109
- module : ' ./index.js' ,
113
+ main : " ./index.js" ,
114
+ module : " ./index.js" ,
110
115
}
111
116
: { } ) ,
112
- types : ' ./index.d.ts' ,
117
+ types : " ./index.d.ts" ,
113
118
} ;
114
119
115
120
delete newPackageData . files ;
116
121
117
- const targetPath = path . resolve ( buildPath , ' ./package.json' ) ;
122
+ const targetPath = path . resolve ( buildPath , " ./package.json" ) ;
118
123
119
124
await fse . writeFile (
120
125
targetPath ,
121
126
JSON . stringify ( newPackageData , null , 2 ) ,
122
- ' utf8' ,
127
+ " utf8" ,
123
128
) ;
124
129
console . log ( `Created package.json in ${ targetPath } ` ) ;
125
130
126
131
return newPackageData ;
127
132
}
128
133
129
134
async function prepend ( file , string ) {
130
- const data = await fse . readFile ( file , ' utf8' ) ;
131
- await fse . writeFile ( file , string + data , ' utf8' ) ;
135
+ const data = await fse . readFile ( file , " utf8" ) ;
136
+ await fse . writeFile ( file , string + data , " utf8" ) ;
132
137
}
133
138
134
139
async function addLicense ( packageData ) {
@@ -139,11 +144,11 @@ async function addLicense(packageData) {
139
144
*/
140
145
` ;
141
146
await Promise . all (
142
- [ ' ./index.js' ] . map ( async ( file ) => {
147
+ [ " ./index.js" ] . map ( async ( file ) => {
143
148
try {
144
149
await prepend ( path . resolve ( buildPath , file ) , license ) ;
145
150
} catch ( err ) {
146
- if ( err . code === ' ENOENT' ) {
151
+ if ( err . code === " ENOENT" ) {
147
152
console . log ( `Skipped license for ${ file } ` ) ;
148
153
} else {
149
154
throw err ;
@@ -159,7 +164,7 @@ async function run() {
159
164
160
165
await Promise . all (
161
166
[
162
- ' ./README.md' ,
167
+ " ./README.md" ,
163
168
// './CHANGELOG.md',
164
169
// './LICENSE',
165
170
] . map ( ( file ) => includeFileInBuild ( file ) ) ,
0 commit comments