Skip to content

Commit

Permalink
build: upgrade setup
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Dec 9, 2020
1 parent b124c91 commit 72a3500
Show file tree
Hide file tree
Showing 16 changed files with 3,129 additions and 3,449 deletions.
24 changes: 24 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-env node */

// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('./package.json');

module.exports = {
plugins: ['@typescript-eslint', 'prettier'],
extends: [
'react-app',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'prettier/@typescript-eslint',
],
settings: {
react: {
version: pkg.devDependencies.react ? 'detect' : '99.99.99',
},
},
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
};
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2.1.2
with:
node-version: '12.x'
- run: npm i -g yarn
Expand All @@ -26,3 +26,10 @@ jobs:
- run: yarn lint
- run: yarn test:coverage
- run: yarn docs
# - name: Deploy
# if: github.ref == 'refs/heads/master' && github.event_name == 'push'
# uses: peaceiris/actions-gh-pages@v3
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_dir: ./docs
# enable_jekyll: false
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ npm-debug.log*
/.pnp.js

# Build files
/dist
/.tmp
/build

*.tgz
/.vscode/extensions.json
/docs
/docs
samples/*.map
samples/*.js
15 changes: 14 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
/.pnp.js
/.yarnrc.yml
/.yarnrc.yml
/.yarn
/build
/docs
/coverage
/.gitattributes
/.gitignore
/.prettierignore
/LICENSE
/yarn.lock
/.vscode
*.map
samples/*.js
src/**/*.js
6 changes: 3 additions & 3 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"hooks": {
"before:init": "yarn test",
"before:release": "yarn run build & yarn pack",
"before:init": "yarn clean && yarn test",
"before:release": "yarn build && yarn pack",
"after:release": "echo Successfully released ${name} v${version} to ${repo.repository}."
},
"git": {
Expand All @@ -12,6 +12,6 @@
},
"github": {
"release": true,
"assets": ["dist/*.js", "dist/*.d.ts", "*.tgz"]
"assets": ["build/*.js", "build/*.d.ts", "*.tgz"]
}
}
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"eslint.enable": true,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"[javascript]": {
Expand All @@ -7,6 +8,9 @@
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
Expand All @@ -19,5 +23,6 @@
"editor.detectIndentation": false,
"editor.tabSize": 2,
"typescript.tsdk": ".yarn/sdks/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
"typescript.enablePromptUseWorkspaceTsdk": true,
"npm.packageManager": "yarn"
}
8 changes: 1 addition & 7 deletions .yarnrc_patch.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
packageExtensions:
'tsdx@*':
dependencies:
'babel-jest': '^25.5.1'
'eslint-config-react-app@*':
dependencies:
'babel-eslint': '*'
# packageExtensions:
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-env node */

