Skip to content

Commit

Permalink
build: update scripts and config files
Browse files Browse the repository at this point in the history
  • Loading branch information
juliencrn committed Sep 19, 2022
1 parent 438a044 commit c24c270
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 133 deletions.
1 change: 0 additions & 1 deletion .node-version

This file was deleted.

40 changes: 0 additions & 40 deletions jest.config.base.ts

This file was deleted.

10 changes: 0 additions & 10 deletions jest.config.node.ts

This file was deleted.

35 changes: 33 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
import type { Config } from '@jest/types'
import glob from 'glob'

import base from './jest.config.base'
const packages = glob.sync(`./src`).map(p => p.replace(/^\./, `<rootDir>`))

const ignoreDirs = [
'build/',
'dist/',
'node_modules/',
`\\.cache`,
'scripts/',
'public/',
'generators/',
'generated/',
'site/',
]

const config: Config.InitialOptions = {
...base,
testEnvironment: 'jsdom',
roots: packages,
transform: {
'^.+\\.[jt]sx?$': `<rootDir>/jest-preprocess.js`,
},
moduleNameMapper: {
'.+\\.(css|styl|less|sass|scss)$': `identity-obj-proxy`,
'.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': `<rootDir>/__mocks__/file-mock.js`,
},
testPathIgnorePatterns: ignoreDirs,
transformIgnorePatterns: [`node_modules/(?!(gatsby)/)`],
coveragePathIgnorePatterns: ignoreDirs,
coverageDirectory: '<rootDir>/coverage/',
globals: {
__PATH_PREFIX__: ``,
},
testURL: `http://localhost`,
setupFiles: [`<rootDir>/loadershim.js`],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.([tj]sx?)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
}

