init
This commit is contained in:
commit
1932890f49
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
dist
|
BIN
assets/background.png
Normal file
BIN
assets/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
255
main.js
Normal file
255
main.js
Normal file
@ -0,0 +1,255 @@
|
||||
const {app, screen, shell, BrowserWindow, BrowserView, ipcMain, dialog, clipboard } = require('electron')
|
||||
const Store = require('electron-store');
|
||||
const windowStateKeeper = require('electron-window-state');
|
||||
const fs = require('fs')
|
||||
const path = require("path")
|
||||
const Pinokiod = require("pinokiod")
|
||||
const is_mac = process.platform.startsWith("darwin")
|
||||
var mainWindow;
|
||||
var root_url;
|
||||
var wins = {}
|
||||
var pinned = {}
|
||||
var launched
|
||||
const PORT = 4200
|
||||
const store = new Store();
|
||||
const pinokiod = new Pinokiod({
|
||||
port: PORT,
|
||||
agent: "electron",
|
||||
store
|
||||
})
|
||||
const titleBarOverlay = (theme) => {
|
||||
if (is_mac) {
|
||||
return false
|
||||
} else {
|
||||
if (theme === "dark") {
|
||||
return {
|
||||
color: "#111",
|
||||
symbolColor: "white"
|
||||
}
|
||||
} else if (theme === "default") {
|
||||
if (launched) {
|
||||
return {
|
||||
color: "#F5F4FA",
|
||||
symbolColor: "black"
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
color: "royalblue",
|
||||
symbolColor: "white"
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
color: "white",
|
||||
symbolColor: "black"
|
||||
}
|
||||
}
|
||||
}
|
||||
const attach = (event, webContents) => {
|
||||
let wc = webContents
|
||||
webContents.on('will-navigate', (event, url) => {
|
||||
if (!webContents.opened) {
|
||||
// The first time this view is being used, set the "opened" to true, and don't do anything
|
||||
// The next time the view navigates, "the "opened" is already true, so trigger the URL open logic
|
||||
// - if the new URL has the same host as the app's url, open in app
|
||||
// - if it's a remote host, open in external browser
|
||||
webContents.opened = true
|
||||
} else {
|
||||
let host = new URL(url).host
|
||||
let localhost = new URL(root_url).host
|
||||
if (host !== localhost) {
|
||||
event.preventDefault()
|
||||
shell.openExternal(url);
|
||||
}
|
||||
}
|
||||
})
|
||||
// webContents.on("did-create-window", (parentWindow, details) => {
|
||||
// const view = new BrowserView();
|
||||
// parentWindow.setBrowserView(view);
|
||||
// view.setBounds({ x: 0, y: 30, width: parentWindow.getContentBounds().width, height: parentWindow.getContentBounds().height - 30 });
|
||||
// view.setAutoResize({ width: true, height: true });
|
||||
// view.webContents.loadURL(details.url);
|
||||
// })
|
||||
webContents.on('did-navigate', (event, url) => {
|
||||
let win = webContents.getOwnerBrowserWindow()
|
||||
if (win && win.setTitleBarOverlay && typeof win.setTitleBarOverlay === "function") {
|
||||
const overlay = titleBarOverlay("default")
|
||||
win.setTitleBarOverlay(overlay)
|
||||
}
|
||||
launched = true
|
||||
|
||||
})
|
||||
webContents.setWindowOpenHandler((config) => {
|
||||
let url = config.url
|
||||
let features = config.features
|
||||
let params = new URLSearchParams(features.split(",").join("&"))
|
||||
let win = wc.getOwnerBrowserWindow()
|
||||
let [width, height] = win.getSize()
|
||||
let [x,y] = win.getPosition()
|
||||
|
||||
if (features) {
|
||||
if (features.startsWith("app") || features.startsWith("self")) {
|
||||
return {
|
||||
action: 'allow',
|
||||
outlivesOpener: true,
|
||||
overrideBrowserWindowOptions: {
|
||||
width: (params.get("width") ? parseInt(params.get("width")) : width),
|
||||
height: (params.get("height") ? parseInt(params.get("height")) : height),
|
||||
x: x + 30,
|
||||
y: y + 30,
|
||||
|
||||
parent: null,
|
||||
titleBarStyle : "hidden",
|
||||
titleBarOverlay : titleBarOverlay("default"),
|
||||
}
|
||||
}
|
||||
} else if (features.startsWith("file")) {
|
||||
let u = features.replace("file://", "")
|
||||
shell.showItemInFolder(u)
|
||||
return { action: 'deny' };
|
||||
} else {
|
||||
return { action: 'deny' };
|
||||
}
|
||||
} else {
|
||||
shell.openExternal(url);
|
||||
return { action: 'deny' };
|
||||
}
|
||||
});
|
||||
}
|
||||
const getWinState = (url, options) => {
|
||||
let filename
|
||||
try {
|
||||
let pathname = new URL(url).pathname.slice(1)
|
||||
filename = pathname.slice("/").join("-")
|
||||
} catch {
|
||||
filename = "index.json"
|
||||
}
|
||||
let state = windowStateKeeper({
|
||||
file: filename,
|
||||
...options
|
||||
});
|
||||
return state
|
||||
}
|
||||
const createWindow = (port) => {
|
||||
|
||||
|
||||
let mainWindowState = windowStateKeeper({
|
||||
// file: "index.json",
|
||||
defaultWidth: 1000,
|
||||
defaultHeight: 800
|
||||
});
|
||||
|
||||
mainWindow = new BrowserWindow({
|
||||
titleBarStyle : "hidden",
|
||||
titleBarOverlay : titleBarOverlay("default"),
|
||||
x: mainWindowState.x,
|
||||
y: mainWindowState.y,
|
||||
width: mainWindowState.width,
|
||||
height: mainWindowState.height,
|
||||
minWidth: 190,
|
||||
webPreferences: {
|
||||
nativeWindowOpen: true
|
||||
// preload: path.join(__dirname, 'preload.js')
|
||||
},
|
||||
})
|
||||
root_url = `http://localhost:${port}`
|
||||
mainWindow.loadURL(root_url)
|
||||
// mainWindow.maximize();
|
||||
mainWindowState.manage(mainWindow);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (process.defaultApp) {
|
||||
if (process.argv.length >= 2) {
|
||||
app.setAsDefaultProtocolClient('pinokio', process.execPath, [path.resolve(process.argv[1])])
|
||||
}
|
||||
} else {
|
||||
app.setAsDefaultProtocolClient('pinokio')
|
||||
}
|
||||
|
||||
const gotTheLock = app.requestSingleInstanceLock()
|
||||
|
||||
if (!gotTheLock) {
|
||||
app.quit()
|
||||
} else {
|
||||
app.on('second-instance', (event, argv) => {
|
||||
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore()
|
||||
mainWindow.focus()
|
||||
}
|
||||
let url = argv.pop()
|
||||
let u = new URL(url).search
|
||||
mainWindow.loadURL(`${root_url}${u}`)
|
||||
})
|
||||
|
||||
// Create mainWindow, load the rest of the app, etc...
|
||||
app.whenReady().then(async () => {
|
||||
const WIDTH = 300;
|
||||
const HEIGHT = 300;
|
||||
let bounds = screen.getPrimaryDisplay().bounds;
|
||||
let x = Math.ceil(bounds.x + ((bounds.width - WIDTH) / 2));
|
||||
let y = Math.ceil(bounds.y + ((bounds.height - HEIGHT) / 2));
|
||||
|
||||
|
||||
// splash window
|
||||
const splash = new BrowserWindow({
|
||||
width: WIDTH,
|
||||
height: HEIGHT,
|
||||
// transparent: true,
|
||||
frame: false,
|
||||
alwaysOnTop: true,
|
||||
x,
|
||||
y,
|
||||
show: false
|
||||
});
|
||||
splash.type = "splash"
|
||||
splash.loadFile('splash.html');
|
||||
splash.once('ready-to-show', () => {
|
||||
splash.show()
|
||||
})
|
||||
|
||||
await pinokiod.start(PORT)
|
||||
splash.hide();
|
||||
|
||||
app.on('web-contents-created', attach)
|
||||
app.on('activate', function () {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow(PORT)
|
||||
})
|
||||
app.on('window-all-closed', function () {
|
||||
if (process.platform !== 'darwin') app.quit()
|
||||
})
|
||||
app.on('browser-window-created', (event, win) => {
|
||||
if (win.type !== "splash") {
|
||||
if (win.setTitleBarOverlay) {
|
||||
const overlay = titleBarOverlay("default")
|
||||
try {
|
||||
win.setTitleBarOverlay(overlay)
|
||||
} catch (e) {
|
||||
// console.log("ERROR", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
let all = BrowserWindow.getAllWindows()
|
||||
for(win of all) {
|
||||
try {
|
||||
if (win.setTitleBarOverlay) {
|
||||
const overlay = titleBarOverlay("default")
|
||||
win.setTitleBarOverlay(overlay)
|
||||
}
|
||||
} catch (e) {
|
||||
// console.log("E2", e)
|
||||
}
|
||||
}
|
||||
createWindow(PORT)
|
||||
splash.close();
|
||||
})
|
||||
|
||||
app.on('open-url', (event, url) => {
|
||||
let u = new URL(url).search
|
||||
mainWindow.loadURL(`${root_url}${u}`)
|
||||
})
|
||||
}
|
6117
package-lock.json
generated
Normal file
6117
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
115
package.json
Normal file
115
package.json
Normal file
@ -0,0 +1,115 @@
|
||||
{
|
||||
"name": "Pinokio",
|
||||
"version": "0.0.18",
|
||||
"homepage": "https://pinokio.computer",
|
||||
"description": "pinokio",
|
||||
"main": "main.js",
|
||||
"email": "cocktailpeanuts@proton.me",
|
||||
"author": "https://twitter.com/cocktailpeanut",
|
||||
"scripts": {
|
||||
"start": "electron .",
|
||||
"pack": "./node_modules/.bin/electron-builder --dir",
|
||||
"dist": "npm run monkeypatch && export SNAPCRAFT_BUILD_ENVIRONMENT=host && export SNAP_DESTRUCTIVE_MODE='true' && ./node_modules/.bin/electron-builder -mwl && npm run zip",
|
||||
"zip": "node script/zip",
|
||||
"monkeypatch": "cp temp/yarn.js node_modules/app-builder-lib/out/util/yarn.js && cp temp/rebuild.js node_modules/@electron/rebuild/lib/src/rebuild.js",
|
||||
"postinstall": "npm run monkeypatch && ./node_modules/.bin/electron-builder install-app-deps"
|
||||
},
|
||||
"build": {
|
||||
"appId": "computer.pinokio",
|
||||
"asarUnpack": [
|
||||
"node_modules/7zip-bin/**/*",
|
||||
"node_modules/node-pty-prebuilt-multiarch-cp/**/*"
|
||||
],
|
||||
"extraResources": [
|
||||
"./script/**"
|
||||
],
|
||||
"protocols": [
|
||||
{
|
||||
"name": "pinokio",
|
||||
"schemes": [
|
||||
"pinokio"
|
||||
]
|
||||
}
|
||||
],
|
||||
"dmg": {
|
||||
"background": "./assets/background.png",
|
||||
"contents": [
|
||||
{
|
||||
"x": 130,
|
||||
"y": 250
|
||||
},
|
||||
{
|
||||
"x": 410,
|
||||
"y": 80,
|
||||
"type": "file",
|
||||
"path": "./script/patch.command"
|
||||
},
|
||||
{
|
||||
"x": 410,
|
||||
"y": 250,
|
||||
"type": "link",
|
||||
"path": "/Applications"
|
||||
}
|
||||
]
|
||||
},
|
||||
"mac": {
|
||||
"category": "utility",
|
||||
"target": [
|
||||
{
|
||||
"target": "default",
|
||||
"arch": [
|
||||
"x64",
|
||||
"arm64"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux": {
|
||||
"maintainer": "Cocktail Peanut <cocktailpeanuts@proton.me>",
|
||||
"target": [
|
||||
{
|
||||
"target": "deb",
|
||||
"arch": [
|
||||
"x64",
|
||||
"arm64"
|
||||
]
|
||||
},
|
||||
{
|
||||
"target": "rpm",
|
||||
"arch": [
|
||||
"x64",
|
||||
"arm64"
|
||||
]
|
||||
},
|
||||
{
|
||||
"target": "AppImage",
|
||||
"arch": [
|
||||
"x64",
|
||||
"arm64"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"win": {
|
||||
"target": [
|
||||
{
|
||||
"target": "nsis",
|
||||
"arch": [
|
||||
"x64"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"electron-store": "^8.1.0",
|
||||
"electron-window-state": "^5.0.3",
|
||||
"pinokiod": "^0.0.144"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@electron/rebuild": "3.2.10",
|
||||
"electron": "^23.1.2",
|
||||
"electron-builder": "^24.0.0"
|
||||
}
|
||||
}
|
1
script/patch.command
Executable file
1
script/patch.command
Executable file
@ -0,0 +1 @@
|
||||
sudo -s xattr -r -d com.apple.quarantine /Applications/Pinokio.app
|
20
script/zip.js
Normal file
20
script/zip.js
Normal file
@ -0,0 +1,20 @@
|
||||
const { exec } = require('child_process');
|
||||
const path = require('path')
|
||||
const version = process.env.npm_package_version
|
||||
|
||||
// Replace "ls -l" with your desired terminal command
|
||||
const command = 'ls -l';
|
||||
|
||||
let exePath = path.resolve(__dirname, `../dist/Pinokio Setup ${version}.exe`)
|
||||
let zipPath = path.resolve(__dirname, `../dist/Pinokio-${version}-win32.zip`)
|
||||
exec(`zip -j "${zipPath}" "${exePath}"`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`Error executing command: ${error}`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Command executed successfully.');
|
||||
console.log('stdout:', stdout);
|
||||
console.log('stderr:', stderr);
|
||||
});
|
||||
|
112
splash.html
Normal file
112
splash.html
Normal file
@ -0,0 +1,112 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
body {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: royalblue;
|
||||
}
|
||||
.loader {
|
||||
|
||||
height: 5px;
|
||||
width: 5px;
|
||||
color: #fff;
|
||||
box-shadow: -10px -10px 0 5px,
|
||||
-10px -10px 0 5px,
|
||||
-10px -10px 0 5px,
|
||||
-10px -10px 0 5px;
|
||||
animation: loader-38 6s infinite;
|
||||
}
|
||||
|
||||
@keyframes loader-38 {
|
||||
0% {
|
||||
box-shadow: -10px -10px 0 5px,
|
||||
-10px -10px 0 5px,
|
||||
-10px -10px 0 5px,
|
||||
-10px -10px 0 5px;
|
||||
}
|
||||
8.33% {
|
||||
box-shadow: -10px -10px 0 5px,
|
||||
10px -10px 0 5px,
|
||||
10px -10px 0 5px,
|
||||
10px -10px 0 5px;
|
||||
}
|
||||
16.66% {
|
||||
box-shadow: -10px -10px 0 5px,
|
||||
10px -10px 0 5px,
|
||||
10px 10px 0 5px,
|
||||
10px 10px 0 5px;
|
||||
}
|
||||
24.99% {
|
||||
box-shadow: -10px -10px 0 5px,
|
||||
10px -10px 0 5px,
|
||||
10px 10px 0 5px,
|
||||
-10px 10px 0 5px;
|
||||
}
|
||||
33.32% {
|
||||
box-shadow: -10px -10px 0 5px,
|
||||
10px -10px 0 5px,
|
||||
10px 10px 0 5px,
|
||||
-10px -10px 0 5px;
|
||||
}
|
||||
41.65% {
|
||||
box-shadow: 10px -10px 0 5px,
|
||||
10px -10px 0 5px,
|
||||
10px 10px 0 5px,
|
||||
10px -10px 0 5px;
|
||||
}
|
||||
49.98% {
|
||||
box-shadow: 10px 10px 0 5px,
|
||||
10px 10px 0 5px,
|
||||
10px 10px 0 5px,
|
||||
10px 10px 0 5px;
|
||||
}
|
||||
58.31% {
|
||||
box-shadow: -10px 10px 0 5px,
|
||||
-10px 10px 0 5px,
|
||||
10px 10px 0 5px,
|
||||
-10px 10px 0 5px;
|
||||
}
|
||||
66.64% {
|
||||
box-shadow: -10px -10px 0 5px,
|
||||
-10px -10px 0 5px,
|
||||
10px 10px 0 5px,
|
||||
-10px 10px 0 5px;
|
||||
}
|
||||
74.97% {
|
||||
box-shadow: -10px -10px 0 5px,
|
||||
10px -10px 0 5px,
|
||||
10px 10px 0 5px,
|
||||
-10px 10px 0 5px;
|
||||
}
|
||||
83.3% {
|
||||
box-shadow: -10px -10px 0 5px,
|
||||
10px 10px 0 5px,
|
||||
10px 10px 0 5px,
|
||||
-10px 10px 0 5px;
|
||||
}
|
||||
91.63% {
|
||||
box-shadow: -10px -10px 0 5px,
|
||||
-10px 10px 0 5px,
|
||||
-10px 10px 0 5px,
|
||||
-10px 10px 0 5px;
|
||||
}
|
||||
100% {
|
||||
box-shadow: -10px -10px 0 5px,
|
||||
-10px -10px 0 5px,
|
||||
-10px -10px 0 5px,
|
||||
-10px -10px 0 5px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<span class="loader"></span>
|
||||
</body>
|
||||
</html>
|
169
temp/rebuild.js
Normal file
169
temp/rebuild.js
Normal file
@ -0,0 +1,169 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.rebuild = exports.Rebuilder = void 0;
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const events_1 = require("events");
|
||||
const fs = __importStar(require("fs-extra"));
|
||||
const nodeAbi = __importStar(require("node-abi"));
|
||||
const os = __importStar(require("os"));
|
||||
const path = __importStar(require("path"));
|
||||
const cache_1 = require("./cache");
|
||||
const types_1 = require("./types");
|
||||
const module_rebuilder_1 = require("./module-rebuilder");
|
||||
const module_walker_1 = require("./module-walker");
|
||||
const d = (0, debug_1.default)('electron-rebuild');
|
||||
const defaultMode = 'sequential';
|
||||
const defaultTypes = ['prod', 'optional'];
|
||||
class Rebuilder {
|
||||
constructor(options) {
|
||||
console.log("options", options)
|
||||
var _a;
|
||||
this.platform = options.platform || process.platform;
|
||||
this.lifecycle = options.lifecycle;
|
||||
this.buildPath = options.buildPath;
|
||||
this.electronVersion = options.electronVersion;
|
||||
this.arch = options.arch || process.arch;
|
||||
this.force = options.force || false;
|
||||
this.headerURL = options.headerURL || 'https://www.electronjs.org/headers';
|
||||
this.mode = options.mode || defaultMode;
|
||||
this.debug = options.debug || false;
|
||||
this.useCache = options.useCache || false;
|
||||
this.useElectronClang = options.useElectronClang || false;
|
||||
this.cachePath = options.cachePath || path.resolve(os.homedir(), '.electron-rebuild-cache');
|
||||
this.prebuildTagPrefix = options.prebuildTagPrefix || 'v';
|
||||
this.msvsVersion = process.env.GYP_MSVS_VERSION;
|
||||
this.disablePreGypCopy = options.disablePreGypCopy || false;
|
||||
if (this.useCache && this.force) {
|
||||
console.warn('[WARNING]: Electron Rebuild has force enabled and cache enabled, force take precedence and the cache will not be used.');
|
||||
this.useCache = false;
|
||||
}
|
||||
if (typeof this.electronVersion === 'number') {
|
||||
if (`${this.electronVersion}`.split('.').length === 1) {
|
||||
this.electronVersion = `${this.electronVersion}.0.0`;
|
||||
}
|
||||
else {
|
||||
this.electronVersion = `${this.electronVersion}.0`;
|
||||
}
|
||||
}
|
||||
if (typeof this.electronVersion !== 'string') {
|
||||
throw new Error(`Expected a string version for electron version, got a "${typeof this.electronVersion}"`);
|
||||
}
|
||||
this.ABIVersion = (_a = options.forceABI) === null || _a === void 0 ? void 0 : _a.toString();
|
||||
const onlyModules = options.onlyModules || null;
|
||||
const extraModules = (options.extraModules || []).reduce((acc, x) => acc.add(x), new Set());
|
||||
const types = options.types || defaultTypes;
|
||||
this.moduleWalker = new module_walker_1.ModuleWalker(this.buildPath, options.projectRootPath, types, extraModules, onlyModules);
|
||||
this.rebuilds = [];
|
||||
d('rebuilding with args:', this.buildPath, this.electronVersion, this.arch, extraModules, this.force, this.headerURL, types, this.debug);
|
||||
console.log("THIS>PLATFORM", this.platform)
|
||||
}
|
||||
get ABI() {
|
||||
if (this.ABIVersion === undefined) {
|
||||
this.ABIVersion = nodeAbi.getAbi(this.electronVersion, 'electron');
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
return this.ABIVersion;
|
||||
}
|
||||
get buildType() {
|
||||
return this.debug ? types_1.BuildType.Debug : types_1.BuildType.Release;
|
||||
}
|
||||
async rebuild() {
|
||||
if (!path.isAbsolute(this.buildPath)) {
|
||||
throw new Error('Expected buildPath to be an absolute path');
|
||||
}
|
||||
this.lifecycle.emit('start');
|
||||
await this.moduleWalker.walkModules();
|
||||
for (const nodeModulesPath of await this.moduleWalker.nodeModulesPaths) {
|
||||
await this.moduleWalker.findAllModulesIn(nodeModulesPath);
|
||||
}
|
||||
for (const modulePath of this.moduleWalker.modulesToRebuild) {
|
||||
this.rebuilds.push(() => this.rebuildModuleAt(modulePath));
|
||||
}
|
||||
this.rebuilds.push(() => this.rebuildModuleAt(this.buildPath));
|
||||
if (this.mode !== 'sequential') {
|
||||
await Promise.all(this.rebuilds.map(fn => fn()));
|
||||
}
|
||||
else {
|
||||
for (const rebuildFn of this.rebuilds) {
|
||||
await rebuildFn();
|
||||
}
|
||||
}
|
||||
}
|
||||
async rebuildModuleAt(modulePath) {
|
||||
if (!(await fs.pathExists(path.resolve(modulePath, 'binding.gyp')))) {
|
||||
return;
|
||||
}
|
||||
const moduleRebuilder = new module_rebuilder_1.ModuleRebuilder(this, modulePath);
|
||||
this.lifecycle.emit('module-found', path.basename(modulePath));
|
||||
if (!this.force && await moduleRebuilder.alreadyBuiltByRebuild()) {
|
||||
d(`skipping: ${path.basename(modulePath)} as it is already built`);
|
||||
this.lifecycle.emit('module-done');
|
||||
this.lifecycle.emit('module-skip');
|
||||
return;
|
||||
}
|
||||
if (await moduleRebuilder.prebuildInstallNativeModuleExists()) {
|
||||
d(`skipping: ${path.basename(modulePath)} as it was prebuilt`);
|
||||
return;
|
||||
}
|
||||
let cacheKey;
|
||||
if (this.useCache) {
|
||||
cacheKey = await (0, cache_1.generateCacheKey)({
|
||||
ABI: this.ABI,
|
||||
arch: this.arch,
|
||||
debug: this.debug,
|
||||
electronVersion: this.electronVersion,
|
||||
headerURL: this.headerURL,
|
||||
modulePath,
|
||||
});
|
||||
const applyDiffFn = await (0, cache_1.lookupModuleState)(this.cachePath, cacheKey);
|
||||
if (typeof applyDiffFn === 'function') {
|
||||
await applyDiffFn(modulePath);
|
||||
this.lifecycle.emit('module-done');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (await moduleRebuilder.rebuild(cacheKey)) {
|
||||
this.lifecycle.emit('module-done');
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Rebuilder = Rebuilder;
|
||||
function rebuild(options) {
|
||||
console.log("(rebuild)", options)
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
d('rebuilding with args:', arguments);
|
||||
const lifecycle = new events_1.EventEmitter();
|
||||
const rebuilderOptions = { ...options, lifecycle };
|
||||
const rebuilder = new Rebuilder(rebuilderOptions);
|
||||
const ret = rebuilder.rebuild();
|
||||
ret.lifecycle = lifecycle;
|
||||
return ret;
|
||||
}
|
||||
exports.rebuild = rebuild;
|
||||
//# sourceMappingURL=rebuild.js.map
|
142
temp/yarn.js
Normal file
142
temp/yarn.js
Normal file
@ -0,0 +1,142 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.rebuild = exports.nodeGypRebuild = exports.getGypEnv = exports.installOrRebuild = void 0;
|
||||
const builder_util_1 = require("builder-util");
|
||||
const fs_extra_1 = require("fs-extra");
|
||||
const os_1 = require("os");
|
||||
const path = require("path");
|
||||
const electronVersion_1 = require("../electron/electronVersion");
|
||||
const electronRebuild = require("@electron/rebuild");
|
||||
const searchModule = require("@electron/rebuild/lib/src/search-module");
|
||||
async function installOrRebuild(config, appDir, options, forceInstall = false) {
|
||||
console.log("install or rebuild", { config, options })
|
||||
let isDependenciesInstalled = false;
|
||||
for (const fileOrDir of ["node_modules", ".pnp.js"]) {
|
||||
if (await (0, fs_extra_1.pathExists)(path.join(appDir, fileOrDir))) {
|
||||
isDependenciesInstalled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (forceInstall || !isDependenciesInstalled) {
|
||||
const effectiveOptions = {
|
||||
buildFromSource: config.buildDependenciesFromSource === true,
|
||||
additionalArgs: (0, builder_util_1.asArray)(config.npmArgs),
|
||||
...options,
|
||||
};
|
||||
await installDependencies(appDir, effectiveOptions);
|
||||
}
|
||||
else {
|
||||
await rebuild(appDir, config.buildDependenciesFromSource === true, options);
|
||||
}
|
||||
}
|
||||
exports.installOrRebuild = installOrRebuild;
|
||||
function getElectronGypCacheDir() {
|
||||
return path.join((0, os_1.homedir)(), ".electron-gyp");
|
||||
}
|
||||
function getGypEnv(frameworkInfo, platform, arch, buildFromSource) {
|
||||
const npmConfigArch = arch === "armv7l" ? "arm" : arch;
|
||||
const common = {
|
||||
...process.env,
|
||||
npm_config_arch: npmConfigArch,
|
||||
npm_config_target_arch: npmConfigArch,
|
||||
npm_config_platform: platform,
|
||||
npm_config_build_from_source: buildFromSource,
|
||||
// required for node-pre-gyp
|
||||
npm_config_target_platform: platform,
|
||||
npm_config_update_binary: true,
|
||||
npm_config_fallback_to_build: true,
|
||||
};
|
||||
if (platform !== process.platform) {
|
||||
common.npm_config_force = "true";
|
||||
}
|
||||
if (platform === "win32" || platform === "darwin") {
|
||||
common.npm_config_target_libc = "unknown";
|
||||
}
|
||||
if (!frameworkInfo.useCustomDist) {
|
||||
return common;
|
||||
}
|
||||
// https://github.com/nodejs/node-gyp/issues/21
|
||||
return {
|
||||
...common,
|
||||
npm_config_disturl: "https://electronjs.org/headers",
|
||||
npm_config_target: frameworkInfo.version,
|
||||
npm_config_runtime: "electron",
|
||||
npm_config_devdir: getElectronGypCacheDir(),
|
||||
};
|
||||
}
|
||||
exports.getGypEnv = getGypEnv;
|
||||
function checkYarnBerry() {
|
||||
var _a;
|
||||
const npmUserAgent = process.env["npm_config_user_agent"] || "";
|
||||
const regex = /yarn\/(\d+)\./gm;
|
||||
const yarnVersionMatch = regex.exec(npmUserAgent);
|
||||
const yarnMajorVersion = Number((_a = yarnVersionMatch === null || yarnVersionMatch === void 0 ? void 0 : yarnVersionMatch[1]) !== null && _a !== void 0 ? _a : 0);
|
||||
return yarnMajorVersion >= 2;
|
||||
}
|
||||
function installDependencies(appDir, options) {
|
||||
const platform = options.platform || process.platform;
|
||||
const arch = options.arch || process.arch;
|
||||
const additionalArgs = options.additionalArgs;
|
||||
builder_util_1.log.info({ platform, arch, appDir }, `installing production dependencies`);
|
||||
let execPath = process.env.npm_execpath || process.env.NPM_CLI_JS;
|
||||
const execArgs = ["install"];
|
||||
const isYarnBerry = checkYarnBerry();
|
||||
if (!isYarnBerry) {
|
||||
if (process.env.NPM_NO_BIN_LINKS === "true") {
|
||||
execArgs.push("--no-bin-links");
|
||||
}
|
||||
execArgs.push("--production");
|
||||
}
|
||||
if (!isRunningYarn(execPath)) {
|
||||
execArgs.push("--prefer-offline");
|
||||
}
|
||||
if (execPath == null) {
|
||||
execPath = getPackageToolPath();
|
||||
}
|
||||
else if (!isYarnBerry) {
|
||||
execArgs.unshift(execPath);
|
||||
execPath = process.env.npm_node_execpath || process.env.NODE_EXE || "node";
|
||||
}
|
||||
if (additionalArgs != null) {
|
||||
execArgs.push(...additionalArgs);
|
||||
}
|
||||
return (0, builder_util_1.spawn)(execPath, execArgs, {
|
||||
cwd: appDir,
|
||||
env: getGypEnv(options.frameworkInfo, platform, arch, options.buildFromSource === true),
|
||||
});
|
||||
}
|
||||
async function nodeGypRebuild(arch) {
|
||||
return rebuild(process.cwd(), false, arch);
|
||||
}
|
||||
exports.nodeGypRebuild = nodeGypRebuild;
|
||||
function getPackageToolPath() {
|
||||
if (process.env.FORCE_YARN === "true") {
|
||||
return process.platform === "win32" ? "yarn.cmd" : "yarn";
|
||||
}
|
||||
else {
|
||||
return process.platform === "win32" ? "npm.cmd" : "npm";
|
||||
}
|
||||
}
|
||||
function isRunningYarn(execPath) {
|
||||
const userAgent = process.env.npm_config_user_agent;
|
||||
return process.env.FORCE_YARN === "true" || (execPath != null && path.basename(execPath).startsWith("yarn")) || (userAgent != null && /\byarn\b/.test(userAgent));
|
||||
}
|
||||
/** @internal */
|
||||
async function rebuild(appDir, buildFromSource, options) {
|
||||
builder_util_1.log.info({ appDir, arch: options.arch, platform: options.platform }, "executing @electron/rebuild");
|
||||
const effectiveOptions = {
|
||||
buildPath: appDir,
|
||||
electronVersion: await (0, electronVersion_1.getElectronVersion)(appDir),
|
||||
arch: options.arch,
|
||||
platform: options.platform,
|
||||
force: true,
|
||||
debug: builder_util_1.log.isDebugEnabled,
|
||||
projectRootPath: await searchModule.getProjectRootPath(appDir),
|
||||
};
|
||||
if (buildFromSource) {
|
||||
effectiveOptions.prebuildTagPrefix = "totally-not-a-real-prefix-to-force-rebuild";
|
||||
}
|
||||
return electronRebuild.rebuild(effectiveOptions);
|
||||
}
|
||||
exports.rebuild = rebuild;
|
||||
//# sourceMappingURL=yarn.js.map
|
Loading…
x
Reference in New Issue
Block a user