pwa-builder / PWABuilder-CLI

Node.js tool for App Generation
Other
1.63k stars 142 forks source link

ManifoldJS can't run from node_modules/ folder #213

Closed zackhall closed 8 years ago

zackhall commented 8 years ago

I'm trying to create a script that creates a project with manifold and then runs it immediately.

The node script does something like this:

/*
 *  script.js
 */
...
cp.execSync(`manifoldjs http://localhost:3000/ -d ${localDir} -p windows10 -l info`, {stdio: [0,1,2]});
cp.execSync(`manifoldjs run windows10`, { stdio: [0,1,2], cwd: cwd });

When running straight from a command prompt like node script.js it runs okay. If I try to put it in an npm script like:

{
  ...
  "scripts": {
    "start:local": "node script.js"
  },
  ...
}

I get the following error:

[warn ] general     : Manifest validation SUGGESTION - It is recommended to specify a set of rules that represent the navigation scope of the application(member: mjs_extended_scope).
[warn ] general     : Manifest validation WARNING    - Unknown property (not in schema)(member: /lang).
[warn ] windows10   : Manifest validation WARNING    - A small square logo of any of the following sizes is required for Windows: 24x24, 30x30, 42x42, 54x54(member: icons).
[warn ] windows10   : Manifest validation WARNING    - A small tile logo of any of the following sizes is required for Windows Phone: 71x71, 99x99, 170x170(member: icons).
[debug] manifoldjs  : Creating the 'Windows 10 Platform' app...
[info ] windows10   : Generating the Windows 10 Platform app...
[debug] windows10   : Creating the Windows 10 Platform app folder...
[debug] windows10   : Copying the Windows 10 Platform manifest to the app folder...
[debug] windows10   : Downloading the windows10 icons...
[debug] manifoldjs  : Downloading icon file from 'http://localhost:3000/img/icons/Icon@44w.png' to 'E:\github\hwa-starter\tmp\local\StarterPack\windows10\manifest\images\smalllogo.scale-100.png'...
[debug] manifoldjs  : Downloading icon file from 'http://localhost:3000/img/icons/Icon@50w.png' to 'E:\github\hwa-starter\tmp\local\StarterPack\windows10\manifest\images\storelogo.scale-100.png'...
[debug] manifoldjs  : Downloading icon file from 'http://localhost:3000/img/icons/Icon@150w.png' to 'E:\github\hwa-starter\tmp\local\StarterPack\windows10\manifest\images\logo.scale-100.png'...
[debug] manifoldjs  : Downloading icon file from 'http://localhost:3000/img/icons/Splash@620w.png' to 'E:\github\hwa-starter\tmp\local\StarterPack\windows10\manifest\images\splashscreen.scale-100.png'...
[info ] windows10   : Copying offline file "msapp-error.html" to target: E:\github\hwa-starter\tmp\local\StarterPack\windows10\manifest\msapp-error.html...
[info ] windows10   : Copying files to the Windows 10 Platform source project...
[info ] windows10   : Copying documentation from 'E:\github\hwa-starter\node_modules\manifoldjs-windows10\lib\docs' to 'E:\github\hwa-starter\tmp\local\StarterPack\windows10'...

[error] manifoldjs  : Failed to create the Windows 10 Platform app.
                          at E:\github\hwa-starter\node_modules\manifoldjs-lib\lib\projectBuilder.js:95:27
                          at _rejected (E:\github\hwa-starter\node_modules\q\q.js:844:24)
                          at E:\github\hwa-starter\node_modules\q\q.js:870:30
                          at Promise.when (E:\github\hwa-starter\node_modules\q\q.js:1122:31)
                          at Promise.promise.promiseDispatch (E:\github\hwa-starter\node_modules\q\q.js:788:41)
                          at E:\github\hwa-starter\node_modules\q\q.js:604:44
                          at runSingle (E:\github\hwa-starter\node_modules\q\q.js:137:13)
                          at flush (E:\github\hwa-starter\node_modules\q\q.js:125:13)
                          at _combinedTickCallback (internal/process/next_tick.js:67:7)
                          at process._tickCallback (internal/process/next_tick.js:98:9)

