Skip to content

Commit a074f32

Browse files
committed
chore: setup Lerna + Yarn Workspaces + TypeScript Project References
1 parent 128bb42 commit a074f32

22 files changed

+8145
-1
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages/*/lib/

.eslintrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
extends: 'smarthr',
3+
settings: {
4+
react: {
5+
version: 'latest',
6+
},
7+
},
8+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
packages/*/lib/
2+
node_modules/
3+
tsconfig.tsbuildinfo

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"semi": false,
5+
"printWidth": 100
6+
}

CONTRIBUTING.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Contributing Guide
2+
3+
## For Contributors
4+
5+
Thank you for your contribution!
6+
7+
### Setup
8+
9+
This repository is a monorepo using Lerna and Yarn Workspaces.
10+
11+
```sh
12+
% cd tamatebako
13+
% yarn install
14+
```
15+
16+
### Develop
17+
18+
```sh
19+
% yarn start
20+
```
21+
22+
### Test
23+
24+
```sh
25+
% cd tamatebako
26+
% yarn test
27+
% yarn lint
28+
```
29+
30+
## For Maintainers
31+
32+
### Merge
33+
34+
After you have approved a PR, please merge the PR using Squash and merge with Conventional Commits format.
35+
36+
### Release
37+
38+
```sh
39+
% cd tamatebako
40+
% yarn release
41+
```
42+
43+
If you'd like to release a new package.
44+
45+
```sh
46+
% cd tamatebako
47+
% yarn initial:release
48+
```

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
# tamatebako
1+
# tamatebako
2+
3+
Frontend packages for projects at SmartHR
4+
5+
### Package Index
6+
7+
| Package | Version | Description |
8+
| ------- | ------- | ----------- |
9+
| TBD | TBD | TBD |

jest.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testRegex: '.*\\.test\\.tsx?$',
4+
}

lerna.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"npmClient": "yarn",
3+
"useWorkspaces": true,
4+
"version": "independent"
5+
}

package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "tamatebako",
3+
"version": "1.0.0",
4+
"private": true,
5+
"description": "Frontend packages for projects at SmartHR",
6+
"workspaces": [
7+
"packages/*"
8+
],
9+
"main": "index.js",
10+
"scripts": {
11+
"build": "yarn tsc",
12+
"prebuild": "lerna run clean --stream",
13+
"lint": "eslint '**/*.{ts,tsx}'",
14+
"release": "lerna publish --conventional-commits",
15+
"prerelease": "yarn build && yarn lint && yarn test",
16+
"initial:release": "lerna publish from-package",
17+
"preinitial:release": "yarn prerelease",
18+
"start": "yarn build --watch",
19+
"tsc": "tsc --build packages --force",
20+
"test": "jest"
21+
},
22+
"author": "SmartHR",
23+
"license": "MIT",
24+
"devDependencies": {
25+
"@types/jest": "^26.0.3",
26+
"eslint": "^7.2.0",
27+
"eslint-config-smarthr": "^4.0.0",
28+
"jest": "^26.1.0",
29+
"lerna": "^3.22.1",
30+
"prettier": "^2.0.5",
31+
"rimraf": "^3.0.2",
32+
"ts-jest": "^26.1.1",
33+
"typescript": "^3.9.5"
34+
}
35+
}

packages/package-a/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# `@smarthr/package-a`
2+
3+
## Usage
4+
5+
```
6+
const { fnA } = require('@smarthr/package-a');
7+
fnA();
8+
```

