I need to exclude only the "package.json" from the root folder
but at the moment all "package.json" files are unpacked (from node_modules ...)
Electron v18
Electron Package v15.4.0
Windows
script in package.json
"scripts": {
"package": "electron-packager . TestApp --out=dist/win --asar.unpack=\"{*/jar/**/*,**/jre/**/*,package.json}\"
}
and with this pattern, no file will be unpacked
/package.json => NOK
/{,!(node_modules)/**/}package.json => NOK
any ideas??
Greetings
Klaus
Related
When running my Electron project normally, like electron ./artist-test-kit-main.js, everything works fine. When I build the project into an executable, attempts to load files start failing, like: Uncaught Error: ENOENT: no such file or directory, open 'asset-editor\data.json' So I ran a test to see if there's a difference in the root directory between the normal (electron ./artist-test-kit-main.js) execution and the .exe's.
Within index.js (launched by index.html, launched by artist-test-kit-main.js which is a standard electron.js initiator file):
console.log(fs.readdirSync('./'))
In the .exe, this outputs:
In the normal dev execution (electron ./artist-test-kit-main.js), this outputs:
This usual root directory of the project is, after being packaged, stored in the resources directory seen in the .exe execution root directory. So now all my file reads seem to be broken because of this discrepancy in root directories.
How can I solve this?
My package.json shows the build arguments used:
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "artist-test-kit-main.js",
"dependencies": {
...
},
"scripts": {
"start": "electron .",
"start-artist": "electron ./artist-test-kit-main.js",
"build": "electron-packager ./ game --platform=win32 --arch=x64 --overwrite=true",
"build-art": "electron-packager ./ asset-editor --platform=win32 --arch=x64 --overwrite=true"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"electron-packager": "^15.4.0"
}
}
TLDR
Use __dirname instead of .
Explanation
. refers to the current working directory (cwd), which is the directory in which the node process was started.
For an unpackaged app, this is usually the root folder of your project, producing the expected results. For a packaged app, the cwd will likely be where the Electron executable is stored. The app's contents (what was previously the root folder) are put inside resources/app or resources/app.asar relative to the executable.
The way to unify the packaged and unpackaged scenarios is to use __dirname, which contains the directory of the currently running Node script. This way, it will be the same as using . in an unpackaged app, but will return the path with resources/app in the packaged scenario, as that is then the location of the currently running Node script.
This is why you'll often see people using something like `file://${__dirname}/assets/index.html` to address files in Electron.
Side note
If you use require('./file.js'), the path is evaluated relative to the location of the calling script and will work as if you had used __dirname.
electron-packager always create a "version" file in the package it creates. At this moment, this "version" file only contents the electron version.
How to modify the content of this file? How to include my package.json version tag instead of the electron version?
See inside the "version" file :
I use this command in my package.json to run electron-packager :
"packager-mac64": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=app/icons/mac/icon.icns --prune=true --out ./dist-pkg-packager --ignore=distributions --ignore=dist-pkg-builder --ignore=trash --ignore=csv-excel --ignore=.*win32-x64$ --ignore=.DS_Store"
In my package.json, I also have these lines :
"version": "1.1.0",
"devDependencies": {
"electron": "8.2.0"
},
I would want "1.1.0" instead of "8.2.0" in the version file...
On my ruby project when I try to run gulp (gulp server, gulp watch) I have the following error :
Users/workspace/website2019/gulpfile.babel.js:1
import del from 'del';
^^^^^^
SyntaxError: Cannot use import statement outside a module
I don't get how can I fix it, if someone could help me please,
you use babel transpilation with gulp because of the file gulpfile.babel.js For this reason you need to install babel. according to the documentation you need #babel/register and #babel/preset-env for transpiling your import syntax.
So run the following command in your project folder
npm install --save-dev #babel/core #babel/register
Afterwards create the babel configuration file .babelrc in the root folder and add the following lines to it
{
"presets": [
[
"#babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
make sure you have this line in package.json
"type": "module"
I have installed electron and electron-packager, all of them in global mode. When I build my app electron-packager searchs the local electron module. How forcing electron-packager to use the global electron module that I have installed?
The short answer is that what you have described isn't the way you "should" use electron-packager. Normally, the intent is that you are building a local package (exe or such) under the project directory you are working on. For example, an electron/angular project building on a Windows platform might have the following kind of structure:
C:.
+---ClientSide
¦ +---index.html
¦ +---app
¦ ¦ +---app.component.ts
¦ ¦ +---app.module.ts
¦ ¦ +---main.ts
¦ ¦ +---AppContent/
¦ ¦ +---help/
¦ +---Styles
¦ +---test
¦ +---AppContent/
+---dist/
+---edist
| \---Application-win32-ia32 [*location of binary source for the install]
+---Installer
+---Application/
gulpfile.js
karma.conf.js
main.js
package.json
README.md
webpack.config.js
In this kind of scenario, the package.json file typically contains reference to both packages, as in:
.. .. ..
"devDependencies": {
"#angular/animations": "4.4.4",
"#angular/common": "4.4.4",
"#angular/compiler": "4.4.4",
.. .. ..
.. .. ..
"electron": "1.7.9",
"electron-packager": "9.1.0",
.. .. ..
Then within your local gulpfile.js you would typically include a call to run the packager that refers to the local version of electron. Something like:
'use strict';
... ...
var packager = require('electron-packager');
var electronPackage = require('electron/package.json');
var pkg = require('./package.json');
// pull the electron version from the package.json file
var electronVersion = electronPackage.version;
... ...
var opts = {
name: pkg.name,
platform: 'win32',
arch: 'ia32', // ia32, x64 or all
dir: './', // source location of app
out: './edist/', // destination location for app os/native binaries
ignore: config.electronignore, // don't include these directories in the electron app build
icon: config.icon,
asar: {unpackDir: config.electroncompiled}, // compress project/modules into an asar blob but don't use asar to pack the native compiled modules
overwrite: true,
prune: true,
electronVersion: electronVersion , // Tell the packager what version of electron to build with
appCopyright: pkg.copyright, // copyright info
appVersion: pkg.version, // The version of the application we are building
win32metadata: { // Windows Only config data
CompanyName: pkg.authors,
ProductName: pkg.name,
FileDescription: pkg.description,
OriginalFilename: pkg.name + '.exe'
}
};
// Build the electron app
gulp.task('build:electron', function (cb) {
console.log('Launching task to package binaries for ' + opts.name + ' v' + opts['appVersion']);
packager(opts, function (err, appPath) {
console.log(' <- packagerDone() ' + err + ' ' + appPath);
console.log(' all done!');
cb();
});
});
If you don't want to build the same version of electron that as is present locally, you can change that parameter to whatever version of electron you'd like packager to use. As in, replacing this line of code:
// pull the electron version from the package.json file
var electronVersion = electronPackage.version;
With something like this:
// Use a specific electron version
var electronVersion = '1.7.8';
If you are going to run electron-packager from the command line, you have all the same options available as I've shown here in the API options. You can see the full list of options in their online github user docs . In your case, if you are using command line then use the "--electron-version" switch to set the electron version you wish.
Is there any way to install modules by directly downloading from git-hub without php composer.phar. Because my php composer is not working.
this is the error
$ php composer.phar require webino/webino-image-thumb:2.*
./composer.json has been updated
Loading composer repositories with package information
Ignoring unknown parameter "server role"
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Can only install one of: zf-commons/zfc-admin[v0.1.0, dev-master].
- Can only install one of: zf-commons/zfc-admin[v0.1.0, dev-master].
- Installation request for zf-commons/zfc-admin 0.1.0 -> satisfiable by zf-commons/zfc-admin[v0.1.0].
- Installation request for zf-commons/zfc-admin == 9999999-dev -> satisfiable by zf-commons/zfc-admin[dev-master].
Installation failed, reverting ./composer.json to its original content.
My composer.json looks like this:
{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [ "framework", "zf2" ],
"minimum-stability": "dev",
"homepage": "framework.zend.com/",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.2.0",
"webino/webino-image-thumb": "1.*",
"zf-commons/zfc-admin":"0.1.0"
}
}
There are three ways you can typically install Zend 2 Modules.
Through the file system
Git
Composer
You could just run:
https://github.com/ZF-Commons/ZfcAdmin.git
to get the module. But I am unsure if it is going to work since you likely have a dependency issue that needs resolving. I would recommend sticking with composer. Please post your whole composer.json file and I'm sure that the issue can be solved.
I cannot reproduce your error.
I copy your composer.json file into an empty directory and execute composer install there. Works.
I then issue composer require webino/webino-image-thumb:2.*, and it downloads that version (2.0.0-RC1) just fine.