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

Moves cli to TypeScript and uses Inquirer.js #86

Merged
merged 2 commits into from
Jan 27, 2020

Conversation

andreban
Copy link
Member

@andreban andreban commented Jan 27, 2020

  • Moves the remaining JS files in cli/ to TypeScript
  • Replaces 'prompt' with 'Inquirer.js'

Closes #76
Closes #79

- Moves the remaining JS files in cli/ to TypeScript
- Replaces 'prompt' with 'Inquirer.js'
@andreban andreban requested a review from PEConn January 27, 2020 15:41
@@ -14,9 +14,7 @@
* limitations under the License.
*/

'use strict';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how come we're removing this?

Copy link
Member Author

@andreban andreban Jan 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have strict: true on tsconfig.json, so TypeScript will add 'use strict'to the output JS for us.

@@ -18,11 +18,10 @@ import {promisify} from 'util';
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import userPrompt = require('prompt');
import * as inquirer from 'inquirer';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not essential, but I'd still prefer we be precise with our imports.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit divided in the case where a library has many related methods.

When we import with import * as inquirer from 'inquirer', then we get to use inquirer.prompt(...) in the code, which makes it clear where prompt is coming from.

When we import with import {prompt} from 'inquirer', the call in the code becomes just prompt, which is less obvious where it comes from, unless you scan the imports.

WDYT?

@@ -21,6 +21,7 @@ import {template} from 'lodash';
import {promisify} from 'util';
import {TwaManifest} from './TwaManifest';
import Jimp = require('jimp');
import Log from './Log';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript question - why do some of these have {} and some don't?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Log, we do export default class Log. on TwaManifest, only export class TwaManifest.

import {isWebUri} from 'valid-url';

export function validatePassword(input: string): boolean {
return input.length > 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure we don't want something longer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to look at the requirements for keytool and replicate there. Doing on a following CL.

}

export function notEmpty(input: string): boolean {
return input.length > 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input.trim().length > 0 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. done

import prompt = require('prompt');
// TODO(andreban): Remove usage of any
export function get(schema: any): any; // eslint-disable-line @typescript-eslint/no-explicit-any
import Color = require('color');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And again with the imports questions, why is this require?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand the require one, but it's related to the underlying library being written in JavaScript. Using import * as Color from 'color', import {Color} from 'color' or import Color from 'color' reports the error below:

Module '"/Users/andreban/Projects/twa-bootstrap/node_modules/@types/color/index"' can only be default-imported using the 'esModuleInterop' flagts(1259)

index.d.ts(135, 1): This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.


async function help() {
export async function help(): Promise<void> {
return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

help is a no-op?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now... Need to add actual help messages (I'll do in another PR. Focusing this one on translating JS => TS)

type: 'input',
message: 'Domain being opened in the TWA:',
default: twaManifest.host,
validate: notEmpty,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could check this is a valid URL (future CL though).

Copy link
Member Author

@andreban andreban Jan 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is not a full URL, just the host component (I agree we should validate)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#31 is the one I created for those.

type: 'input',
message: 'Name of the application:',
default: twaManifest.name,
validate: notEmpty,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, we could check that this and launcherName aren't too long.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another good one for #31 (Adding here so I get the mentions in the issue)

}, {
name: 'themeColor',
type: 'input',
message: 'Color to be used for the status bar:',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's maybe worth putting an example of the value format (is it #232323, just 232323, either, both?).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value shows the correct format (#232323). Is this enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we accept a wide range of formats. Including blue, rgb(0, 0, 255), etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fine.

@andreban andreban merged commit b6c61c8 into GoogleChromeLabs:master Jan 27, 2020
@andreban andreban deleted the cli-typescript branch February 13, 2020 08:14
@andreban andreban mentioned this pull request Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace prompt with inquirer.js Convert Project into TypeScript
2 participants