-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add alias command as an eventual replacement for the 3 existing…
… alias commands This is a non breaking change but does add deprecation messages for pkg-alias, map-alias and npm-alias, all of which are replaced by this new alias command. The alias command detects type from eik.json which was not possible in earlier versions of the cli which was the reason for the existence of 3 separate commands instead of 1. If the command is run in a directory that does not contain an eik.json file, type can be provided via the command line argument --type. If neither are present, an error is thrown.
- Loading branch information
1 parent
5814b82
commit ff4a27c
Showing
12 changed files
with
388 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import ora from 'ora'; | ||
import semver from 'semver'; | ||
import Alias from '../classes/alias.js'; | ||
import { logger, getDefaults, getCWD } from '../utils/index.js'; | ||
import { Alias as AliasFormatter } from '../formatters/index.js'; | ||
|
||
export const command = 'alias [name] [version] [alias]'; | ||
|
||
export const aliases = ['a']; | ||
|
||
export const describe = `Create a semver major alias for a package, NPM package or import map as identified by its name and version. A package with the given name and version must already exist on asset server. Alias should be the semver major part of the package version. Eg. For a package of version 5.4.3, you should use 5 as the alias. Alias type is detected from an eik.json file in the current working directory.`; | ||
|
||
export const builder = (yargs) => { | ||
const cwd = getCWD(); | ||
const defaults = getDefaults(cwd); | ||
|
||
yargs | ||
.positional('name', { | ||
describe: 'Name matching existing name for a package on Eik server', | ||
type: 'string', | ||
default: defaults.name, | ||
}) | ||
.positional('version', { | ||
describe: | ||
'Version matching existing version for a package on Eik server', | ||
type: 'string', | ||
default: defaults.version, | ||
}) | ||
.positional('alias', { | ||
describe: | ||
'Alias for a semver version. Must be the semver major component of version. Eg. 1.0.0 should be given as 1', | ||
type: 'string', | ||
default: defaults.version ? semver.major(defaults.version) : null, | ||
}); | ||
|
||
yargs.options({ | ||
server: { | ||
alias: 's', | ||
describe: 'Specify location of Eik asset server.', | ||
default: defaults.server, | ||
}, | ||
cwd: { | ||
alias: 'c', | ||
describe: 'Alter the current working directory.', | ||
default: defaults.cwd, | ||
}, | ||
type: { | ||
describe: | ||
'Alter the alias type. Default is detected from eik.json. Valid values are `package`, `npm`, or `map` Eg. --type npm', | ||
default: defaults.type, | ||
}, | ||
debug: { | ||
describe: 'Logs additional messages', | ||
default: false, | ||
type: 'boolean', | ||
}, | ||
token: { | ||
describe: | ||
'Provide a jwt token to be used to authenticate with the Eik server.', | ||
default: '', | ||
alias: 't', | ||
}, | ||
}); | ||
|
||
yargs.default('token', defaults.token, defaults.token ? '######' : ''); | ||
|
||
yargs.example(`eik alias my-app 1.0.0 1`); | ||
yargs.example(`eik alias my-app 1.7.3 1`); | ||
yargs.example(`eik alias my-app 6.3.1 6`); | ||
yargs.example( | ||
`eik alias my-app 6.3.1 6 --server https://assets.myeikserver.com`, | ||
); | ||
yargs.example(`eik alias my-app 4.2.2 4 --debug`); | ||
yargs.example(`eik alias my-app 4.2.2 4 --type package`); | ||
}; | ||
|
||
export const handler = async (argv) => { | ||
const spinner = ora({ stream: process.stdout }).start('working...'); | ||
let success = false; | ||
const { debug, server, type } = argv; | ||
const log = logger(spinner, debug); | ||
let af; | ||
|
||
try { | ||
const data = await new Alias({ | ||
type, | ||
logger: log, | ||
...argv, | ||
}).run(); | ||
|
||
// TODO: get rid of this rediculous formatter class idea that past me put here to irk present and future me. | ||
// Smells like DRY silliness | ||
af = new AliasFormatter(data); | ||
|
||
const createdOrUpdated = data.update ? 'Updated' : 'Created'; | ||
log.info( | ||
`${createdOrUpdated} alias for "${type}" "${data.name}". ("${data.version}" => "v${data.alias}")`, | ||
); | ||
success = true; | ||
} catch (err) { | ||
log.warn(err.message); | ||
} | ||
|
||
spinner.text = ''; | ||
spinner.stopAndPersist(); | ||
if (success) { | ||
af?.format(server); | ||
} else { | ||
process.exit(1); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.