alexa / ask-cli

Alexa Skills Kit Command Line Interface
https://developer.amazon.com/en-US/docs/alexa/smapi/ask-cli-intro.html
Apache License 2.0
167 stars 54 forks source link

"ask deploy" on Mac gives "Cannot copy '<project_directory>/dist' to a subdirectory of itself, '<project_directory>/dist/.ask' error #510

Open chmurray opened 5 months ago

chmurray commented 5 months ago

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request 
[ ] Other... Please describe: 

Expected Behavior

The 'deploy' functionality should cause all of the contents of project '/dist' EXCEPT FOR '/dist/.ask' to be copied to /dist/.ask.

The 'deploy' functionality should not cause all of the contents of '/dist' to be copied to '/dist/.ask'. The '/dist/.ask' directory should be excluded from the copy.

Current Behavior

Running the 'deploy' command causes the following error in the "Build Skill Code" phase of the process: [Error]: Cannot copy '/dist' to a subdirectory of itself, '/dist/.ask'.

[Error]: Cannot copy '/dist' to a subdirectory of itself, '/dist/.ask'.

CLI Snapshot If applicable, add screenshots to help explain your problem.

Steps to Reproduce (for bugs)

Try to deploy anything from a Mac.

Possible Solution

In order to get it working on my machine, I modified CodeBuilder._setupBuildFolder() (defined in lib/controllers/skill-code-controller/code-builder.js). I would have submitted a pull request with my changes, but they break two tests, and I wasn't quickly able to figure out how to resolve that. Here is what my CodeBuilder._setupBuildFolder() function looks like:

_setUpBuildFolder() { fs.ensureDirSync(this.build.folder); fs.emptyDirSync(this.build.folder);

// My Mac is rejecting the fs.copySync() call with the following error:
//    [Error]: Cannot copy '<path>/dist' to a subdirectory of itself, '<path>/dist/.ask'.
// It doesn't even try using the filter specified in the options argument.
//fs.copySync(path.resolve(this.src), this.build.folder, {filter: (src) => !src.includes(this.build.folder)});

// I am new to JavaScript.  
//    Please be kind with the feedback, but the following is working for me:

let srcFiles = fs.readdirSync(path.resolve(this.src));
for (const file of srcFiles) {

  let fullyQualifiedFileName = path.resolve(this.src, file);
  if (!fullyQualifiedFileName.includes(this.build.folder)) {

    if (fs.lstatSync(fullyQualifiedFileName).isDirectory()) {
      fs.copySync(fullyQualifiedFileName, this.build.folder);
    } else {
      fs.copyFileSync(fullyQualifiedFileName, this.build.folder + "/" + file);
    }

  }
}

}

Your Environment and Context