-
Notifications
You must be signed in to change notification settings - Fork 559
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate fake package.json for electron-builder to resolve modules
- Loading branch information
Showing
3 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env node | ||
|
||
const { existsSync, writeFile } = require("fs"); | ||
const { join } = require("path"); | ||
const { promisify } = require("util"); | ||
|
||
/** | ||
* Generates a fake package.json for given packages that don't have any. | ||
* Allows electron-builder to resolve them | ||
*/ | ||
|
||
const generatePackageJson = async packageName => { | ||
var filepath = join("node_modules", packageName, "package.json"); | ||
if (!existsSync(filepath)) { | ||
console.log( | ||
`No package.json found for ${packageName} module, generating one…` | ||
); | ||
pkg = { | ||
name: packageName, | ||
version: "0.0.0", | ||
description: "-", | ||
repository: { type: "git", url: "-" }, | ||
readme: "-" | ||
}; | ||
const writeFileAsync = promisify(writeFile); | ||
await writeFileAsync(filepath, JSON.stringify(pkg, null, 2)); | ||
} | ||
}; | ||
|
||
if (require.main === module) { | ||
process.argv.slice(2).forEach(async packageName => { | ||
await generatePackageJson(packageName); | ||
}); | ||
} |