Skip to content

Commit

Permalink
Add class for project
Browse files Browse the repository at this point in the history
Read spec file to populate certain fields of project class

Change-type: minor
Signed-off-by: Anuj Deshpande <anuj@balena.io>
  • Loading branch information
anujdeshpande committed May 5, 2020
1 parent eb8984e commit 364f3b3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -6,12 +6,12 @@
"main": "build/index.js",
"bin": {
"rfq": "index.js"
},
},
"directories": {
"test": "test"
},
"scripts": {
"prepublish":"npm run build",
"scripts": {
"prepublish": "npm run build",
"test": "jest && npm run lint",
"build": "tsc",
"start": "node ./build/index.js",
Expand All @@ -37,6 +37,7 @@
},
"dependencies": {
"@balena/lint": "^5.0.4",
"@types/lodash": "^4.14.150",
"capitano": "^1.9.2"
}
}
51 changes: 48 additions & 3 deletions src/index.ts
@@ -1,12 +1,57 @@
import * as capitano from 'capitano';
import * as fs from 'fs';
import * as _ from 'lodash';

function generate() {
console.log('Hello world');
const specPath: string = '/source/specification/spec.json';
const testPath: string = '/testing/';

class Project {
public name: string = '';
public inPath: string = '';
public outPath: string = '';
public projectType: string = '';

constructor() {
this.outPath = 'outputs/';
}
}

let proj = new Project();

const generate = async (
params: { folder: string },
options: { output: string },
) => {
proj.inPath = params.folder;
if (!_.isNil(options.output)) {
proj.outPath = options.output;
}
let specFile = JSON.parse(fs.readFileSync(proj.inPath + specPath).toString());
proj.name = specFile.name;
proj.projectType = specFile.hwType;
console.log(
'Project name\t - ',
proj.name,
'\nInput folder\t - ',
proj.inPath,
' \nOutput folder\t - ',
proj.outPath,
'\nHardware Type\t - ',
proj.projectType,
);
};

capitano.command({
signature: 'generate <path>',
signature: 'generate <folder>',
description: 'Generate a target-specific RFQ from a repository',
options: [
{
signature: 'output',
parameter: 'output',
alias: ['o'],
description: 'Output directory, defaults to path if not specified',
},
],
action: generate,
});

Expand Down

0 comments on commit 364f3b3

Please sign in to comment.