Skip to content

Commit

Permalink
Generate fake package.json for electron-builder to resolve modules
Browse files Browse the repository at this point in the history
  • Loading branch information
th-ch committed Mar 14, 2020
1 parent 164c314 commit 479013f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 0 additions & 1 deletion electron-builder.env

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"test": "xo",
"start": "electron .",
"icon": "rimraf assets/generated && electron-icon-maker --input=assets/youtube-music.png --output=assets/generated",
"postinstall": "yarn run icon && npm rebuild && node plugins/adblocker/generator.js && electron-rebuild",
"generate:package": "node utils/generate-package-json.js",
"postinstall": "yarn run generate:package YoutubeNonStop && yarn run icon && npm rebuild && node plugins/adblocker/generator.js && electron-rebuild",
"clean": "rimraf dist",
"build": "yarn run clean && build --win --mac --linux",
"build:mac": "yarn run clean && build --mac",
Expand Down
34 changes: 34 additions & 0 deletions utils/generate-package-json.js
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);
});
}

0 comments on commit 479013f

Please sign in to comment.