-->>                 Error retrieving information for module: 'manifoldjs-windows10'.
                          at Object.getPackageInformation (E:\github\hwa-starter\node_modules\manifoldjs-lib\lib\packageTools.js:77:11)
                          at PlatformBase.self.writeGenerationInfo (E:\github\hwa-starter\node_modules\manifoldjs-lib\lib\platformBase.js:248:39)
                          at E:\github\hwa-starter\node_modules\manifoldjs-windows10\lib\platform.js:108:21
                          at _fulfilled (E:\github\hwa-starter\node_modules\q\q.js:834:54)
                          at self.promiseDispatch.done (E:\github\hwa-starter\node_modules\q\q.js:863:30)
                          at Promise.promise.promiseDispatch (E:\github\hwa-starter\node_modules\q\q.js:796:13)
                          at E:\github\hwa-starter\node_modules\q\q.js:604:44
                          at runSingle (E:\github\hwa-starter\node_modules\q\q.js:137:13)
                          at flush (E:\github\hwa-starter\node_modules\q\q.js:125:13)
                          at _combinedTickCallback (internal/process/next_tick.js:67:7)
[error] manifoldjs  : One or more platforms could not be generated successfully.
                          at E:\github\hwa-starter\node_modules\manifoldjs-lib\lib\projectBuilder.js:28:23
                          at _fulfilled (E:\github\hwa-starter\node_modules\q\q.js:834:54)
                          at self.promiseDispatch.done (E:\github\hwa-starter\node_modules\q\q.js:863:30)
                          at Promise.promise.promiseDispatch (E:\github\hwa-starter\node_modules\q\q.js:796:13)
                          at E:\github\hwa-starter\node_modules\q\q.js:604:44
                          at runSingle (E:\github\hwa-starter\node_modules\q\q.js:137:13)
                          at flush (E:\github\hwa-starter\node_modules\q\q.js:125:13)
                          at _combinedTickCallback (internal/process/next_tick.js:67:7)
                          at process._tickCallback (internal/process/next_tick.js:98:9)
[error] manifoldjs  : The specified directory does not appear to contain a valid manifoldjs project.
                      For more information, run manifoldjs with the diagnostics level set to debug (e.g. manifoldjs [...] -l debug)

Is there any guidance on using this from an npm script?

zackhall commented 8 years ago

Simplifying this a bit, I added the line directly to the package.json. So the updated package.json file reads:

{
  ...
  "scripts": {
    "start:local": "manifoldjs http://localhost:3000/ -d tmp\\local\\ -p windows10 -l info"
  },
  ...
  "devDependencies": {
   ...
    "manifoldjs": "^0.5.1",
    ...
  },
}

I still see the same issue. But running that command directly doesn't hit any issues.

Moreover, I can verify the node_modules\manifoldjs-windows10\ folder is present.

boyofgreen commented 8 years ago

This sounds similar to help me test with Visual Studio code. In that scenario, we don't call the bianary E. Instead we call them the JS file directly. Have you tried that? and then I know when we run it on the server we actually have endpoints her exposed but we do not have one for building the APPX

boyofgreen commented 8 years ago

This is what we put on top of it for the server: https://github.com/manifoldjs/manifold-api/tree/master/src/services this lets us call in. There is no endpoint for the build of appx, but that shouldn't be hard to add. I don't know if this is the right way to go or wheatear you should just run it from the top (doing just windows10 and then packaging it should be really quick). Do you want to set up a call to talk about?

zackhall commented 8 years ago

Hi, @boyofgreen. Sorry for the delay. I've been out a couple of days. I'd love to set up a call to chat about it.

The goal is to set up a starter pack repo to help anyone quickly build a Hosted Web App. The package.json would have some scripts similar to above to make it much quicker to generate/launch the app packages for local/prod so that they don't have to type out the full command each time.

I'd love to chat with you about it!

f2bo commented 8 years ago

Hi @zackhall

The approach suggested by @boyofgreen seems more appropriate for you scenario. Also, starting with the latest release, we moved most of the core code into a separate library so I would recommend taking a dependency on manifoldjs-lib rather than manifoldjs.

Nevertheless, I think the problem you currently have could be fixed if you replace the implementation of getPackageInformation in manifoldjs-lib/lib/packageTools.js with the following code. It would be very helpful to know if this solves the problem so that we might consider including this change in the next release.

function getPackageInformation (packageName) {

  try {
    var packagePath = path.dirname(require.main.filename);
    var modulesPath = path.join(packagePath, node_modules);

    try { fs.statSync(modulesPath).isDirectory() }
    catch (er) { 
      modulesPath = path.resolve(packagePath, '..');  
    }

    if (packageName) {
      packagePath = path.join(modulesPath, packageName);      
    }

    packagePath = path.join(packagePath, packageJson);

    return require(packagePath);  
  }
  catch (err) {
    throw new Error('Error retrieving information for module: \'' + (packageName || 'main') + '\'.');    
  }
}
zackhall commented 8 years ago

Patching my manifoldjs-lib package in /node_modules/ locally with @f2bo's code above resolved the issue for me. This allows me to run the CLI from an npm script.

f2bo commented 8 years ago

@zackhall This fix is already part of the v0.5.2 release that we published today.