Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use old and new ASK-CLIs in parallel (Alexa Skills Kit Command Line Interface)

I advise that if the VSCode plugin supports the ask-cli v2 then use Method 1. If we're not there yet then use Method 2 if you want the VSCode plugin to work. If you don't care about the plugin just go with Method 1.

Method 1

After following these instructions the old ask-cli v1.7.23 will run via the command ask1 and the latest ask-cli v2 via the command ask. You will be able to update the ask-cli v2 as usual. You can skip all steps below to create the npm package by just doing:

npm install -g https://gist.github.com/germanviscuso/48f5c68f876b31b51ba59f91b49a253f/raw/3a074faf055fe261441964d1ad5894012e716e0c/ask-cli-1-1.7.23.tgz

(This is the file below but whch I already edited for you to install as ask1 rather than ask)

  • Download the original npm package of ask-cli v1 without installing it:
wget https://registry.npmjs.org/ask-cli/-/ask-cli-1.7.23.tgz
  • Uncompress it and in the Terminal cd to the subdirectory package (this is the project root)
  • Edit file package.json and change package name from ask-cli to ask-cli-1
"name": "ask-cli-1"
  • Also change bin command from ask to ask1:
"bin": {
    "ask1": "bin/ask.js"
}
  • While in that directory in the command line do an npm pack. A file called ask-cli-1-1.7.23.tgz will be generated
npm pack
  • Install it globally by doing:
 npm install -g ask-cli-1-1.7.23.tgz
  • You can now execute ask-cli v1 with ask1 (config files with profiles can be shared among v1 and v2 so this will still work)
  • And if you still haven't done that go ahead and install/update the latest ask-cli v2 as usual with:
npm install -g ask-cli

Method 2

The objective of these instructions is to keep the newest ask-cli v2.X.X running with the askx command and the old ask-cli v1.7.23 under the ask command without breaking the cli setup and getting the VSCode plugin to work again. See: (https://github.com/alexa/ask-toolkit-for-vscode/issues/15)

> npm uninstall -g ask-cli-x                   // in case you still have the beta version installed, no longer used
> npm uninstall -g ask-cli                     // this will unistall your current ask-cli but won't delete your cli configuration
> npm install -g ask-cli@1.7.23                // this will install your ask-cli as the latest v1 version (1.7.23)

> git clone git@github.com:alexa/ask-cli.git   // this will clone the latest v2.x.x to you local machine

Go to project root directory and in package.json:

  • Change package name from ask-cli to ask-cli-x
"name": "ask-cli-x"

  • Change bin command from ask to askx:
"bin": {
    "askx": "bin/ask.js"
}
> npm link                                     // this will install the modified package globally (don't delete the project files, the installation links to it)

You're done!

But later, if you want to update the new cli you can't do npm install -g. Instead you have to force an overwrite of you local source files by using the following commands.

git fetch --all
git reset --hard origin/master

WARNING: the above will overwrite any local changes you have made with the latest version of ask-cli from github

But remember that you'll have to edit package.json again (as explained above). After updating and editing then you should install by running:

npm install

locally (not with -g).

If you're interested in automating this process check the comment below (great contribution with scripts!)

@goldzulu

This comment has been minimized.

Copy link

@goldzulu goldzulu commented May 21, 2020

For Method 2, please note that if you have changed the package.json to askx when you do a git pull it will not update the package.json and hence when you run npm install you will still be using the old version.

Instead of pull, you have to force an overwrite of you local source files (if that's what is intended) by using the following commands.

git fetch --all
git reset --hard origin/master

WARNING: the above will overwrite any local changes you have made with the latest version of ask-cli from github

then you can update by running
npm install

Also i find changing the ask->askx a repetitive task that is yelling out to be automated so I've written a javascript file that does that... combined together with a bash script. (so 2x files attached) Just drop the 2 files into the root folder of the source ask-cli (where package.json is) and run ./update.sh (you might need to run chmod 755 ./update.sh first (in linux/mac terminal) to make the file executable)

Files in link below:
https://gist.github.com/goldzulu/3e41a864de6fd5e2b9a9fb3b7cf9bacc

@germanviscuso

This comment has been minimized.

Copy link
Owner Author

@germanviscuso germanviscuso commented May 21, 2020

I will update the text below to include your strategy. I was overwriting and repetitively changing package.json (tefious)

@goldzulu

This comment has been minimized.

Copy link

@goldzulu goldzulu commented May 21, 2020

Yes. Thats' why i did that script... lol... the two automation scripts are
in the gists link i gave in my comment.

@bbezerra82

This comment has been minimized.

Copy link

@bbezerra82 bbezerra82 commented Jun 2, 2020

In the first method, the npm install -g command is returning an error:

 % npm install -g https://gist.github.com/germanviscuso/48f5c68f876b31b51ba59f91b49a253f#file-ask-cli-1-1-7-23-tgz

npm ERR! code 1
npm ERR! Command failed: git checkout file-ask-cli-1-1-7-23-tgz
npm ERR! error: pathspec 'file-ask-cli-1-1-7-23-tgz' did not match any file(s) known to git
npm ERR! 

The steps below it work without an issue, though.

@germanviscuso

This comment has been minimized.

Copy link
Owner Author

@germanviscuso germanviscuso commented Jun 18, 2020

Thanks Bernardo I had to pass a link to the raw file instead (fixed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.