Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ testem.log
# System Files
.DS_Store
Thumbs.db

# testing folder from cli
my-first-vulcan-project
test-vulcan-project
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": ["build", "lint", "test", "e2e"]
"cacheableOperations": ["build", "lint", "test", "e2e", "tsc"]
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
"dependencies": {
"@koa/cors": "^3.3.0",
"class-validator": "^0.13.2",
"commander": "^9.4.0",
"dayjs": "^1.11.2",
"glob": "^8.0.1",
"inquirer": "^8.0.0",
"inversify": "^6.0.1",
"joi": "^17.6.0",
"js-yaml": "^4.1.0",
Expand All @@ -22,6 +24,7 @@
"lodash": "^4.17.21",
"nunjucks": "^3.2.3",
"openapi3-ts": "^2.0.2",
"ora": "^5.4.1",
"reflect-metadata": "^0.1.13",
"tslib": "^2.3.0",
"tslog": "^3.3.3",
Expand All @@ -37,6 +40,7 @@
"@nrwl/workspace": "14.0.3",
"@types/from2": "^2.3.1",
"@types/glob": "^7.2.0",
"@types/inquirer": "^8.0.0",
"@types/jest": "27.4.1",
"@types/js-yaml": "^4.0.5",
"@types/koa": "^2.13.4",
Expand Down
26 changes: 24 additions & 2 deletions packages/build/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
{
"name": "@vulcan-sql/build",
"version": "0.0.1",
"type": "commonjs"
"description": "Vulcan package for building projects",
"version": "0.1.0-alpha.1",
"type": "commonjs",
"publishConfig": {
"access": "public"
},
"keywords": [
"vulcan",
"vulcan-sql",
"data",
"sql",
"database",
"data-warehouse",
"data-lake",
"api-builder"
],
"repository": {
"type": "git",
"url": "https://github.com/Canner/vulcan.git"
},
"license": "MIT",
"peerDependencies": {
"@vulcan-sql/core": "0.1.0-alpha.1"
}
}
36 changes: 34 additions & 2 deletions packages/build/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,33 @@
"sourceRoot": "packages/build/src",
"targets": {
"build": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"command": "yarn ts-node ./tools/scripts/replaceAlias.ts build"
},
"dependsOn": [
{
"projects": "self",
"target": "tsc"
}
]
},
"tsc": {
"executor": "@nrwl/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/build",
"main": "packages/build/src/index.ts",
"tsConfig": "packages/build/tsconfig.lib.json",
"assets": ["packages/build/*.md"]
}
"assets": ["packages/build/*.md"],
"buildableProjectDepsInPackageJsonType": "dependencies"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the property buildableProjectDepsInPackageJsonType could the nx automatically add dependencies and buildable libraries so that we could publish a library with all dependencies ? (nrwl/nx#4620)

if it is true, maybe you could add the comment to let others know the purpose so that we could remind it to add when we create new nx packages and would like to publish in the future?

Copy link
Contributor Author

@oscar60310 oscar60310 Aug 19, 2022

Choose a reason for hiding this comment

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

https://nx.dev/packages/js/executors/tsc
The property updateBuildableProjectDepsInPackageJson control whether to add dependencies to package.json or not, its default value is true.

The setting here enforces the generator put these dependencies to "dependencies" but not "peerDependencies", I'll add some comments to tell the reason

Update: We can't add comments in JSON file 🤣

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @oscar60310 for answering my question, it was really helpful for me to understand its importance in the project.

That's fine. 😄 Still thanks for sharing the message, if there, I will memo it in my note.

},
"dependsOn": [
{
"projects": "dependencies",
"target": "build"
}
]
},
"lint": {
"executor": "@nrwl/linter:eslint",
Expand All @@ -26,6 +45,19 @@
"jestConfig": "packages/build/jest.config.ts",
"passWithNoTests": true
}
},
"publish": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"command": "node ../../../tools/scripts/publish.mjs {args.tag}",
"cwd": "dist/packages/build"
},
"dependsOn": [
{
"projects": "self",
"target": "build"
}
]
}
},
"tags": []
Expand Down
9 changes: 7 additions & 2 deletions packages/build/src/lib/vulcanBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ import {
import { DocumentGenerator } from './document-generator';

export class VulcanBuilder {
public async build(options: IBuildOptions) {
private options: IBuildOptions;
constructor(options: IBuildOptions) {
this.options = options;
}

public async build() {
const container = new Container();
await container.load(options);
await container.load(this.options);
const schemaParser = container.get<SchemaParser>(TYPES.SchemaParser);
const templateEngine = container.get<TemplateEngine>(
CORE_TYPES.TemplateEngine
Expand Down
4 changes: 2 additions & 2 deletions packages/build/test/builder/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {

it('Builder.build should work', async () => {
// Arrange
const builder = new VulcanBuilder();
const options: IBuildOptions = {
'schema-parser': {
reader: SchemaReaderType.LocalFile,
Expand All @@ -34,7 +33,8 @@ it('Builder.build should work', async () => {
},
extensions: {},
};
const builder = new VulcanBuilder(options);

// Act, Assert
await expect(builder.build(options)).resolves.not.toThrow();
await expect(builder.build()).resolves.not.toThrow();
});
18 changes: 18 additions & 0 deletions packages/cli/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
12 changes: 12 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# cli

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build cli` to build the library.

## Running unit tests

Run `nx test cli` to execute the unit tests via [Jest](https://jestjs.io).

14 changes: 14 additions & 0 deletions packages/cli/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
displayName: 'cli',
preset: '../../jest.preset.ts',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/packages/cli',
};
27 changes: 27 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@vulcan-sql/cli",
"description": "CLI tools for Vulcan",
"version": "0.1.0-alpha.1",
"type": "commonjs",
"bin": {
"vulcan": "./src/index.js"
},
"publishConfig": {
"access": "public"
},
"keywords": [
"vulcan",
"vulcan-sql",
"data",
"sql",
"database",
"data-warehouse",
"data-lake",
"api-builder"
],
"repository": {
"type": "git",
"url": "https://github.com/Canner/vulcan.git"
},
"license": "MIT"
}
91 changes: 91 additions & 0 deletions packages/cli/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"root": "packages/cli",
"sourceRoot": "packages/cli/src",
"targets": {
"build": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"commands": [
{
"command": "yarn ts-node ./tools/scripts/replaceAlias.ts cli",
"forwardAllArgs": false
},
{
"command": "chmod +x dist/packages/cli/src/index.js",
"forwardAllArgs": false
}
]
},
"dependsOn": [
{
"projects": "self",
"target": "tsc"
}
]
},
"tsc": {
"executor": "@nrwl/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/cli",
"main": "packages/cli/src/index.ts",
"tsConfig": "packages/cli/tsconfig.lib.json",
"assets": ["packages/cli/*.md", "packages/cli/src/schemas/**/*.*"],
"buildableProjectDepsInPackageJsonType": "dependencies"
},
"dependsOn": [
{
"projects": "dependencies",
"target": "build"
}
]
},
"publish": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"command": "node ../../../tools/scripts/publish.mjs {args.tag}",
"cwd": "dist/packages/cli"
},
"dependsOn": [
{
"projects": "self",
"target": "build"
}
]
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/cli/**/*.ts"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/packages/cli"],
"options": {
"jestConfig": "packages/cli/jest.config.ts",
"passWithNoTests": true
}
},
"install": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"commands": [
{
"command": "npm i -g . && echo done.",
"forwardAllArgs": false
}
],
"cwd": "dist/packages/cli"
},
"dependsOn": [
{
"projects": "self",
"target": "build"
}
]
}
},
"tags": []
}
61 changes: 61 additions & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { program } from 'commander';
import { handleInit, handleStart, handleVersion } from './commands';
import { handleBuild } from './commands/build';
import { handleServe } from './commands/serve';

program.exitOverride();

program
.command('version')
.description('show the version of CLI and Vulcan packages')
.action(async () => {
await handleVersion();
});

program
.command('init')
.description('create a new Vulcan project')
.option('-p --project-name <project-name>', 'specify project name')
.action(async (options) => {
await handleInit(options);
});

program
.command('build')
.description('build Vulcan project')
.option(
'-c --config <config-path>',
'path to Vulcan config file',
'./vulcan.yaml'
)
.action(async (options) => {
await handleBuild(options);
});

program
.command('serve')
.description('serve Vulcan project')
.option(
'-c --config <config-path>',
'path to Vulcan config file',
'./vulcan.yaml'
)
.option('-p --port <port>', 'server port', '3000')
.action(async (options) => {
await handleServe(options);
});

program
.command('start')
.description('build and serve Vulcan project')
.option(
'-c --config <config-path>',
'path to Vulcan config file',
'./vulcan.yaml'
)
.option('-p --port <port>', 'server port', '3000')
.action(async (options) => {
await handleStart(options);
});

export { program };
Loading