Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
l0rd committed Nov 20, 2018
0 parents commit 8d7e32d
Showing 16 changed files with 2,854 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*-debug.log
*-error.log
/.nyc_output
/dist
/lib
/package-lock.json
/tmp
node_modules
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
chectl
======

Eclipse Che CLI

[![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
[![Version](https://img.shields.io/npm/v/chectl.svg)](https://npmjs.org/package/chectl)
[![Downloads/week](https://img.shields.io/npm/dw/chectl.svg)](https://npmjs.org/package/chectl)
[![License](https://img.shields.io/npm/l/chectl.svg)](https://github.com/l0rd/chectl/blob/master/package.json)

<!-- toc -->
* [Usage](#usage)
* [Commands](#commands)
<!-- tocstop -->
# Usage
<!-- usage -->
```sh-session
$ npm install -g chectl
$ chectl COMMAND
running command...
$ chectl (-v|--version|version)
chectl/0.0.2 darwin-x64 node-v8.9.1
$ chectl --help [COMMAND]
USAGE
$ chectl COMMAND
...
```
<!-- usagestop -->
# Commands
<!-- commands -->
* [`chectl hello [FILE]`](#chectl-hello-file)
* [`chectl help [COMMAND]`](#chectl-help-command)

## `chectl hello [FILE]`

describe the command here

```
USAGE
$ chectl hello [FILE]
OPTIONS
-f, --force
-h, --help show CLI help
-n, --name=name name to print
EXAMPLE
$ chectl hello
hello world from ./src/hello.ts!
```

_See code: [src/commands/hello.ts](https://github.com/l0rd/chectl/blob/v0.0.2/src/commands/hello.ts)_

## `chectl help [COMMAND]`

display help for chectl

```
USAGE
$ chectl help [COMMAND]
ARGUMENTS
COMMAND command to show help for
OPTIONS
--all see all commands in CLI
```

_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.1.4/src/commands/help.ts)_
<!-- commandsstop -->
5 changes: 5 additions & 0 deletions bin/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

require('@oclif/command').run()
.then(require('@oclif/command/flush'))
.catch(require('@oclif/errors/handle'))
3 changes: 3 additions & 0 deletions bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
63 changes: 63 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "chectl",
"description": "Eclipse Che CLI",
"version": "0.0.2",
"author": "Mario Loriedo @l0rd",
"bin": {
"chectl": "./bin/run"
},
"bugs": "https://github.com/l0rd/chectl/issues",
"dependencies": {
"@oclif/command": "^1",
"@oclif/config": "^1",
"@oclif/plugin-help": "^2",
"command-exists": "^1.2.8",
"tslib": "^1"
},
"devDependencies": {
"@oclif/dev-cli": "^1",
"@oclif/test": "^1",
"@oclif/tslint": "^3",
"@types/chai": "^4",
"@types/mocha": "^5",
"@types/node": "^10",
"chai": "^4",
"globby": "^8",
"mocha": "^5",
"nyc": "^13",
"ts-node": "^7",
"tslint": "^5",
"typescript": "^3.0"
},
"engines": {
"node": ">=8.0.0"
},
"files": [
"/bin",
"/lib",
"/npm-shrinkwrap.json",
"/oclif.manifest.json"
],
"homepage": "https://github.com/l0rd/chectl",
"keywords": [
"oclif"
],
"license": "MIT",
"main": "lib/index.js",
"oclif": {
"commands": "./lib/commands",
"bin": "chectl",
"plugins": [
"@oclif/plugin-help"
]
},
"repository": "l0rd/chectl",
"scripts": {
"postpack": "rm -f oclif.manifest.json",
"posttest": "tslint -p test -t stylish",
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
"version": "oclif-dev readme && git add README.md"
},
"types": "lib/index.d.ts"
}
31 changes: 31 additions & 0 deletions src/commands/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {Command, flags} from '@oclif/command'

export default class Hello extends Command {
static description = 'describe the command here'

static examples = [
`$ chectl hello
hello world from ./src/hello.ts!
`,
]

static flags = {
help: flags.help({char: 'h'}),
// flag with a value (-n, --name=VALUE)
name: flags.string({char: 'n', description: 'name to print'}),
// flag with no value (-f, --force)
force: flags.boolean({char: 'f'}),
}

static args = [{name: 'file'}]

async run() {
const {args, flags} = this.parse(Hello)

const name = flags.name || 'world'
this.log(`hello ${name} from ./src/commands/hello.ts`)
if (args.file && flags.force) {
this.log(`you input --force and --file: ${args.file}`)
}
}
}
164 changes: 164 additions & 0 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import {Command, flags} from '@oclif/command'
import {commandExists} from 'command-exists'
import { isNull } from 'util';
import { string } from '@oclif/parser/lib/flags';

export default class Run extends Command {
static description = 'Run Eclipse Che'

static flags = {
help: flags.help({char: 'h'}),
"che-local-git-repository": flags.string({
char: 'r',
description: 'path to Che local git repository',
default: '~/github/che',
env: 'CHE_LOCAL_GIT_REPO'}),
force: flags.boolean({char: 'f'}),
}

static args = [{name: 'file'}]

async run() {
const {args, flags} = this.parse(Run)

preFlightChecks();
configureMinikube();

}
}

function preFlightChecks() {
checkPrerequisites();
checkStatus();
}

function checkPrerequisites() {
var commandExists = require('command-exists');
commandExists('minikube', function (err: any, commandExists: any) {
if (!commandExists) {
console.error('ERROR: minikube is not installed.');
return -1;
}
console.log("Minikube is installed");
});
commandExists('helm', function (err: any, commandExists: any) {
if (!commandExists) {
console.error('ERROR: helm is not installed.');
return -1;
}
console.log("Helm is installed");
});
}

function checkStatus() {
const { exec } = require('child_process');
exec('minikube status', (err: any, stdout: any, stderr: any) => {
if (!isNull(err)) {
console.error('ERROR: command \'minikube status\' failed');
console.error(`${stdout}`);
return -1;
}

if (!stdout.includes("Running")) {
console.error('ERROR: command \'minikube status\' failed');
console.error(`stdout: ${stdout}`);
return -1;
}
console.log("Minikube is running");
});
}

const { exec } = require('child_process');

function configureMinikube() {
exec('minikube addons enable ingress', (err: any, stdout: any, stderr: any) => {
if (!isNull(err)) {
console.error('ERROR: command \'minikube addons enable ingress\' failed');
console.error(`${stdout}`);
return -1;
}
console.log("Ingress Addon Enabled Successfully");
});

exec('kubectl get clusterrolebinding add-on-cluster-admin', (err: any, stdout: any, stderr: any) => {
if (isNull(err)) {
console.log("RoleBinding \'add-on-cluster-admin\' already exists, no need to create it");
} else {
exec('kubectl create clusterrolebinding add-on-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:default', (err: any, stdout: any, stderr: any) => {
if (isNull(err)) {
console.error('ERROR: command \'kubectl create clusterrolebinding add-on-cluster-admin\' failed');
console.error(`${stdout}`);
return -1;
}
console.log("RoleBinding \'add-on-cluster-admin\' created successfully");
});
}
});
}

function installHelm(){
exec('kubectl get serviceaccounts tiller --namespace kube-system', (err: any, stdout: any, stderr: any) => {
if (isNull(err)) {
console.log("Service account \'tiller\' already exists, no need to create it");
} else {
exec('kubectl create serviceaccount tiller --namespace kube-system', (err: any, stdout: any, stderr: any) => {
if (isNull(err)) {
console.error('ERROR: command \'kubectl create serviceaccount tiller --namespace kube-system\' failed');
console.error(`${stdout}`);
return -1;
}
console.log("Service account \'tiller\' created successfully");
});
}
});

exec('kubectl apply -f ${ flags."che-local-git-repository" }/deploy/kubernetes/helm/che/tiller-rbac.yaml', (err: any, stdout: any, stderr: any) => {
if (!isNull(err)) {
console.error('ERROR: command \'kubectl apply -f ${ flags."che-local-git-repository" }/deploy/kubernetes/helm/che/tiller-rbac.yaml\' failed');
console.error(`${stdout}`);
return -1;
}
console.log("Tiller RBAC created successfully");
});

exec('kubectl get services tiller-deploy -n kube-system', (err: any, stdout: any, stderr: any) => {
if (isNull(err)) {
console.log("Tiller service already exists, no need to deploy it");
} else {
exec('helm init --service-account tiller', (err: any, stdout: any, stderr: any) => {
if (isNull(err)) {
console.error('ERROR: command \'kubectl create serviceaccount tiller --namespace kube-system\' failed');
console.error(`${stdout}`);
return -1;
}
console.log("Tiller has been deployed successfully");
});
}
});
}

function deployChe(){
let command: string = "helm upgrade \
\n--install che \
\n--namespace ${ flags. } \
\n--set global.ingressDomain=$(minikube ip).nip.io \
\n--set cheImage=eclipse/che-server:nightly \
\n--set global.cheWorkspacesNamespace=${CHE_NAMESPACE} \
\n${CHE_LOCAL_GIT_REPO}/deploy/kubernetes/helm/che/"

exec(command, (err: any, stdout: any, stderr: any) => {
if (isNull(err)) {
console.log("Service account \'tiller\' already exists, no need to create it");
} else {
exec('kubectl create serviceaccount tiller --namespace kube-system', (err: any, stdout: any, stderr: any) => {
if (isNull(err)) {
console.error('ERROR: command \'kubectl create serviceaccount tiller --namespace kube-system\' failed');
console.error(`${stdout}`);
return -1;
}
console.log("Service account \'tiller\' created successfully");
});
}
});
}

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {run} from '@oclif/command'
17 changes: 17 additions & 0 deletions test/commands/hello.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {expect, test} from '@oclif/test'

describe('hello', () => {
test
.stdout()
.command(['hello'])
.it('runs hello', ctx => {
expect(ctx.stdout).to.contain('hello world')
})

test
.stdout()
.command(['hello', '--name', 'jeff'])
.it('runs hello --name jeff', ctx => {
expect(ctx.stdout).to.contain('hello jeff')
})
})
17 changes: 17 additions & 0 deletions test/commands/run.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {expect, test} from '@oclif/test'

describe('run', () => {
test
.stdout()
.command(['run'])
.it('runs hello', ctx => {
expect(ctx.stdout).to.contain('hello world')
})

test
.stdout()
.command(['run', '--name', 'jeff'])
.it('runs hello --name jeff', ctx => {
expect(ctx.stdout).to.contain('hello jeff')
})
})
5 changes: 5 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--require ts-node/register
--watch-extensions ts
--recursive
--reporter spec
--timeout 5000
9 changes: 9 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig",
"compilerOptions": {
"noEmit": true
},
"references": [
{"path": ".."}
]
}
15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"declaration": true,
"importHelpers": true,
"module": "commonjs",
"outDir": "lib",
"rootDir": "src",
"strict": true,
"target": "es2017",
"composite": true
},
"include": [
"src/**/*"
]
}
3 changes: 3 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@oclif/tslint"
}
2,432 changes: 2,432 additions & 0 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 8d7e32d

Please sign in to comment.