export default config
51 changes: 19 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,24 @@
"./site"
],
"scripts": {
"prebuild": "npm run clean",
"start": "chokidar \"src/**/*.ts\" -c \"npm run build\"",
"start": "echo 'TODO: chokidar \"src/**/*.ts\" -c \"npm run build\" || npm run test:watch'",
"prebuild": "npm run clean && npm run types-check",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc -p tsconfig.build.json --module commonjs --outDir dist/cjs",
"build:esm": "tsc -p tsconfig.build.json --module esNext --outDir dist/esm",
"postbuild": "npm run copy:hooks && npm run update:readme",
"build:cjs": "tsc --module commonjs --outDir dist/cjs",
"build:esm": "tsc --module esNext --outDir dist/esm",
"test": "jest",
"test:watch": "npm run test -- --watch --silent",
"test:coverage": "ts-node ./scripts/coverage.ts",
"clean": "rimraf -rf ./dist",
"types-check": "tsc -p tsconfig.json",
"legacy-clean": "lerna run clean && lerna clean -y",
"legacy-bootstrap": "npm ci && lerna exec npm ci && npm run copy:hooks && npm run build:lib",
"legacy-types-check": "lerna run types-check",
"legacy-lint": "npm-run-all --continue-on-error -p lint:*",
"legacy-lint:code": "eslint '**/*.{js,jsx,ts,tsx}'",
"legacy-lint:other": "prettier --check \"**/*.{json,md,mdx,css,scss,yaml,yml}\"",
"legacy-format": "run-p format:*",
"legacy-format:code": "npm run lint:code -- --fix",
"legacy-format:other": "npm run lint:other -- --write",
"legacy-pretest": "npm run types-check && npm run format",
"legacy-test": "jest",
"legacy-test:ssr": "jest --config ./jest.config.node.ts",
"legacy-test:watch": "npm run test -- --watch --silent",
"legacy-test:coverage": "ts-node ./scripts/coverage.ts",
"legacy-prebuilt": "npm run format && npm run copy:hooks",
"legacy-build": "lerna run build --stream",
"legacy-build:site": "lerna run --scope site build",
"legacy-build:lib": "lerna run --scope usehooks-ts build && npm run copy:hooks",
"legacy-predeploy": "npm run build",
"legacy-deploy": "netlify deploy --dir=site/public --prod",
"legacy-dev:site": "npm run build:lib && cd site && npm run start",
"legacy-dev:lib": "npm run test:watch",
"legacy-serve:site": "cd site && npm run serve",
"legacy-publish": "npm run build:lib && npm run test && lerna publish --no-git-reset",
"legacy-update:readme": "ts-node ./scripts/updateReadme.ts",
"legacy-copy:hooks": "rimraf -rf ./site/generated && ts-node ./scripts/copyHooks.ts",
"legacy-plop": "plop && npm run update:readme && npm run format"
"format": "prettier --check \"**/*.{json,md,mdx,css,scss,yaml,yml}\"",
"lint": "eslint '**/*.{js,jsx,ts,tsx}'",
"types-check": "tsc --noEmit",
"publish": "echo 'TODO: Publish npm package on npm.com'",
"update:readme": "ts-node ./scripts/updateReadme.ts",
"copy:hooks": "rimraf -rf ./site/generated && ts-node ./scripts/copyHooks.ts",
"plop": "plop && npm run update:readme && npm run format",
"deploy-site": "echo 'TODO: deploy: netlify deploy --dir=site/public --prod'"
},
"devDependencies": {
"@testing-library/react": "^12.1.2",
Expand Down Expand Up @@ -93,6 +76,10 @@
"peerDependencies": {
"react": "^16.9.0 || ^17.0.0 || ^18.0.0"
},
"engines": {
"node": ">=16.15.0",
"npm": ">=8"
},
"repository": {
"type": "git",
"url": "https://github.com/juliencrn/usehooks-ts"
Expand Down
8 changes: 4 additions & 4 deletions plopfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ module.exports = function (plop) {
*/
{
type: 'add',
path: 'lib/src/{{camelCase name}}/index.ts',
path: 'src/{{camelCase name}}/index.ts',
templateFile: 'templates/plop/hooks/lib/index.ts.hbs',
},
{
type: 'add',
path: 'lib/src/{{camelCase name}}/{{camelCase name}}.ts',
path: 'src/{{camelCase name}}/{{camelCase name}}.ts',
templateFile: 'templates/plop/hooks/lib/hook.ts.hbs',
},
{
type: 'add',
path: 'lib/src/{{camelCase name}}/{{camelCase name}}.test.ts',
path: 'src/{{camelCase name}}/{{camelCase name}}.test.ts',
templateFile: 'templates/plop/hooks/lib/hook.test.ts.hbs',
},
{
type: 'append',
path: 'lib/src/index.ts',
path: 'src/index.ts',
templateFile: 'templates/plop/hooks/index.ts.hbs',
},

Expand Down
2 changes: 1 addition & 1 deletion scripts/copyHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path'

import { isHookFile, toQueryParams } from './utils'

const hooksDir = path.resolve('./lib/src')
const hooksDir = path.resolve('./src')
const demosDir = path.resolve('./site/src/hooks-doc')
const outputDir = path.resolve('./site/generated')
const sandboxTemplatePath = path.resolve('./templates/codesandbox')
Expand Down
2 changes: 1 addition & 1 deletion scripts/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path'

import { isHookFile } from './utils'

const hookDir = path.resolve('./lib/src')
const hookDir = path.resolve('./src')
const hooks = fs.readdirSync(hookDir).filter(isHookFile)
const testFileRegex = new RegExp(`\.test\.ts$`)
let hasTestCount = 0
Expand Down
3 changes: 1 addition & 2 deletions scripts/updateReadme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import { camelToKebabCase, isHookFile } from './utils'
const demos = fs.readdirSync(path.resolve(path.resolve('./site/src/hooks-doc')))

const hooks = fs
.readdirSync(path.resolve(path.resolve('./lib/src')))
.readdirSync(path.resolve(path.resolve('./src')))
.filter(isHookFile)
.map(name => formatHook(name, demos))

const markdown = createMarkdownList(hooks)

insertIn(markdown, path.resolve('./README.md'))
insertIn(markdown, path.resolve('./lib/README.md'))

////////////////////////////////////////////////////////////////////////
// 2. Utility functions
Expand Down
17 changes: 0 additions & 17 deletions tsconfig.base.json

This file was deleted.

15 changes: 0 additions & 15 deletions tsconfig.build.json

This file was deleted.

26 changes: 18 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
{
"extends": "./tsconfig.base.json",

"compilerOptions": {
"baseUrl": ".",
"paths": {
"lib": ["src"],
"site": ["site/src"]
},
"noEmit": true
"rootDir": "./src",
"target": "esnext",
"moduleResolution": "node",
// Needed for CommonJS modules
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"noEmitOnError": true,
"skipLibCheck": true,
"removeComments": true,
"esModuleInterop": true,
"jsx": "react",
"strict": true,
"isolatedModules": true,
"lib": ["ESNEXT", "DOM"]
},

"include": ["src/**/*"]
"include": ["./src/**/*"],
"exclude": ["node_modules", "dist", "./src/**/*.test.ts", "site", "scripts"]
}

0 comments on commit c24c270

Please sign in to comment.