1- import { mkdir , readFile , rm } from "node:fs/promises" ;
2- import { basename } from "node:path" ;
3-
4- import glob from "glob-promise" ;
1+ import { mkdir , rm } from "node:fs/promises" ;
52
63import { decompress } from "./get/decompress.js" ;
74import { download } from "./get/download.js" ;
@@ -11,6 +8,7 @@ import { packager } from "./bld/package.js";
118import { develop } from "./run/develop.js" ;
129import { isCached } from "./util/cache.js" ;
1310import { notify } from "./util/notify.js" ;
11+ import { getOptions } from "./util/options.js" ;
1412import { parse } from "./util/parse.js" ;
1513import { validate } from "./util/validate.js" ;
1614
@@ -81,54 +79,16 @@ import { log } from "./log.js";
8179 */
8280const nwbuild = async ( options ) => {
8381 let nwDir = "" ;
84- let nwPkg = undefined ;
8582 let cached ;
8683 let built ;
8784 let releaseInfo = { } ;
88- notify ( ) ;
89- try {
90- let files = [ ] ;
91- let patterns = options . srcDir . split ( " " ) ;
92-
93- for ( const pattern of patterns ) {
94- let contents = await glob ( pattern ) ;
95- files . push ( ...contents ) ;
96- // Try to find the first instance of the package.json
97- for ( const content of contents ) {
98- if ( basename ( content ) === "package.json" && nwPkg === undefined ) {
99- nwPkg = JSON . parse ( await readFile ( content ) ) ;
100- }
101- }
102-
103- if ( nwPkg === undefined ) {
104- throw new Error ( "package.json not found in srcDir file glob patterns." ) ;
105- }
106- }
107-
108- if ( files . length === 0 ) {
109- throw new Error ( `The globbing pattern ${ options . srcDir } is invalid.` ) ;
110- }
11185
112- // The name property is required for NW.js applications
113- if ( nwPkg . name === undefined ) {
114- throw new Error ( `name property is missing from package.json` ) ;
115- }
86+ notify ( ) ;
11687
117- // The main property is required for NW.js applications
118- if ( nwPkg . main === undefined ) {
119- throw new Error ( `main property is missing from package.json` ) ;
120- }
88+ try {
12189
122- // If the nwbuild property exists in srcDir/package.json, then they take precedence
123- if ( typeof nwPkg . nwbuild === "object" ) {
124- options = { ...nwPkg . nwbuild } ;
125- } else if ( typeof nwPkg . nwbuild === "undefined" ) {
126- log . debug ( `nwbuild property is not defined in package.json` ) ;
127- } else {
128- throw new Error (
129- `nwbuild property in the package.json is of type ${ typeof nwPkg . nwbuild } . Expected type object.` ,
130- ) ;
131- }
90+ const { opts, files, nwPkg } = await getOptions ( options ) ;
91+ options = opts ;
13292
13393 // Parse options, set required values to undefined and flags with default values unless specified by user
13494 options = await parse ( options , nwPkg ) ;
0 commit comments