Skip to content

Commit

Permalink
feat(tsbb): Refactor the tsbb code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 22, 2021
1 parent b45b9af commit c0023b6
Show file tree
Hide file tree
Showing 75 changed files with 831 additions and 1,140 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/ci.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build & Deploy
on:
push:
branches:
- dev
env:
SKIP_PREFLIGHT_CHECK: true
jobs:
build-deploy:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14

- name: Look Changelog
uses: jaywcjlove/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
filter-author: (jaywcjlove|小弟调调™|dependabot\[bot\]|Renovate Bot|renovate\-bot)
filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}'

- run: npm install
- run: npm run hoist
- run: npm run build

- name: example @example/basic
working-directory: example/basic
run: npm run build && npm run coverage

- name: example @example/express
working-directory: example/express
run: npm run build

- name: example @example/hapi
working-directory: example/hapi
run: npm run build

- name: example @example/express-typeorm
working-directory: example/express-typeorm
run: npm run build

- name: example @example/koa
working-directory: example/koa
run: npm run build

- name: example @example/react-component
working-directory: example/react-component
run: npm run build && npm run doc

- name: example @example/react-component-tsx
working-directory: example/react-component-tsx
run: |
npm run build:lib
npm run doc
cd lib/cjs
ls -al
- name: example @example/transform-typescript
working-directory: example/transform-typescript
run: npm run build
12 changes: 5 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
branches:
- master
- v2
tags:
- v*
env:
SKIP_PREFLIGHT_CHECK: true
jobs:
Expand All @@ -18,7 +16,7 @@ jobs:
node-version: 14

- name: Look Changelog
uses: jaywcjlove/[email protected].2
uses: jaywcjlove/[email protected].3
with:
token: ${{ secrets.GITHUB_TOKEN }}
filter-author: (jaywcjlove|小弟调调™|dependabot\[bot\]|Renovate Bot|renovate\-bot)
Expand Down Expand Up @@ -73,7 +71,7 @@ jobs:

- name: Generate Changelog
id: changelog
uses: jaywcjlove/[email protected].2
uses: jaywcjlove/[email protected].3
if: steps.create_tag.outputs.successful
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -202,6 +200,6 @@ jobs:
publish_branch: gh-pages
publish_dir: ./zip

- run: npm install @jsdevtools/npm-publish
- run: ./node_modules/.bin/npm-publish --token="${{ secrets.NPM_TOKEN }}" ./packages/tsbb/package.json
- run: ./node_modules/.bin/npm-publish --token="${{ secrets.NPM_TOKEN }}" ./packages/create-tsbb/package.json
- run: npm install @jsdevtools/npm-publish -g
- run: npm-publish --token="${{ secrets.NPM_TOKEN }}" ./packages/tsbb/package.json
- run: npm-publish --token="${{ secrets.NPM_TOKEN }}" ./packages/create-tsbb/package.json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ yarn-debug.log*
yarn-error.log*
lerna-debug.log*

yarn.lock
package-lock.json

# Diagnostic reports (https://nodejs.org/api/report.html)
Expand Down
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

./node_modules/.bin/pretty-quick --staged
1 change: 1 addition & 0 deletions example/basic/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Created by https://www.gitignore.io/api/node
# Edit at https://www.gitignore.io/?templates=node

esm
lib
package-lock.json
__snapshots__
Expand Down
11 changes: 3 additions & 8 deletions example/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@
"description": "Basic Example.",
"scripts": {
"start": "node lib/index.js",
"watch": "npm run watch:ts",
"watch:ts": "tsbb watch & npm run build:types -- --watch",
"build": "npm run build:ts && npm run build:types",
"build:ts": "tsbb build",
"build:types": "tsbb types",
"watch": "tsbb watch --no-esm",
"build": "tsbb build --no-esm",
"test": "tsbb test",
"coverage": "tsbb test --coverage"
},
"repository": {
"type": "git",
"url": "https://github.com/jaywcjlove/tsbb/tree/master/example/basic"
},
"jest": {},
"keywords": [],
"license": "MIT",
"devDependencies": {
"tsbb": "2.3.1"
},
"author": ""
}
}
4 changes: 1 addition & 3 deletions example/basic/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/// <reference types="jest" />

import index from './';

describe('sum', () => {
it('works', async () => {
const num = await index();
expect(num).toBe(11);
expect(num).toBe('22 Hello World');
});
});
11 changes: 3 additions & 8 deletions example/basic/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sum } from './utils/sum';
import { test } from './utils/Test';

class Test {
constructor() {}
Expand All @@ -7,19 +8,13 @@ class Test {
}
}

async function testHandle() {
console.log('>>>');
}

(() => {
const { sum } = require('./utils/sum');
const data = { a: 1 };
const result = { ...data };
console.log('>>>', sum(1, result.a));
})();

export default async () => {
const test = new Test();
await testHandle();
return sum(1, test.count());
const testHandle = new Test();
return `${sum(1, testHandle.count())} ${test('Hello World')}`;
};
17 changes: 17 additions & 0 deletions example/basic/src/utils/Test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export type Test = {
a: string;
b: number;
};

export type TestGood = {
a: string;
g: string;
b: number;
c: number;
e: number;
e333: number;
};

