Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
60 changes: 60 additions & 0 deletions app/cli-client/.angular-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "angular-cli"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"deployUrl": "",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"test": "sys/unit/test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"polyfills": "sys/polyfills.ts",
"prefix": "app",
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
},
"styles": [
"styles/angular.scss"
],
"scripts": []
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json",
"exclude": "**/node_modules/**"
},
{
"project": "src/tsconfig.spec.json",
"exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "scss",
"serve": {
"port": 9876
},
"component": {}
}
}
10 changes: 10 additions & 0 deletions app/cli-client/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
max_line_length = 79
trim_trailing_whitespace = true
3 changes: 3 additions & 0 deletions app/cli-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
/dist
/src/app/proto
25 changes: 25 additions & 0 deletions app/cli-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# CLI gRPC client

### Start local server
From root
```
sh ./app/run_localserver.sh
```

### Installation
Open second terminal. And from `app/cli-client`
```
npm install
```

### Create proto functions
```
npm run protoc
```

### Start angular client
```
npm start
```

Navigate to `http://localhost:9876/`
63 changes: 63 additions & 0 deletions app/cli-client/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const path = require('path');
const fs = require('fs-extra');
const gulp = require('gulp');
const clean = require('gulp-clean');
const { exec } = require('child_process');

const importPath = 'local_server/service/hello_world_service.proto';
const exportPath = './src/app/proto';
const rootPath = path.resolve('../');

gulp.task('default', ['protoc']);
gulp.task('protoc', () => {
// Create a proto folder
if (!fs.existsSync(exportPath)) {
fs.mkdirSync(exportPath);
}

var protoImportList = [];
// Copy all packages to the proto folder
function copyPackage(relativePath) {
const absolutePath = path.join(
rootPath,
relativePath
);
const filename = path.parse(absolutePath).base;
protoImportList.push(filename);
const newPackagePath = path.join(exportPath, filename);
fs.copySync(absolutePath, newPackagePath);

return newPackagePath;
}
const newCodeReviewPath = copyPackage(importPath);

// Create proto functions from the packages in the proto folder
const protoImport = protoImportList.join(' ');
exec(
'protoc ' +
`--proto_path=${exportPath} ` +
`--js_out=import_style=commonjs,binary:${exportPath} ` +
'--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts ' +
`--ts_out=service=true:${exportPath} ` +
protoImport,
protocOnLoad
);

// When protoc finished generating proto functions
function protocOnLoad(error) {
if (error) {
throw error;
}

// Remove all *.proto files from the proto folder
gulp.src(path.join(exportPath, '**/*.proto'))
.pipe(clean())
.on('data', () => {})
.on('end', removingOnLoad);
}

// When all *.proto files are removed
function removingOnLoad() {
console.log('Proto functions are successfully created.');
}
});
30 changes: 30 additions & 0 deletions app/cli-client/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
Loading