GithubHelp home page GithubHelp logo

Comments (15)

MarshallOfSound avatar MarshallOfSound commented on July 24, 2024 1

But it seems, the electron-package is running before the native build and thus above ignore is of no use.

This is accurate, you need to use an afterCopy hook to delete the artifacts you don't want from the native module build process.

/cc @malept I don't think we should do this ^^ by default as some people may want the debug artifacts. What do you think?

from forge.

manikantag avatar manikantag commented on July 24, 2024

@MarshallOfSound can you tell me how to ignore some dir/files using afterCopy? I don't see any examples.

from forge.

MarshallOfSound avatar MarshallOfSound commented on July 24, 2024

@manikantag Not ignore really, more like delete.

Use a combination of fs.unlinkSync and the glob module.

from forge.

manikantag avatar manikantag commented on July 24, 2024

Excuse me for asking questions in this issue.

I m writing some console logs, but Forge cli output is only seen, no console logs. Where do I see them? Thanks.

from forge.

manikantag avatar manikantag commented on July 24, 2024

@MarshallOfSound I m not sure how to use afterCopy.

config.forge in package.json:

"forge": {
         "afterCopy": [
                  "./forge-hooks.js"
         ]
}

forge-hooks.js:

const fs = require('fs');
function afterCopy() {
    fs.unlinkSync('d:/test.txt');
}
module.exports = afterCopy

The afterCopy hook is not working as d:\test.txt file is not getting deleted. I m trying to go through the source (https://github.com/electron-userland/electron-forge/blob/master/src/api/package.js#L84), but no clue so far.

What is the correct way of using afterCopy and what are the arguments?

from forge.

MarshallOfSound avatar MarshallOfSound commented on July 24, 2024
fs.unlinkSync('d:/test.txt');

That path looks wrong (for windows). Try this.

fs.unlinkSync('d:\\test.txt');

You can also try adding some console.log calls to ensure that JS file is being resolved correctly.

from forge.

manikantag avatar manikantag commented on July 24, 2024

fs.unlinkSync('d:/test.txt');
That path looks wrong (for windows). Try this.

Node fs module will take care of it even when using /.

from forge.

manikantag avatar manikantag commented on July 24, 2024

You can also try adding some console.log calls to ensure that JS file is being resolved correctly.

As I mentioned in earlier, I m not seeing any console.logs when I m using forge start or forge package or any forge command. Where can I see console.logs?

from forge.

manikantag avatar manikantag commented on July 24, 2024

Okay, I figured it out. I need use config.forge.electronPackagerConfig.afterCopy, but not config.forge.afterCopy.

But now, the require is failing.

"electronPackagerConfig": {
    "afterCopy": [
        "./forge-hooks"
     ]
}

If I give absolute path, it is working. How do I give relative paths? And how do I know the packaging temp dir? what are the args for the afterCopy method?

DEBUG log:

An unhandled rejection has occurred inside Forge:
Cannot find module './forge-hooks'
Error: Cannot find module './forge-hooks'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at C:\eapp\node_modules\electron-forge\dist\api\package.js:297:51
    at Array.map (native)
    at _callee4$ (C:\eapp\node_modules\electron-forge\dist\api\package.js:296:119)
    at tryCatch (C:\eapp\node_modules\regenerator-runtime\runtime.js:64:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (C:\eapp\node_modules\regenerator-runtime\runtime.js:355:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\eapp\node_modules\regenerator-runtime\runtime.js:116:21)
    at GeneratorFunctionPrototype.tryCatcher (C:\eapp\node_modules\bluebird\js\release\util.js:16:23)
    at PromiseSpawn._promiseFulfilled (C:\eapp\node_modules\bluebird\js\release\generators.js:97:49)
    at Promise._settlePromise (C:\eapp\node_modules\bluebird\js\release\promise.js:572:26)
    at Promise._settlePromise0 (C:\eapp\node_modules\bluebird\js\release\promise.js:612:10)
    at Promise._settlePromises (C:\eapp\node_modules\bluebird\js\release\promise.js:691:18)
    at Async._drainQueue (C:\eapp\node_modules\bluebird\js\release\async.js:133:16)

from forge.

manikantag avatar manikantag commented on July 24, 2024

Got the arguments: buildPath, electronVersion, pPlatform, pArch, done.

I got these from https://github.com/electron-userland/electron-forge/blob/master/src/api/package.js#L64

I m seeing console logs when using DEBUG=electron-debug:*.

So, now I m left with giving relative paths for afterCopy js file.

from forge.

MarshallOfSound avatar MarshallOfSound commented on July 24, 2024

@manikantag The afterCopy hooks are documented over at electron-packager.

https://github.com/electron-userland/electron-packager/blob/master/docs/api.md

I'm looking into the relative path issue now

from forge.

manikantag avatar manikantag commented on July 24, 2024

I m using https://www.npmjs.com/package/rimraf to delete build dirctory as the dir has files in it.

from forge.

MarshallOfSound avatar MarshallOfSound commented on July 24, 2024

[email protected] should fix the path resolution issue, gonna close this out as the recommended solution is to use an afterCopy hook to clean up.

from forge.

MarshallOfSound avatar MarshallOfSound commented on July 24, 2024

Would say that if someone can make a super generic afterCopy hook to clean up a node_modules directory as a separate module that would be pretty cool.

electron-packager-cleanup-hook

from forge.

manikantag avatar manikantag commented on July 24, 2024

With 2.7.3, it is working with relative paths. Pretty quick fix! Thanks.

from forge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.