export function test(str: string) {
return `${str}`;
}
9 changes: 8 additions & 1 deletion example/basic/src/utils/a/a.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
* @param a
* @param b
*/
export function abs(a: number, b: number) {
export function abs(a: number, b: number, c?: string) {
return a + b;
}

export type TestGood2333 = {
aaaa: string;
xxxx: number;
wwww: number;
good: number;
};
4 changes: 3 additions & 1 deletion example/basic/src/utils/sum.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { abs } from './a/a';

export function sum(a: number, b: number) {
return a + b;
return a + b + abs(a, b);
}
4 changes: 1 addition & 3 deletions example/basic/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/// <reference types="jest" />

import { sum } from '../src/utils/sum';

describe('sum', () => {
it('works', async () => {
expect(sum(1, 1)).toEqual(2);
expect(sum(1, 1)).toEqual(4);
});
});
9 changes: 7 additions & 2 deletions example/basic/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
"target": "ES2017",
"noImplicitAny": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"strict": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"skipLibCheck": true,
"outDir": "lib",
"types": ["jest", "node"],
"baseUrl": "."
},
"include": ["src/**/*"]
"include": ["src/**/*"],
"exclude": ["lib", "esm"]
}
3 changes: 3 additions & 0 deletions example/express-typeorm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
# Edit at https://www.gitignore.io/?templates=node

lib
esm
package-lock.json
__snapshots__
*.sqlite
*.env
*.environment

### Node ###
# Logs
Expand Down
16 changes: 7 additions & 9 deletions example/express-typeorm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
"scripts": {
"start": "npm run build && node lib/main.js",
"tsdev": "ts-node-dev --respawn --transpile-only src/main.ts",
"dev": "npm run build && nodemon --inspect lib/main.js",
"types": "tsbb types",
"types:watch": "tsbb types --watch",
"watch": "tsbb watch",
"build": "tsbb build",
"dev": "npm run build && nodemon --inspect esm/main.js",
"watch": "tsbb watch --entry ./src/main.ts --no-esm",
"build": "tsbb build --entry ./src/main.ts --no-esm",
"test": "tsbb test",
"coverage": "tsbb test --coverage"
},
Expand All @@ -33,9 +31,9 @@
"@types/express": "4.17.13",
"@types/express-session": "1.17.4",
"@types/http-errors": "1.8.1",
"@types/node": "16.4.2",
"@types/node": "16.6.2",
"nodemon": "2.0.12",
"ts-node": "10.1.0",
"ts-node": "10.2.1",
"ts-node-dev": "1.1.8",
"tsbb": "2.3.1"
},
Expand All @@ -49,8 +47,8 @@
"http-errors": "1.8.0",
"pg": "8.7.1",
"reflect-metadata": "0.1.13",
"typeorm": "0.2.35",
"typeorm-extension": "0.2.7",
"typeorm": "0.2.37",
"typeorm-extension": "0.2.9",
"typeorm-store": "2.0.0"
}
}
11 changes: 5 additions & 6 deletions example/express-typeorm/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import 'reflect-metadata';
import dotenv from 'dotenv';
import crypto from 'crypto';
import { createDatabase } from 'typeorm-extension';
import { createConnection, ConnectionOptions, getRepository } from 'typeorm';
import { createConnection, getRepository } from 'typeorm';
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';
import { expressApp } from './app';
import { User } from './entity/User';
import { getEntity } from './utils/entity';
Expand All @@ -12,7 +13,8 @@ const env = dotenv.config();
async function run() {
try {
const entities = await getEntity();
const options: ConnectionOptions = {
if (!env.parsed) env.parsed = {};
const options: PostgresConnectionOptions = {
type: 'postgres',
host: env.parsed.DB_HOST || 'localhost',
port: env.parsed.DB_PORT ? Number(env.parsed.DB_PORT) : 5432,
Expand All @@ -21,10 +23,7 @@ async function run() {
database: env.parsed.DB_NAME || 'smg',
synchronize: true,
logging: false,
entities: [
// 'src/entity/*.ts'
...entities,
],
entities: [...entities],
};
await createDatabase({ ifNotExist: true }, options);
const connection = await createConnection(options);
Expand Down
4 changes: 2 additions & 2 deletions example/express-typeorm/src/utils/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import fs from 'fs';

export async function getEntity(entityPath: string = '../entity') {
const dirPath = path.resolve(__dirname, entityPath);
const dirArr = await fs.promises.readdir(dirPath);
const arr: any[] = [];
const dirArr = (await fs.promises.readdir(dirPath)).filter((fileName) => !/\.js\.map$/.test(fileName));
const arr: string[] = [];
dirArr.forEach((fileName) => {
const ePath = path.resolve(dirPath, fileName).replace(/\.(js|ts)$/, '');
const handle = require(ePath);
Expand Down
3 changes: 1 addition & 2 deletions example/express-typeorm/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
"target": "ES2017",
"noImplicitAny": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"strict": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"outDir": "lib",
"baseUrl": ".",
"typeRoots": ["src/types/*", "node_modules/@types/*"]
"types": ["jest", "node"]
},
"include": ["src/**/*"]
}
1 change: 1 addition & 0 deletions example/express/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Edit at https://www.gitignore.io/?templates=node

lib
esm
package-lock.json
__snapshots__

Expand Down
6 changes: 2 additions & 4 deletions example/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
"start": "npm run build && node lib/app.js",
"tsnd": "ts-node-dev --inspect -- src/app.ts",
"dev": "npm run build && nodemon --inspect lib/app.js",
"types": "tsbb types",
"types:watch": "tsbb types --watch",
"watch": "tsbb watch --timer 200",
"build": "tsbb build",
"watch": "tsbb watch --entry ./src/app.ts --no-esm",
"build": "tsbb build --entry ./src/app.ts --no-esm",
"test": "tsbb test",
"coverage": "tsbb test --coverage"
},
Expand Down
2 changes: 1 addition & 1 deletion example/express/src/routes/home/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express, { Response, Request, NextFunction } from 'express';
import { IRoute, Router } from 'express-serve-static-core';
import { Router } from 'express-serve-static-core';

let router: Router = express.Router();

Expand Down
Loading

1 comment on commit c0023b6

@jaywcjlove
Copy link
Owner Author

Choose a reason for hiding this comment

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

Please sign in to comment.