Skip to content

Commit 547c19f

Browse files
authored
Setup monorepo structure (#167)
* prepare monorepo setup * hoist up lint-staged to root package.json * quick note * trigger formatting * split up deps * move scripts * update gitignore * update the build and all that stuff * update where to get the files * setup build process * update ci * add babelrc to repo * add build tasks to pipelines * setup website build * ready deploy * retry build
1 parent 59763e1 commit 547c19f

File tree

17 files changed

+2508
-1417
lines changed

17 files changed

+2508
-1417
lines changed

.circleci/config.yml

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@
22
aliases:
33
- &restore-cache
44
keys:
5-
- v3-dependencies-{{ .Branch }}-{{ checksum "yarn.lock" }}
5+
- v4-dependencies-{{ .Branch }}-{{ checksum "yarn.lock" }}
66
# Fallback in case checksum fails
7-
- v3-dependencies-{{ .Branch }}-
7+
- v4-dependencies-{{ .Branch }}-
8+
9+
- &install
10+
# --frozen-lockfile ensures the build will fail if the lockfile needs to be updated
11+
run: yarn --no-progress --frozen-lockfile
12+
13+
- &build
14+
run:
15+
command: yarn build
16+
working_directory: packages/scroll-into-view-if-needed
817

918
- &save-cache
1019
paths:
1120
- node_modules
12-
key: v2-dependencies-{{ .Branch }}-{{ checksum "yarn.lock" }}
21+
key: v4-dependencies-{{ .Branch }}-{{ checksum "yarn.lock" }}
1322

1423
- &cypress-dependencies-install
1524
run:
@@ -18,6 +27,28 @@ aliases:
1827

1928
version: 2
2029
jobs:
30+
Typecheck:
31+
docker:
32+
- image: circleci/node:8
33+
steps:
34+
- checkout
35+
- restore-cache: *restore-cache
36+
- *install
37+
- run:
38+
command: yarn typecheck
39+
working_directory: packages/scroll-into-view-if-needed
40+
- save-cache: *save-cache
41+
42+
Build:
43+
docker:
44+
- image: circleci/node:8
45+
steps:
46+
- checkout
47+
- restore-cache: *restore-cache
48+
- *install
49+
- *build
50+
- save-cache: *save-cache
51+
2152
Website:
2253
docker:
2354
- image: circleci/node:carbon-browsers
@@ -28,6 +59,8 @@ jobs:
2859
command: node --version && npm --version && npx --version && yarn --version
2960
- *cypress-dependencies-install
3061
- restore-cache: *restore-cache
62+
- *install
63+
- *build
3164
- run: echo TODO
3265
- save-cache: *save-cache
3366

@@ -37,7 +70,8 @@ jobs:
3770
steps:
3871
- checkout
3972
- restore-cache: *restore-cache
40-
- run: echo TODO build
73+
- *install
74+
- *build
4175
- save-cache: *save-cache
4276
- run: yarn semantic-release
4377

@@ -46,9 +80,13 @@ workflows:
4680
version: 2
4781
Build and Deploy:
4882
jobs:
83+
- Typecheck
84+
- Build
4985
- Website
5086
- Semantic Release:
5187
requires:
88+
- Typecheck
89+
- Build
5290
- Website
5391
filters:
5492
branches:

.prettierrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

package.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"private": true,
3+
"workspaces": [
4+
"packages/*",
5+
"website"
6+
],
7+
"scripts": {
8+
"precommit": "lint-staged",
9+
"predeploy:website": "cd packages/scroll-into-view-if-needed && yarn build",
10+
"deploy:website": "cd website && yarn deploy"
11+
},
12+
"devDependencies": {
13+
"husky": "0.14.3",
14+
"lint-staged": "7.0.4",
15+
"prettier": "1.12.1",
16+
"prettier-package-json": "1.5.1"
17+
},
18+
"lint-staged": {
19+
"*.js": [
20+
"prettier --write",
21+
"git add"
22+
],
23+
"*.{ts,tsx}": [
24+
"prettier --write",
25+
"git add"
26+
],
27+
"*.json": [
28+
"prettier --write",
29+
"git add"
30+
],
31+
"*.md": [
32+
"prettier --write",
33+
"git add"
34+
],
35+
"**/package.json": [
36+
"prettier-package-json --write",
37+
"git add"
38+
],
39+
"**/.babelrc": [
40+
"prettier --write",
41+
"git add"
42+
]
43+
},
44+
"prettier": {
45+
"semi": false,
46+
"singleQuote": true,
47+
"trailingComma": "es5",
48+
"overrides": [
49+
{
50+
"files": ".babelrc",
51+
"options": {
52+
"parser": "json"
53+
}
54+
}
55+
]
56+
},
57+
"resolutions": {
58+
"@types/react": "*"
59+
}
60+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const BABEL_ENV = process.env.BABEL_ENV
2+
const building = BABEL_ENV != undefined && BABEL_ENV !== 'cjs'
3+
4+
const plugins = []
5+
6+
if (process.env.NODE_ENV === 'production') {
7+
plugins.push('dev-expression')
8+
}
9+
10+
module.exports = {
11+
presets: [
12+
'@babel/preset-typescript',
13+
[
14+
'@babel/preset-env',
15+
{
16+
loose: true,
17+
modules: building ? false : 'commonjs',
18+
},
19+
],
20+
],
21+
plugins: plugins,
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dist
2+
es
3+
typings
4+
umd
5+
/*.js
6+
!.babelrc.js

packages/scroll-into-view-if-needed/package.json

Lines changed: 40 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -8,70 +8,56 @@
88
"type": "git",
99
"url": "git+https://github.com/stipsan/scroll-into-view-if-needed.git"
1010
},
11-
"version": "0.0.0-dev",
12-
"main": "dist/bundle.js",
11+
"version": "2.0.0-dev",
12+
"main": "index.js",
13+
"files": [
14+
"auto.js",
15+
"compute.js",
16+
"es",
17+
"ponyfill.js",
18+
"umd"
19+
],
1320
"scripts": {
1421
"prebuild": "yarn clean",
15-
"build": "yarn build:tsc && yarn build:rollup",
16-
"build:example": "next build example",
17-
"build:rollup": "rollup -c",
18-
"build:tsc": "yarn tsc:main",
19-
"clean": "rimraf dist",
20-
"precommit": "lint-staged",
21-
"predev": "yarn build",
22-
"dev": "concurrently \"yarn tsc:main --watch\" \"yarn build:rollup -w\" \"next dev example\"",
23-
"docs": "next build example && DOCS=true next export -o ./docs example && npx -p https://gist.github.com/stipsan/bbf4adcdafd9eabfa6a9a42397a1c1b9 -c 'git-update-ghpages'",
22+
"build": "yarn build:cjs && yarn build:es && yarn build:umd && yarn build:umd.min",
23+
"build:cjs": "BABEL_ENV=cjs babel src -d . --extensions '.ts'",
24+
"build:es": "BABEL_ENV=es babel src -d es --extensions '.ts'",
25+
"build:umd": "BABEL_ENV=umd NODE_ENV=development rollup -c -f umd -o umd/scroll-into-view-if-needed.js",
26+
"build:umd.min": "BABEL_ENV=umd NODE_ENV=production rollup -c -f umd -o umd/scroll-into-view-if-needed.min.js",
27+
"clean": "rimraf 'umd' 'es'",
28+
"dev": "concurrently 'tsc --watch' 'yarn build:cjs --watch'",
2429
"prepublishOnly": "unset npm_config_cafile && yarn build",
2530
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
26-
"prestart": "yarn build",
27-
"start": "next start example",
28-
"test": "cypress run --browser chrome --reporter junit --reporter-options 'mochaFile=junit/test-results.xml'",
29-
"tsc:main": "tsc -p ."
31+
"typecheck": "tsc"
32+
},
33+
"dependencies": {
34+
"invariant": "2.2.4",
35+
"warning": "3.0.0"
3036
},
3137
"devDependencies": {
32-
"@cypress/browserify-preprocessor": "1.0.2",
33-
"@types/next": "2.4.9",
34-
"@types/node": "9.6.6",
35-
"@types/prettier": "1.12.0",
36-
"@types/react": "16.3.11",
37-
"@types/react-dom": "16.0.5",
38-
"@zeit/next-typescript": "0.1.1",
39-
"babel-cli": "^6.23.0",
38+
"@babel/cli": "7.0.0-beta.44",
39+
"@babel/core": "7.0.0-beta.44",
40+
"@babel/plugin-external-helpers": "7.0.0-beta.44",
41+
"@babel/preset-env": "7.0.0-beta.44",
42+
"@babel/preset-typescript": "7.0.0-beta.44",
4043
"babel-plugin-add-module-exports": "^0.2.1",
44+
"babel-plugin-dev-expression": "0.2.1",
4145
"babel-plugin-styled-components": "1.5.1",
42-
"babel-preset-env": "^1.2.1",
43-
"babel-preset-es2015-rollup": "^3.0.0",
44-
"browserify": "16.2.0",
45-
"bulma": "0.7.0",
46-
"codemirror": "5.36.0",
4746
"concurrently": "^3.5.0",
48-
"cypress": "2.1.0",
49-
"husky": "^0.14.3",
50-
"lint-staged": "^4.3.0",
51-
"next": "5.1.0",
52-
"prettier": "1.12.0",
53-
"prettier-browser": "git://github.com/prettier/prettier.git#1.8.2",
54-
"prettier-package-json": "1.5.1",
55-
"react": "16.3.1",
56-
"react-codemirror2": "4.2.1",
57-
"react-dom": "16.3.1",
58-
"react-syntax-highlighter": "7.0.2",
59-
"release-relief": "^1.0.1",
47+
"release-relief": "1.0.1",
6048
"rimraf": "^2.6.1",
61-
"rollup": "^0.50.0",
62-
"rollup-plugin-babel": "^2.7.1",
63-
"rollup-plugin-commonjs": "^8.0.2",
64-
"rollup-plugin-node-resolve": "^2.0.0",
65-
"scroll-into-view-if-needed": "link:.",
66-
"styled-components": "3.2.6",
67-
"system-font-stack": "1.0.5",
68-
"tsify": "4.0.0",
69-
"typescript": "2.8.3",
70-
"uglifyjs-webpack-plugin": "^1.0.1"
49+
"rollup": "0.58.1",
50+
"rollup-plugin-babel": "4.0.0-beta.4",
51+
"rollup-plugin-commonjs": "9.1.0",
52+
"rollup-plugin-node-resolve": "3.3.0",
53+
"rollup-plugin-replace": "2.0.0",
54+
"rollup-plugin-uglify": "3.0.0",
55+
"typescript": "2.8.3"
7156
},
7257
"keywords": [
7358
"behavior-smooth",
7459
"if-needed",
60+
"polyfill",
7561
"ponyfill",
7662
"scroll",
7763
"scroll-into-view",
@@ -82,38 +68,18 @@
8268
"smoothscroll",
8369
"typescript"
8470
],
85-
"lint-staged": {
86-
"*.js": [
87-
"prettier --write",
88-
"git add"
89-
],
90-
"*.{ts,tsx}": [
91-
"prettier --write",
92-
"git add"
93-
],
94-
"*.json": [
95-
"prettier --write",
96-
"git add"
97-
],
98-
"*.md": [
99-
"prettier --write",
100-
"git add"
101-
],
102-
"package.json": [
103-
"prettier-package-json --write",
104-
"git add"
71+
"browserify": {
72+
"transform": [
73+
"loose-envify"
10574
]
10675
},
107-
"module": "index.js",
76+
"module": "es/index.js",
10877
"release": {
10978
"analyzeCommits": "semantic-release-tamia/analyzeCommits",
11079
"verifyConditions": "condition-circle",
11180
"generateNotes": "semantic-release-tamia/generateNotes",
11281
"verifyRelease": "semantic-release-tamia/verifyRelease"
11382
},
114-
"resolutions": {
115-
"@types/react": "16.3.11"
116-
},
11783
"sideEffects": false,
11884
"typings": "typings/index.d.ts"
11985
}
Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
1+
import babel from 'rollup-plugin-babel'
2+
import uglify from 'rollup-plugin-uglify'
3+
import replace from 'rollup-plugin-replace'
14
import commonjs from 'rollup-plugin-commonjs'
2-
import nodeResolve from 'rollup-plugin-node-resolve'
3-
const globals = {}
5+
import resolve from 'rollup-plugin-node-resolve'
46

5-
const onwarn = message => {
6-
const suppressed = ['UNRESOLVED_IMPORT', 'THIS_IS_UNDEFINED']
7-
8-
if (!suppressed.find(code => message.code === code)) {
9-
return console.warn(message.message)
10-
}
11-
}
12-
13-
export default {
14-
entry: 'index.js',
15-
dest: 'dist/bundle.js',
16-
format: 'umd',
17-
moduleName: 'scrollIntoViewIfNeeded',
18-
exports: 'default',
19-
globals,
20-
onwarn,
7+
const config = {
8+
input: 'src/index.ts',
9+
name: 'scrollIntoView',
2110
plugins: [
22-
nodeResolve({
23-
jsnext: true,
24-
main: true,
11+
babel({
12+
exclude: 'node_modules/**',
13+
}),
14+
resolve({
15+
extensions: ['.ts', '.js', '.json'],
2516
}),
26-
2717
commonjs({
28-
// non-CommonJS modules will be ignored, but you can also
29-
// specifically include/exclude files
30-
include: 'node_modules/**', // Default: undefined
31-
32-
// if false then skip sourceMap generation for CommonJS modules
33-
sourceMap: false, // Default: true
18+
include: /node_modules/,
19+
}),
20+
replace({
21+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
3422
}),
3523
],
3624
}
25+
26+
if (process.env.NODE_ENV === 'production') {
27+
config.plugins.push(uglify())
28+
}
29+
30+
export default config

0 commit comments

Comments
 (0)