module.exports = {
preset: 'ts-jest',
testRegex: '((\\.|/)(test|spec))\\.[jt]sx?$',
};
113 changes: 60 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,76 +20,83 @@
"type": "git",
"url": "https://github.com/upsetjs/cytoscape.js-bubblesets.git"
},
"module": "dist/cytoscapebubblesets.esm.js",
"main": "dist/cytoscapebubblesets.umd.development.js",
"unpkg": "dist/cytoscapebubblesets.umd.production.min.js",
"jsdelivr": "dist/cytoscapebubblesets.umd.production.min.js",
"types": "dist/index.d.ts",
"sideEffects": false,
"files": [
"dist",
"src/**/*.ts"
],
"browserslist": [
"Firefox ESR",
"last 2 Chrome versions",
"last 2 Firefox versions"
],
"global": "CytoscapeBubbleSets",
"dependencies": {
"@types/cytoscape": "^3.14.7",
"cytoscape-layers": "^2.0.0"
"cytoscape-layers": "^2.1.0"
},
"peerDependencies": {
"cytoscape": "^3.15.2"
"cytoscape": "^3.17.0"
},
"browserslist": [
"Firefox ESR",
"last 2 Chrome versions",
"last 2 Firefox versions"
],
"module": "build/index.esm.js",
"main": "build/index.js",
"browser": "build/index.umd.js",
"unpkg": "build/index.umd.min.js",
"jsdelivr": "build/index.umd.min.js",
"types": "build/index.d.ts",
"sideEffects": false,
"files": [
"build",
"src/**/*.ts"
],
"devDependencies": {
"@rollup/plugin-commonjs": "^14.0.0",
"@types/cytoscape": "^3.14.7",
"@types/jest": "^26.0.4",
"@babel/core": "^7.12.9",
"@babel/preset-env": "^7.12.7",
"@rollup/plugin-babel": "^5.2.2",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"@rollup/plugin-replace": "^2.3.4",
"@rollup/plugin-typescript": "^8.0.0",
"@types/d3-array": "^2.8.0",
"@types/jest": "^26.0.18",
"@types/lodash.throttle": "^4.1.6",
"@typescript-eslint/eslint-plugin": "^3.6.1",
"@typescript-eslint/parser": "^3.6.1",
"@yarnpkg/pnpify": "^2.1.0",
"@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.9.1",
"@yarnpkg/pnpify": "^2.4.0",
"bubblesets-js": "^2.2.0",
"cytoscape": "^3.15.0",
"eslint": "^7.4.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-react-app": "^5.2.1",
"cytoscape": "^3.17.0",
"cytoscape-layers": "^2.1.0",
"eslint": "^7.15.0",
"eslint-config-prettier": "^7.0.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.2.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^4.0.8",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.2.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"jest": "^26.6.3",
"lodash.throttle": "^4.1.1",
"prettier": "^2.0.5",
"release-it": "^13.6.5",
"prettier": "^2.2.1",
"release-it": "^14.2.2",
"rimraf": "^3.0.2",
"rollup": "^2.21.0",
"rollup-plugin-cleanup": "^3.1.1",
"rollup-plugin-dts": "^1.4.8",
"rollup-plugin-pnp-resolve": "^2.0.0",
"tsdx": "~0.13.2",
"tslib": "^2.0.0",
"typedoc": "^0.17.8",
"typescript": "^3.9.6"
"rollup": "^2.34.2",
"rollup-plugin-dts": "^2.0.0",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^26.4.4",
"tslib": "^2.0.3",
"typedoc": "^0.19.2",
"typescript": "^4.1.2"
},
"scripts": {
"clean": "rimraf dist node_modules",
"clean": "rimraf build node_modules \"*.tgz\" \"samples/*.js\" \"samples/*.map\"",
"compile": "tsc -p tsconfig.json --noEmit",
"start": "npm run watch",
"watch": "tsdx watch --noClean --name CytoscapeBubbleSets --format esm,umd",
"build": "npm run clean && tsdx build --name CytoscapeBubbleSets --format esm,umd && npm run typings",
"typings": "rollup -c rollup.dts.config.js",
"test": "tsdx test --passWithNoTests",
"test:watch": "tsdx test --passWithNoTests --watch",
"test:coverage": "tsdx test --passWithNoTests --coverage",
"watch": "rollup -c -w",
"build": "rollup -c",
"test": "jest --passWithNoTests",
"test:watch": "jest --passWithNoTests --watch",
"test:coverage": "jest --passWithNoTests --coverage",
"lint": "npm run eslint && npm run prettier",
"fix": "npm run eslint:fix && npm run prettier:write",
"prettier:impl": "prettier \"*.{md,json,js,yml}\" \"{.github,src,samples}/**\"",
"prettier:write": "npm run prettier:impl -- --write",
"prettier": "npm run prettier:impl -- --check",
"eslint": "tsdx lint src --ext .ts,.tsx",
"prettier:write": "prettier */** --write",
"prettier": "prettier */** --check",
"eslint": "eslint src --ext .ts,.tsx",
"eslint:fix": "npm run eslint -- --fix",
"docs": "typedoc",
"prepare": "npm run build",
Expand Down
109 changes: 109 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import dts from 'rollup-plugin-dts';
import typescript from '@rollup/plugin-typescript';
import { terser } from 'rollup-plugin-terser';
import replace from '@rollup/plugin-replace';
import babel from '@rollup/plugin-babel';

import fs from 'fs';

const pkg = JSON.parse(fs.readFileSync('./package.json'));

const banner = `/**
* ${pkg.name}
* ${pkg.homepage}
*
* Copyright (c) ${new Date().getFullYear()} ${pkg.author.name} <${pkg.author.email}>
*/
`;

/**
* defines which formats (umd, esm, cjs, types) should be built when watching
*/
const watchOnly = ['umd'];

const isDependency = (v) => Object.keys(pkg.dependencies || {}).some((e) => e === v || v.startsWith(e + '/'));
const isPeerDependency = (v) => Object.keys(pkg.peerDependencies || {}).some((e) => e === v || v.startsWith(e + '/'));

export default function Config(options) {
const buildFormat = (format) => !options.watch || watchOnly.includes(format);

const base = {
input: './src/index.ts',
output: {
sourcemap: true,
banner,
exports: 'named',
globals: {
cytoscape: 'cytoscape',
'cytoscape-layers': 'CytoscapeLayers',
crypto: 'NodeCrypto',
},
},
external: (v) => isDependency(v) || isPeerDependency(v),
plugins: [
typescript(),
resolve(),
commonjs(),
replace({
// eslint-disable-next-line no-undef
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) || 'production',
__VERSION__: JSON.stringify(pkg.version),
}),
],
};
return [
(buildFormat('esm') || buildFormat('cjs')) && {
...base,
output: [
buildFormat('esm') && {
...base.output,
file: pkg.module,
format: 'esm',
},
buildFormat('cjs') && {
...base.output,
file: pkg.main,
format: 'cjs',
},
].filter(Boolean),
},
((buildFormat('umd') && pkg.browser) || (buildFormat('umd-min') && pkg.unpkg)) && {
...base,
input: fs.existsSync(base.input.replace('.ts', '.umd.ts')) ? base.input.replace('.ts', '.umd.ts') : base.input,
output: [
buildFormat('umd') &&
pkg.browser && {
...base.output,
file: pkg.browser,
format: 'umd',
name: pkg.global,
},
buildFormat('umd-min') &&
pkg.unpkg && {
...base.output,
file: pkg.unpkg,
format: 'umd',
name: pkg.global,
plugins: [terser()],
},
].filter(Boolean),
external: (v) => isPeerDependency(v),
plugins: [...base.plugins, babel({ presets: ['@babel/env'], babelHelpers: 'bundled' })],
},
buildFormat('types') && {
...base,
output: {
...base.output,
file: pkg.types,
format: 'es',
},
plugins: [
dts({
respectExternal: true,
}),
],
},
].filter(Boolean);
}
Loading

0 comments on commit 72a3500

Please sign in to comment.