Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2 #8

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open

v2 #8

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7bce7db
refactor: Implemented new config command.
cb1kenobi Jun 5, 2020
0008483
Added missing project service file and add command.
cb1kenobi Jun 8, 2020
7b5b40c
Added prompter.
cb1kenobi Jun 17, 2020
963b7d6
feat(project): Added project template service.
cb1kenobi Jun 19, 2020
7969bb2
doc: Added jsdoc to prompt utils.
cb1kenobi Jun 19, 2020
00e2827
chore: Updated deps.
cb1kenobi Jun 19, 2020
b96955a
Wired up build, clean, project, and run cli commands to the project s…
cb1kenobi Jun 19, 2020
13c649f
Added app guid to config.
cb1kenobi Jun 30, 2020
ba47c83
refactor: Moved OS detection code to shared library.
cb1kenobi Jul 14, 2020
c2e7607
chore: Fixed most lint warnings.
cb1kenobi Jul 15, 2020
0b5d0b9
chore: Update deps.
cb1kenobi Jul 21, 2020
b70151e
Fixed build option render.
cb1kenobi Jul 21, 2020
dc1046c
doc: Updated changelog.
cb1kenobi Jul 22, 2020
b47c06f
feat: Added App Preview options and hook.
cb1kenobi Jul 24, 2020
607377c
Added App Preview logic.
cb1kenobi Jul 24, 2020
a8cb85c
refactor(legacy): Rewire 'build', 'clean', and 'run' commands to invo…
cb1kenobi Aug 11, 2020
da28246
fix: Removed disabling showHelpOnError as it is now disabled by default.
cb1kenobi Aug 12, 2020
ed99483
refactor(liveview): Removed local LiveView CLI option config in favor…
cb1kenobi Aug 13, 2020
50cf767
fix(legacy): Correctly wired up telemetry calls.
cb1kenobi Aug 13, 2020
06d64c8
fix(legacy): Silently drop log and telemetry IPC messages once child …
cb1kenobi Aug 14, 2020
c82dd76
refactor: Moved the module patching into the CLI constructor.
cb1kenobi Aug 17, 2020
69c78b5
chore: Added support files.
cb1kenobi Sep 2, 2020
dc32b11
fix(cli:login): Fixed issue with login command from cli-kit change.
cb1kenobi Sep 2, 2020
b9b1f29
feat: Added '/module/check-downloads' endpoint.
cb1kenobi Sep 4, 2020
f92c2b0
fix(login): Fixed banner not showing.
cb1kenobi Sep 5, 2020
8acc09f
feat: Update the app tiapp metadata post build.
cb1kenobi Sep 5, 2020
dba7b4d
fix: Added missing pluginVersion to 'ti info' output.
cb1kenobi Sep 9, 2020
1c2776b
chore: Updated deps.
cb1kenobi Sep 9, 2020
4c298d8
fix(legacy-cli): Fixed prompting for build options.
cb1kenobi Sep 9, 2020
b3f2c6f
feat(legacy): Wired up most of the remote encryption policy logic.
cb1kenobi Sep 11, 2020
3e18ed3
feat(legacy): Added support for remote encryption.
cb1kenobi Sep 15, 2020
58f3a35
doc: Updated legacy CLI notes.
cb1kenobi Sep 28, 2020
ced37e3
BREAKING CHANGE: Dropped support for appcd plugin API version 1.0 and…
cb1kenobi Oct 2, 2020
750e54b
chore: Updated deps.
cb1kenobi Oct 22, 2020
ba420a2
feat: Added register command and service endpoint.
cb1kenobi Oct 22, 2020
5c32ffb
feat(register): Finished the register command and endpoint.
cb1kenobi Oct 26, 2020
becaa29
chore: Updated deps.
cb1kenobi Nov 13, 2020
872b965
chore: Updated deps.
cb1kenobi Nov 15, 2020
d01cac8
fix(cli): Explicitly enabled server mode.
cb1kenobi Jan 26, 2021
5e22296
chore: Resolved merge conflicts.
cb1kenobi Jan 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"rules": {
"max-depth": "off",
"no-loop-func": "off",
"promise/always-return": "off"
}
}
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ junit.xml
node_modules
npm-debug.log
yarn-error.log
yarn.lock
/src
/test
yarn.lock
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
# v2.0.0

