Skip to content

Instantly share code, notes, and snippets.

@germanviscuso
Last active March 3, 2022 14:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save germanviscuso/48f5c68f876b31b51ba59f91b49a253f to your computer and use it in GitHub Desktop.
Save germanviscuso/48f5c68f876b31b51ba59f91b49a253f to your computer and use it in GitHub Desktop.
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: (alexa/ask-toolkit-for-vscode#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!)

@bbezerra82
Copy link

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
Copy link
Author

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