packages/package-a/package.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "@smarthr/package-a",
3+
"version": "1.0.0",
4+
"description": "A test library",
5+
"author": "SmartHR",
6+
"homepage": "",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/kufu/tamatebako.git",
10+
"directory": "packages/pacakge-a"
11+
},
12+
"bugs": {
13+
"url": "https://github.com/kufu/tamatebako/issues"
14+
},
15+
"license": "MIT",
16+
"main": "lib/index.js",
17+
"types": "lib/index.d.ts",
18+
"files": [
19+
"lib"
20+
],
21+
"publishConfig": {
22+
"access": "public"
23+
},
24+
"scripts": {
25+
"build": "tsc",
26+
"prebuild": "yarn clean",
27+
"clean": "rimraf lib"
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { fnA, fnAB } from '../index'
2+
3+
describe('package-a', () => {
4+
describe('fnA', () => {
5+
it('should return A', () => {
6+
expect(fnA()).toBe('A')
7+
})
8+
})
9+
describe('fnAB', () => {
10+
it('should return AB', () => {
11+
expect(fnAB()).toBe('AB')
12+
})
13+
})
14+
})

packages/package-a/src/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { fnB } from '@smarthr/package-b'
2+
3+
export const fnA = () => 'A'
4+
export const fnAB = () => fnA() + fnB()

packages/package-a/tsconfig.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../tsconfig-base.json",
3+
"compilerOptions": {
4+
"outDir": "./lib",
5+
"rootDir": "./src"
6+
},
7+
"references": [
8+
{ "path": "../package-b" }
9+
]
10+
}

packages/package-b/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# `@smarthr/package-b`
2+
3+
## Usage
4+
5+
```
6+
const { fnB } = require('@smarthr/package-b');
7+
fnB();
8+
```

packages/package-b/package.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "@smarthr/package-b",
3+
"version": "1.0.0",
4+
"description": "A test library",
5+
"author": "SmartHR",
6+
"homepage": "",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/kufu/tamatebako.git",
10+
"directory": "packages/pacakge-b"
11+
},
12+
"bugs": {
13+
"url": "https://github.com/kufu/tamatebako/issues"
14+
},
15+
"license": "MIT",
16+
"main": "lib/index.js",
17+
"types": "lib/index.d.ts",
18+
"files": [
19+
"lib"
20+
],
21+
"publishConfig": {
22+
"access": "public"
23+
},
24+
"scripts": {
25+
"build": "tsc",
26+
"prebuild": "yarn clean",
27+
"clean": "rimraf lib"
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { fnB } from '../index'
2+
3+
describe('package-b', () => {
4+
it('should return B', () => {
5+
expect(fnB()).toBe('B')
6+
})
7+
})

packages/package-b/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const fnB = () => 'B'

packages/package-b/tsconfig.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../tsconfig-base.json",
3+
"compilerOptions": {
4+
"outDir": "./lib",
5+
"rootDir": "./src"
6+
}
7+
}

packages/tsconfig-base.json

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"compilerOptions": {
3+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
4+
5+
/* Basic Options */
6+
// "incremental": true, /* Enable incremental compilation */
7+
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9+
// "lib": [], /* Specify library files to be included in the compilation. */
10+
// "allowJs": true, /* Allow javascript files to be compiled. */
11+
// "checkJs": true, /* Report errors in .js files. */
12+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13+
"declaration": true, /* Generates corresponding '.d.ts' file. */
14+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15+
"sourceMap": true, /* Generates corresponding '.map' file. */
16+
// "outFile": "./", /* Concatenate and emit output to single file. */
17+
// "outDir": "./", /* Redirect output structure to the directory. */
18+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
19+
"composite": true, /* Enable project compilation */
20+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
21+
// "removeComments": true, /* Do not emit comments to output. */
22+
// "noEmit": true, /* Do not emit outputs. */
23+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
24+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
25+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
26+
27+
/* Strict Type-Checking Options */
28+
"strict": true, /* Enable all strict type-checking options. */
29+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
30+
// "strictNullChecks": true, /* Enable strict null checks. */
31+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
32+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
33+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
34+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
35+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
36+
37+
/* Additional Checks */
38+
// "noUnusedLocals": true, /* Report errors on unused locals. */
39+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
40+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
41+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
42+
43+
/* Module Resolution Options */
44+
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
45+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
46+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
47+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
48+
// "typeRoots": [], /* List of folders to include type definitions from. */
49+
// "types": [], /* Type declaration files to be included in compilation. */
50+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
51+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
52+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
53+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
54+
55+
/* Source Map Options */
56+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
57+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
58+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
59+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
60+
61+
/* Experimental Options */
62+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
63+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
64+
65+
/* Advanced Options */
66+
"skipLibCheck": true, /* Skip type checking of declaration files. */
67+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
68+
}
69+
}

packages/tsconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"files": [],
3+
"include": [],
4+
"references": [
5+
{ "path": "./package-a" },
6+
{ "path": "./package-b" }
7+
]
8+
}

0 commit comments

Comments
 (0)