* BREAKING CHANGE(config): `config` command no longer returns status as apart of JSON output.
* BREAKING CHANGE(config): `config` command does not return current value when doing a `set`,
`push`, or `unshift`.
* BREAKING CHANGE(config): `config list` command no longer supports filtering, use `config get`
instead.
* BREAKING CHANGE(config): Write operations such as `set` return `"OK"` instead of `"Saved"`.
* BREAKING CHANGE: Dropped support for appcd plugin API version 1.0 and require API version 2.0,
which was initially introduced in `appcd@4.0.0`.
* feat(project): Project service with endpoints for `new`, `build`, `run`, `clean`, and info.
[(DAEMON-26)](https://jira.appcelerator.org/browse/DAEMON-26)
[(DAEMON-21)](https://jira.appcelerator.org/browse/DAEMON-21)
* feat(cli): Added `new` command. [(DAEMON-301)](https://jira.appcelerator.org/browse/DAEMON-301)
* feat(cli): Added `clean` command.
[(DAEMON-327)](https://jira.appcelerator.org/browse/DAEMON-327)
* feat(cli): Added `build` and `run` commands.
[(DAEMON-16)](https://jira.appcelerator.org/browse/DAEMON-16)
* feat(cli): Added auth commands `login`, `logout`, `whoami`, and `switch`.
[(DAEMON-300)](https://jira.appcelerator.org/browse/DAEMON-300)
* feat(legacy): Legacy Titanium CLI bootstrap for loading a Titanium SDK and running a `build` or
`clean` command. For differences between this and Titanium CLI v5, see the
[readme](https://github.com/appcelerator/appcd-plugin-titanium/blob/master/src/legacy/README.md).
* feat(legacy): Added support for remote encryption.
* feat(cli:sdk): Added aliases to sdk commands (i, ls, rm).
* feat(sdk): Added `find` endpoint to SDK service to get info about an installed Titanium SDK.
* feat(sdk): Added progress bars during SDK installation.
* feat(module): Added `/module/check-downloads` endpoint.
* feat(module): Added `/module/install` endpoint.
* feat(module): Added automatic checking of new Titanium module downloads.
* feat: Support for Titanium-specific telemetry.
* feat: Added HTTP proxy support.
* feat: Adopted appcd 4.x new `appcd.config.*`.
* feat(cli): Added `register` command to replace old --import flag.
* feat(project): Added `/project/register` endpoint.
* feat(amplify): Upgraded from AMPLIFY appcd plugin v1.x to v2.x.
* refactor: Updated to latest cli-kit with support for the new client/server architecture.
* refactor: Updated `config` command actions to be subcommands with improved help output.
* fix(legacy): Improved logging of uncaught exceptions and rejections.
* chore: Removed `source-map-support` as `appcd-plugin` already hooks it up.
* chore: Added plugin API version 2.x.
* chore: Transpile for Node 10 instead of Node 8. Not a breaking change as appcd has always
guaranteed Node 10 or newer.
* chore: Updated dependencies.

# v1.8.2 (Jan 26, 2021)

* refactor: Updated to cli-kit@1.9.3 adding support for the new client/server architecture.
Expand Down
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

Titanium SDK services for the Appc Daemon.

## Services
> This plugin requires appcd plugin API version 2.x which was introduced in appcd@4.0.0 and the
> AMPLIFY appcd plugin v2.x.

## Service Endpoints

* [SDKs](#SDKs)
- [`/sdk/list/installed`](#sdklistinstalled)
Expand Down Expand Up @@ -131,6 +134,24 @@ $ appcd exec /titanium/latest/sdk/list/releases
}
```

### `/sdk/find/:name?`

Returns information about the specified installed SDK.

#### CLI Usage

```sh
$ appcd exec /titanium/latest/sdk/find
```

```sh
$ appcd exec /titanium/latest/sdk/find/latest
```

```sh
$ appcd exec /titanium/latest/sdk/find/9.0.0.GA
```

### `/sdk/list/branches`

Returns a list of continuous integration branches and which one is the default.
Expand Down
7 changes: 0 additions & 7 deletions conf/config.js

This file was deleted.

7 changes: 7 additions & 0 deletions conf/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"home": "~/.axway/titanium",
"searchPaths": [],
"telemetry": {
"app": "de93eb9e-e53c-4f3a-9222-9e0d124950e5"
}
}
25 changes: 20 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,35 @@
"test": "gulp test"
},
"dependencies": {
"@axway/amplify-request": "^2.1.1",
"@titanium-sdk/node-is-platform-guid": "^1.0.2",
"appc-security": "^0.1.0",
"appcd-fs": "^2.0.4",
"appcd-path": "^2.0.5",
"appcd-util": "^3.1.3",
"chalk": "^4.1.0",
"cli-kit": "^1.9.3",
"colors": "^1.4.0",
"dateformat": "^4.5.0",
"enquirer": "^2.3.6",
"figures": "^3.2.0",
"filesize": "^6.1.0",
"form-data": "^3.0.0",
"fs-extra": "^9.1.0",
"gawk": "^5.0.0",
"get-port": "^5.1.1",
"node-pty-prebuilt-multiarch": "^0.9.0",
"global-modules": "^2.0.0",
"node-forge": "^0.10.0",
"open": "^7.3.1",
"pluralize": "^8.0.0",
"prompts": "^2.4.0",
"progress": "^2.0.3",
"semver": "^7.3.4",
"simple-plist": "^1.1.1",
"sort-object-keys": "^1.1.3",
"source-map-support": "^0.5.19",
"tar": "^6.1.0",
"titaniumlib": "^3.0.1",
"tmp": "^0.2.1",
"v8-compile-cache": "^2.2.0",
"yauzl": "^2.10.0"
},
"devDependencies": {
Expand All @@ -39,8 +54,8 @@
"bugs": "https://github.com/appcelerator/appcd-plugin-titanium/issues",
"repository": "https://github.com/appcelerator/appcd-plugin-titanium",
"appcd": {
"apiVersion": "1.x || 2.x",
"config": "./conf/config.js",
"apiVersion": "2.x",
"config": "./conf/config.json",
"name": "titanium",
"type": "external"
},
Expand Down
89 changes: 89 additions & 0 deletions src/cli/auth/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { prompt } from '../../lib/prompt';

const { alert, highlight } = appcd.logger.styles;

/**
* Performs a login.
*
* @param {Object} opts - Various options.
* @param {Array.<String>} opts.argv - The parsed command line arguments.
* @param {Console} opts.console - The console instance to write to.
* @param {Function} opts.setExitCode - A function to set the exit code.
* @param {Terminal} opts.terminal - A cli-kit Terminal instance.
* @returns {Object} The account info.
*/
export async function login({ argv, console, setExitCode, terminal }) {
const data = {
baseUrl: argv.baseUrl,
clientId: argv.clientId,
clientSecret: argv.clientSecret,
env: argv.env,
force: argv.force,
password: argv.password,
secretFile: argv.secretFile,
username: argv.username
};

if (argv.username !== undefined) {
const questions = [];

if (!argv.username || typeof argv.username !== 'string') {
questions.push({
type: 'input',
name: 'username',
message: 'Username:',
validate(s) {
return !!s || 'Please enter your username';
}
});
}

if (!argv.password || typeof argv.password !== 'string') {
questions.push({
type: 'password',
name: 'password',
message: 'Password:',
validate(s) {
return !!s || 'Please enter your password';
}
});
}

if (questions.length && argv.json) {
throw new Error('--username and --password are required when --json is set');
}

Object.assign(data, await prompt(questions, terminal));

if (!argv.json) {
// add a newline after prompting has completed
console.log();
}
}

try {
const { response: account } = await appcd.call('/amplify/2.x/auth/login', { data });
try {
await appcd.call('/module/check-downloads', { data: { accountName: account.name } });
} catch (err) {
// squelch
}
return account;
} catch (err) {
if (err.code === 'EAUTHENTICATED') {
const { account } = err;
if (argv.json) {
console.log(JSON.stringify(account, null, 2));
} else {
console.log(`You are already logged into ${highlight(account.org.name)} as ${highlight(account.user.email || account.name)}.`);
}
} else if (err.code === 'ERR_AUTH_FAILED') {
console.error(alert(err.message));
setExitCode(1);
} else {
throw err;
}
}
}

export default login;
65 changes: 55 additions & 10 deletions src/cli/cli-service.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import CLI, { snooplogg } from 'cli-kit';
import CLI from 'cli-kit';
import Dispatcher from 'appcd-dispatcher';
import fs from 'fs';
import getPort from 'get-port';
import path from 'path';

import { get } from 'appcd-util';
import { isFile } from 'appcd-fs';
import { loadOptions } from './run-legacy';
import { parseVersion } from '../lib/util';
// import { Tiapp } from 'titaniumlib';

const { highlight } = snooplogg.styles;
const { log } = appcd.logger('cli-service');
const { highlight } = appcd.logger.styles;

/**
* Defines a service endpoint for defining, processing, and dispatching Titanium CLI commands.
Expand All @@ -16,11 +19,10 @@ export default class CLIService extends Dispatcher {
/**
* Registers all of the endpoints.
*
* @param {Object} cfg - The Appc Daemon config object.
* @returns {Promise}
* @access public
*/
async activate(cfg) {
async activate() {
const pluginVersion = JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', '..', 'package.json'))).version;

const cli = new CLI({
Expand All @@ -31,18 +33,61 @@ export default class CLIService extends Dispatcher {
help: true,
helpExitCode: 2,
name: 'titanium',
options: {
'--no-prompt': 'Disable interactive prompting'
},
serverMode: true,
styles: {
subheading(s) {
return `\n${String(s).toUpperCase()}`;
}
},
version: ({ data }) => parseVersion(data.userAgent)
});

// inject the titanium config into the command data object before parsing starts so that
// it's available to the command callback
cli.on('parse', ({ data }) => {
data.config = appcd.config.get('titanium');
data.pluginVersion = pluginVersion;
});

// we need to add platform specific options for the build/run help, so first we listen for
// the help command, then we add in the options before the help is generated
cli.on('exec', async ({ cmd, contexts, data }) => {
// we need the help command, the build/run command, and a cwd containing a tiapp
cmd = data?.cwd && cmd?.name === 'help' && contexts[1];

if (!cmd || (cmd.name !== 'build' && cmd.name !== 'run')) {
return;
}

const tiappFile = path.resolve(data.cwd, 'tiapp.xml');
if (!isFile(tiappFile)) {
return;
}

cmd.on('generateHelp', async ctx => {
const sdk = '9.0.3.GA'; // data.tiapp.get('sdk-version');
await loadOptions({ config: data.config, ctx, sdk });
});
});

// find an available port to listen on
const port = await getPort({
port: get(cfg, 'port', 1733)
port: appcd.config.get('port', 1733)
});

// start the cli-kit server
this.server = await cli.listen({ port });

this.register('/', () => ({
url: `ws://127.0.0.1:${port}`
}));
// register the discovery endpoint for the cli-kit server
this.register('/', () => {
log(`Returning CLI server URL: ${highlight(`ws://127.0.0.1:${port}`)}`);
return {
url: `ws://127.0.0.1:${port}`
};
});

this.register('/schema', ({ headers }) => cli.schema({
data: {
Expand All @@ -52,7 +97,7 @@ export default class CLIService extends Dispatcher {
}

/**
* Perform any necessary cleanup.
* Stop the CLI server.
*
* @returns {Promise}
* @access public
Expand Down
19 changes: 19 additions & 0 deletions src/cli/commands/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { promptLoop } from '../../lib/prompt';

export default {
desc: 'Add a component or service to a project',
options: {
'-d, --project-dir [path]': 'The directory containing the project; defaults to the current directory'
},
async action(ctx) {
await promptLoop({
ctx,
data: {
cwd: ctx.data.cwd,
...ctx.argv
},
path: '/project/add',
ns: 'cli:add'
});
}
};
Loading