Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Commit

Permalink
Rename to polymer-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfagnani committed May 9, 2016
1 parent 9cf23ea commit a1a6f4f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 35 deletions.
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
# polytool
# polymer-cli

A command-line tool for Polymer projects

## Installation

$ npm install -g polytool
$ npm install -g polymer-cli

## Usage

### Display help:

$ polytool help
$ polymer help

### Start the development server
### Initialize a project folders

$ polymer init

$ polytool serve
### List a project

$ polymer lint index.html

### Run web-component-tester tests

$ polytool test
$ polymer test

### Build a project

$ polymer build --main index.html --shell src/my-app/my-app.html

### Start the development server

$ polymer serve
8 changes: 4 additions & 4 deletions bin/polytool.js → bin/polymer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
*/
var resolve = require('resolve');

process.title = 'polytool';
process.title = 'polymer';

resolve('polytool', {basedir: process.cwd()}, function(error, path) {
resolve('polymer-cli', {basedir: process.cwd()}, function(error, path) {
let lib = path ? require(path) : require('..');
let polytool = new lib.Polytool();
polytool.run(process.argv.slice(2));
let cli = new lib.PolymerCli();
cli.run(process.argv.slice(2));
});
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"name": "polytool",
"name": "polymer-cli",
"version": "0.0.6",
"description": "A commandline tool for Polymer projects",
"main": "lib/polytool.js",
"bin": "bin/polytool.js",
"main": "lib/polymer-cli.js",
"bin": {
"polymer": "bin/polymer.js"
},
"scripts": {
"init": "typings install",
"build": "if [ ! -f typings/main.d.ts ]; then npm run init; fi; tsc",
"test": "depcheck . && gulp test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Polymer/polytool.git"
"url": "git+https://github.com/Polymer/polymer-cli.git"
},
"author": "The Polymer Project Authors",
"license": "BSD-3-Clause",
Expand Down
8 changes: 4 additions & 4 deletions src/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export class HelpCommand implements Command {
}

printGeneralUsage() {
console.log(`\nUsage: polytool <command>\n`);
console.log(`polytool supports the following commands:`);
console.log(`\nUsage: polymer <command>\n`);
console.log(`polymer supports the following commands:`);
for (let command of this.commands.values()) {
console.log(` ${command.name}\t\t${command.description}`);
}
console.log(`\nRun \`polytool help <command>\` for help with a specific command.\n`);
console.log(`\nRun \`polymer help <command>\` for help with a specific command.\n`);
}

run(options): Promise<any> {
Expand All @@ -45,7 +45,7 @@ export class HelpCommand implements Command {

let argsCli = commandLineArgs(command.args);
console.log(argsCli.getUsage({
title: `polytool ${command.name}`,
title: `polymer ${command.name}`,
description: command.description,
}));
resolve(null);
Expand Down
10 changes: 4 additions & 6 deletions src/polytool.ts → src/polymer-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {ServeCommand} from './commands/serve';
import {TestCommand} from './commands/test';
import {Command} from './commands/command';

export class Polytool {
export class PolymerCli {

commandDescriptors = [];
commands : Map<String, Command> = new Map();
Expand All @@ -44,12 +44,10 @@ export class Polytool {
run(args) {
this.cli = commandLineCommands(this.commandDescriptors);
let cliCommand = this.cli.parse(args);
let polytoolCommand = this.commands.get(cliCommand.name || 'help');
let command = this.commands.get(cliCommand.name || 'help');

polytoolCommand.run(cliCommand.options).then((result) => {
// success
}, (err) => {
console.error('error', err);
command.run(cliCommand.options).catch((error) => {
console.error('error', error);
});
}
}
20 changes: 10 additions & 10 deletions test/commands/help_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@
'use strict';

const assert = require('chai').assert;
const Polytool = require('../../lib/polytool').Polytool;
const PolymerCli = require('../../lib/polymer-cli').PolymerCli;
const sinon = require('sinon');

suite('help', () => {

test('displays general help when the help command is called with no arguments', () => {
let polytool = new Polytool();
let helpCommand = polytool.commands.get('help');
let cli = new PolymerCli();
let helpCommand = cli.commands.get('help');
let helpCommandSpy = sinon.spy(helpCommand, 'run');
polytool.run(['help']);
cli.run(['help']);
assert.isOk(helpCommandSpy.calledOnce);
assert.deepEqual(helpCommandSpy.firstCall.args, [{}]);
});

test('displays general help when no command is called', () => {
let polytool = new Polytool();
let helpCommand = polytool.commands.get('help');
let cli = new PolymerCli();
let helpCommand = cli.commands.get('help');
let helpCommandSpy = sinon.spy(helpCommand, 'run');
polytool.run([]);
cli.run([]);
assert.isOk(helpCommandSpy.calledOnce);
assert.deepEqual(helpCommandSpy.firstCall.args, [undefined]);
});

test('displays general help when unknown command is called', () => {
let polytool = new Polytool();
let helpCommand = polytool.commands.get('help');
let cli = new PolymerCli();
let helpCommand = cli.commands.get('help');
let helpCommandSpy = sinon.spy(helpCommand, 'run');
polytool.run(['THIS_IS_SOME_UNKNOWN_COMMAND']);
cli.run(['THIS_IS_SOME_UNKNOWN_COMMAND']);
assert.isOk(helpCommandSpy.calledOnce);
assert.deepEqual(helpCommandSpy.firstCall.args, [undefined]);
});
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"src/commands/serve.ts",
"src/commands/test.ts",
"src/github/github.ts",
"src/polytool.ts",
"src/polymer-cli.ts",
"src/templates/polykart.ts",
"custom_typings/command-line-args.d.ts",
"custom_typings/command-line-commands.d.ts",
Expand Down

0 comments on commit a1a6f4f

Please sign in to comment.