From 20847502b9ad89a8d5a51deaf6f513bf813c31bb Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Sun, 19 Jul 2020 17:37:35 -0400 Subject: [PATCH 01/13] Add monorepo template --- templates/monorepo/.gitignore | 25 +++++++++++++ templates/monorepo/LICENSE | 21 +++++++++++ templates/monorepo/README.md | 30 ++++++++++++++++ templates/monorepo/lerna.json | 10 ++++++ templates/monorepo/package.json | 29 +++++++++++++++ .../monorepo/packages/example/.gitignore | 3 ++ .../monorepo/packages/example/index.html | 14 ++++++++ templates/monorepo/packages/example/index.tsx | 14 ++++++++ .../monorepo/packages/example/package.json | 25 +++++++++++++ .../monorepo/packages/example/tsconfig.json | 18 ++++++++++ templates/monorepo/packages/react/README.md | 5 +++ .../monorepo/packages/react/example/index.tsx | 14 ++++++++ .../monorepo/packages/react/package.json | 36 +++++++++++++++++++ .../monorepo/packages/react/src/index.tsx | 10 ++++++ .../packages/react/test/react.test.tsx | 5 +++ .../packages/react/tsconfig.build.json | 7 ++++ templates/monorepo/packages/utils/README.md | 7 ++++ .../monorepo/packages/utils/package.json | 26 ++++++++++++++ .../monorepo/packages/utils/src/index.ts | 19 ++++++++++ .../packages/utils/test/utils.test.tsx | 5 +++ .../packages/utils/tsconfig.build.json | 7 ++++ templates/monorepo/tsconfig.build.json | 29 +++++++++++++++ templates/monorepo/tsconfig.json | 14 ++++++++ templates/monorepo/types/global.d.ts | 6 ++++ 24 files changed, 379 insertions(+) create mode 100644 templates/monorepo/.gitignore create mode 100644 templates/monorepo/LICENSE create mode 100644 templates/monorepo/README.md create mode 100644 templates/monorepo/lerna.json create mode 100644 templates/monorepo/package.json create mode 100644 templates/monorepo/packages/example/.gitignore create mode 100644 templates/monorepo/packages/example/index.html create mode 100644 templates/monorepo/packages/example/index.tsx create mode 100644 templates/monorepo/packages/example/package.json create mode 100644 templates/monorepo/packages/example/tsconfig.json create mode 100644 templates/monorepo/packages/react/README.md create mode 100644 templates/monorepo/packages/react/example/index.tsx create mode 100644 templates/monorepo/packages/react/package.json create mode 100644 templates/monorepo/packages/react/src/index.tsx create mode 100644 templates/monorepo/packages/react/test/react.test.tsx create mode 100644 templates/monorepo/packages/react/tsconfig.build.json create mode 100644 templates/monorepo/packages/utils/README.md create mode 100644 templates/monorepo/packages/utils/package.json create mode 100644 templates/monorepo/packages/utils/src/index.ts create mode 100644 templates/monorepo/packages/utils/test/utils.test.tsx create mode 100644 templates/monorepo/packages/utils/tsconfig.build.json create mode 100644 templates/monorepo/tsconfig.build.json create mode 100644 templates/monorepo/tsconfig.json create mode 100644 templates/monorepo/types/global.d.ts diff --git a/templates/monorepo/.gitignore b/templates/monorepo/.gitignore new file mode 100644 index 000000000..4a12e1903 --- /dev/null +++ b/templates/monorepo/.gitignore @@ -0,0 +1,25 @@ +dist +compiled +*.log +coverage +.DS_Store +next.d.ts +legacy.d.ts +.idea +*.orig + +node_modules +package-lock.json +yarn.lock +!/yarn.lock + +website/translated_docs +website/build +website/yarn.lock +website/node_modules +website/i18n +!website/yarn.lock + +.vercel +.yalc +yalc.lock \ No newline at end of file diff --git a/templates/monorepo/LICENSE b/templates/monorepo/LICENSE new file mode 100644 index 000000000..ac4f03896 --- /dev/null +++ b/templates/monorepo/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/templates/monorepo/README.md b/templates/monorepo/README.md new file mode 100644 index 000000000..dd10c4df5 --- /dev/null +++ b/templates/monorepo/README.md @@ -0,0 +1,30 @@ +# TSDX Monorepo User Guide + +## Usage + +This monorepo is setup for a dummy `@mono/` NPM organization. There are 2 packages by default: + +- `@mono/react` - A placholder React component +- `@mono/utils` - A utils packages + +Unlike other TSDX templates, the developer experience for this template is currently a bit more manual. + +Your first order of business will be to search and replace `@mono` for the npm organization of your own. + +After that you can install all the dependencies in the root directory + +```sh +npm install # or yarn install +``` + +This will install all dependencies in each project, build them, and symlink them via Lerna + +## Development workflow + +```sh +npm start # or yarn start +``` + +This builds each package to `//dist` and runs the project in watch mode so any edits you save inside `//src` causes a rebuild to `//dist`. + +In addition, this will start the example/playground on `localhost:1234` diff --git a/templates/monorepo/lerna.json b/templates/monorepo/lerna.json new file mode 100644 index 000000000..cc8c8c46a --- /dev/null +++ b/templates/monorepo/lerna.json @@ -0,0 +1,10 @@ +{ + "version": "0.0.0", + "registry": "https://registry.npmjs.org/", + "publishConfig": { + "access": "public" + }, + "npmClient": "yarn", + "useWorkspaces": true, + "packages": ["packages/*"] +} diff --git a/templates/monorepo/package.json b/templates/monorepo/package.json new file mode 100644 index 000000000..d72de6405 --- /dev/null +++ b/templates/monorepo/package.json @@ -0,0 +1,29 @@ +{ + "name": "mono", + "private": true, + "devDependencies": { + "@types/react": "^16.9.43", + "@types/react-dom": "^16.9.8", + "lerna": "^3.15.0", + "tsdx": "^0.13.2", + "typescript": "^3.9.7" + }, + "workspaces": [ + "packages/*" + ], + "scripts": { + "lerna": "lerna", + "dev": "lerna run start --stream --parallel", + "test": "lerna run test --", + "build": "lerna run build", + "prepublish": "lerna run prepublish", + "git-reset": "git reset --hard HEAD", + "git-clean": "git clean -d -x -e node_modules -e packages -f", + "now-build": "npm run build-website" + }, + "prettier": { + "trailingComma": "es5", + "singleQuote": true, + "semi": true + } +} diff --git a/templates/monorepo/packages/example/.gitignore b/templates/monorepo/packages/example/.gitignore new file mode 100644 index 000000000..587e4ec7a --- /dev/null +++ b/templates/monorepo/packages/example/.gitignore @@ -0,0 +1,3 @@ +node_modules +.cache +dist \ No newline at end of file diff --git a/templates/monorepo/packages/example/index.html b/templates/monorepo/packages/example/index.html new file mode 100644 index 000000000..547e2e042 --- /dev/null +++ b/templates/monorepo/packages/example/index.html @@ -0,0 +1,14 @@ + + + + + + + Playground + + + +
+ + + diff --git a/templates/monorepo/packages/example/index.tsx b/templates/monorepo/packages/example/index.tsx new file mode 100644 index 000000000..253e3956e --- /dev/null +++ b/templates/monorepo/packages/example/index.tsx @@ -0,0 +1,14 @@ +import 'react-app-polyfill/ie11'; +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; +import { Thing } from '@mono/react'; + +const App = () => { + return ( +
+ +
+ ); +}; + +ReactDOM.render(, document.getElementById('root')); diff --git a/templates/monorepo/packages/example/package.json b/templates/monorepo/packages/example/package.json new file mode 100644 index 000000000..745869125 --- /dev/null +++ b/templates/monorepo/packages/example/package.json @@ -0,0 +1,25 @@ +{ + "name": "@mono/example", + "version": "1.0.0", + "main": "index.js", + "license": "MIT", + "scripts": { + "start": "parcel index.html", + "build": "parcel build index.html" + }, + "dependencies": { + "react-app-polyfill": "^1.0.0", + "@mono/react": "^0.0.0" + }, + "alias": { + "react": "../../../node_modules/react", + "react-dom": "../../../node_modules/react-dom/profiling", + "scheduler/tracing": "../../../node_modules/scheduler/tracing-profiling" + }, + "devDependencies": { + "@types/react": "^16.9.11", + "@types/react-dom": "^16.8.4", + "parcel": "^1.12.3", + "typescript": "^3.4.5" + } +} diff --git a/templates/monorepo/packages/example/tsconfig.json b/templates/monorepo/packages/example/tsconfig.json new file mode 100644 index 000000000..1e2e4fd9c --- /dev/null +++ b/templates/monorepo/packages/example/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": false, + "target": "es5", + "module": "commonjs", + "jsx": "react", + "moduleResolution": "node", + "noImplicitAny": false, + "noUnusedLocals": false, + "noUnusedParameters": false, + "removeComments": true, + "strictNullChecks": true, + "preserveConstEnums": true, + "sourceMap": true, + "lib": ["es2015", "es2016", "dom"], + "types": ["node"] + } +} diff --git a/templates/monorepo/packages/react/README.md b/templates/monorepo/packages/react/README.md new file mode 100644 index 000000000..79a5c48bc --- /dev/null +++ b/templates/monorepo/packages/react/README.md @@ -0,0 +1,5 @@ +# @formium/react + +[![Stable release](https://img.shields.io/npm/v/@formium/utils.svg)](https://npm.im/@formium/utils) + +Official React SDK for Formium diff --git a/templates/monorepo/packages/react/example/index.tsx b/templates/monorepo/packages/react/example/index.tsx new file mode 100644 index 000000000..45bb548e6 --- /dev/null +++ b/templates/monorepo/packages/react/example/index.tsx @@ -0,0 +1,14 @@ +import './node_modules/react-app-polyfill/ie11'; +import * as React from 'react'; +import * as ReactDOM from './node_modules/react-dom'; +import { Thing } from '../.'; + +const App = () => { + return ( +
+ +
+ ); +}; + +ReactDOM.render(, document.getElementById('root')); diff --git a/templates/monorepo/packages/react/package.json b/templates/monorepo/packages/react/package.json new file mode 100644 index 000000000..6227a4aa7 --- /dev/null +++ b/templates/monorepo/packages/react/package.json @@ -0,0 +1,36 @@ +{ + "name": "@mono/react", + "version": "0.0.0", + "description": "Official React library for @mono", + "author": "Jared Palmer", + "repository": { + "type": "git", + "url": "git+https://github.com/mono/mono.git", + "directory": "packages/react" + }, + "scripts": { + "start": "tsdx watch --verbose", + "build": "tsdx build --tsconfig tsconfig.build.json", + "test": "tsdx test", + "lint": "tsdx lint", + "prepublish": "npm run build" + }, + "main": "dist/index.js", + "module": "dist/react.esm.js", + "typings": "dist/index.d.ts", + "files": [ + "README.md", + "dist" + ], + "peerDependencies": { + "react": "^16.8.0", + "react-dom": "^16.8.0" + }, + "dependencies": { + "@mono/utils": "^0.0.0", + "tslib": "^2.0.0" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/templates/monorepo/packages/react/src/index.tsx b/templates/monorepo/packages/react/src/index.tsx new file mode 100644 index 000000000..717604faa --- /dev/null +++ b/templates/monorepo/packages/react/src/index.tsx @@ -0,0 +1,10 @@ +import * as React from 'react'; +import { toSlug } from '@mono/utils'; + +export interface ThingProps { + message: string; +} + +export function Thing(props: ThingProps) { + return <>{toSlug(props.message)}; +} diff --git a/templates/monorepo/packages/react/test/react.test.tsx b/templates/monorepo/packages/react/test/react.test.tsx new file mode 100644 index 000000000..962687642 --- /dev/null +++ b/templates/monorepo/packages/react/test/react.test.tsx @@ -0,0 +1,5 @@ +describe('@mono/react', () => { + it('works', () => { + expect(true).toBe(true); + }); +}); diff --git a/templates/monorepo/packages/react/tsconfig.build.json b/templates/monorepo/packages/react/tsconfig.build.json new file mode 100644 index 000000000..63b06198e --- /dev/null +++ b/templates/monorepo/packages/react/tsconfig.build.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.build.json", + "include": ["src", "types", "../../types"], + "compilerOptions": { + "outDir": "./dist" + } +} diff --git a/templates/monorepo/packages/utils/README.md b/templates/monorepo/packages/utils/README.md new file mode 100644 index 000000000..7d9e3a01d --- /dev/null +++ b/templates/monorepo/packages/utils/README.md @@ -0,0 +1,7 @@ +# @mono/utils + +[![Stable release](https://img.shields.io/npm/v/@mono/utils.svg)](https://npm.im/@mono/utils) + +Shared utilities for various `@mono` packages. + +**Important:** This package is intended for internal use by the @mono libraries. You should not use it directly in your production projects, as the APIs can and will change often without regard to sem-ver. You have been warned! diff --git a/templates/monorepo/packages/utils/package.json b/templates/monorepo/packages/utils/package.json new file mode 100644 index 000000000..bf9842c6a --- /dev/null +++ b/templates/monorepo/packages/utils/package.json @@ -0,0 +1,26 @@ +{ + "name": "@mono/utils", + "version": "0.0.0", + "description": "Internal, shared utilities", + "author": "Jared Palmer ", + "scripts": { + "start": "tsdx watch --verbose", + "build": "tsdx build --tsconfig tsconfig.build.json", + "test": "tsdx test", + "lint": "tsdx lint", + "prepublish": "npm run build" + }, + "main": "dist/index.js", + "module": "dist/utils.esm.js", + "typings": "dist/index.d.ts", + "files": [ + "README.md", + "dist" + ], + "dependencies": { + "tslib": "^2.0.0" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/templates/monorepo/packages/utils/src/index.ts b/templates/monorepo/packages/utils/src/index.ts new file mode 100644 index 000000000..d9aae00a9 --- /dev/null +++ b/templates/monorepo/packages/utils/src/index.ts @@ -0,0 +1,19 @@ +/** + * Return a slugified copy of a string. + * + * @param {string} str The string to be slugified + * @return {string} The slugified string. + */ +export function toSlug(str: string): string { + let s = str; + if (!s) { + return ''; + } + s = s.toLowerCase().trim(); + s = s.replace(/ & /g, ' and '); + s = s.replace(/[ ]+/g, '-'); + s = s.replace(/[-]+/g, '-'); + s = s.replace(/[^a-z0-9-]+/g, ''); + s = s.length > 32 ? s.substr(0, 32) : s; + return s; +} diff --git a/templates/monorepo/packages/utils/test/utils.test.tsx b/templates/monorepo/packages/utils/test/utils.test.tsx new file mode 100644 index 000000000..2affdb3f6 --- /dev/null +++ b/templates/monorepo/packages/utils/test/utils.test.tsx @@ -0,0 +1,5 @@ +describe('@mono/utils', () => { + it('works', () => { + expect(true).toBe(true); + }); +}); diff --git a/templates/monorepo/packages/utils/tsconfig.build.json b/templates/monorepo/packages/utils/tsconfig.build.json new file mode 100644 index 000000000..63b06198e --- /dev/null +++ b/templates/monorepo/packages/utils/tsconfig.build.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.build.json", + "include": ["src", "types", "../../types"], + "compilerOptions": { + "outDir": "./dist" + } +} diff --git a/templates/monorepo/tsconfig.build.json b/templates/monorepo/tsconfig.build.json new file mode 100644 index 000000000..6a9c6cf43 --- /dev/null +++ b/templates/monorepo/tsconfig.build.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "allowJs": true, + "allowSyntheticDefaultImports": true, + "alwaysStrict": true, + "declaration": true, + "emitDecoratorMetadata": false, + "esModuleInterop": true, + "experimentalDecorators": false, + "importHelpers": true, + "jsx": "react", + "lib": ["dom", "esnext"], + "moduleResolution": "node", + "noFallthroughCasesInSwitch": false, + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noUnusedLocals": false, + "noUnusedParameters": false, + "pretty": true, + "sourceMap": true, + "strict": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "strictPropertyInitialization": true, + "stripInternal": true, + "target": "es5" + } +} diff --git a/templates/monorepo/tsconfig.json b/templates/monorepo/tsconfig.json new file mode 100644 index 000000000..58dd30de7 --- /dev/null +++ b/templates/monorepo/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.build.json", + "include": ["packages", "types", "scripts", "example"], + "compilerOptions": { + "allowJs": false, + "baseUrl": ".", + "typeRoots": ["./node_modules/@types", "./types"], + "paths": { + "@mono/utils": ["packages/eval/src"], + "@mono/react": ["packages/react/src"], + "$test/*": ["test/*"] + } + } +} diff --git a/templates/monorepo/types/global.d.ts b/templates/monorepo/types/global.d.ts new file mode 100644 index 000000000..cd09ec42b --- /dev/null +++ b/templates/monorepo/types/global.d.ts @@ -0,0 +1,6 @@ +// Declare global variables for TypeScript and VSCode. +// Do not rename this file or move these types into index.d.ts +// @see https://code.visualstudio.com/docs/nodejs/working-with-javascript#_global-variables-and-type-checking +declare const __DEV__: boolean; +declare const __VERSION__: string; +declare const $FixMe: any; From eb7ff55a80c1a825fdc20bf890b07e8c0fbca585 Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Sun, 19 Jul 2020 17:48:37 -0400 Subject: [PATCH 02/13] Move example up to top level --- .../monorepo/{packages => }/example/.gitignore | 0 .../monorepo/{packages => }/example/index.html | 0 .../monorepo/{packages => }/example/index.tsx | 2 +- .../monorepo/{packages => }/example/package.json | 10 +++++----- .../monorepo/{packages => }/example/tsconfig.json | 0 templates/monorepo/package.json | 2 ++ .../monorepo/packages/react/example/index.tsx | 14 -------------- templates/monorepo/packages/react/package.json | 2 +- templates/monorepo/packages/utils/package.json | 2 +- 9 files changed, 10 insertions(+), 22 deletions(-) rename templates/monorepo/{packages => }/example/.gitignore (100%) rename templates/monorepo/{packages => }/example/index.html (100%) rename templates/monorepo/{packages => }/example/index.tsx (86%) rename templates/monorepo/{packages => }/example/package.json (60%) rename templates/monorepo/{packages => }/example/tsconfig.json (100%) delete mode 100644 templates/monorepo/packages/react/example/index.tsx diff --git a/templates/monorepo/packages/example/.gitignore b/templates/monorepo/example/.gitignore similarity index 100% rename from templates/monorepo/packages/example/.gitignore rename to templates/monorepo/example/.gitignore diff --git a/templates/monorepo/packages/example/index.html b/templates/monorepo/example/index.html similarity index 100% rename from templates/monorepo/packages/example/index.html rename to templates/monorepo/example/index.html diff --git a/templates/monorepo/packages/example/index.tsx b/templates/monorepo/example/index.tsx similarity index 86% rename from templates/monorepo/packages/example/index.tsx rename to templates/monorepo/example/index.tsx index 253e3956e..af29347a9 100644 --- a/templates/monorepo/packages/example/index.tsx +++ b/templates/monorepo/example/index.tsx @@ -6,7 +6,7 @@ import { Thing } from '@mono/react'; const App = () => { return (
- +
); }; diff --git a/templates/monorepo/packages/example/package.json b/templates/monorepo/example/package.json similarity index 60% rename from templates/monorepo/packages/example/package.json rename to templates/monorepo/example/package.json index 745869125..55062b90a 100644 --- a/templates/monorepo/packages/example/package.json +++ b/templates/monorepo/example/package.json @@ -8,13 +8,13 @@ "build": "parcel build index.html" }, "dependencies": { - "react-app-polyfill": "^1.0.0", - "@mono/react": "^0.0.0" + "react-app-polyfill": "^1.0.0" }, "alias": { - "react": "../../../node_modules/react", - "react-dom": "../../../node_modules/react-dom/profiling", - "scheduler/tracing": "../../../node_modules/scheduler/tracing-profiling" + "@mono/react": "../packages/react", + "react": "../node_modules/react", + "react-dom": "../node_modules/react-dom/profiling", + "scheduler/tracing": "../node_modules/scheduler/tracing-profiling" }, "devDependencies": { "@types/react": "^16.9.11", diff --git a/templates/monorepo/packages/example/tsconfig.json b/templates/monorepo/example/tsconfig.json similarity index 100% rename from templates/monorepo/packages/example/tsconfig.json rename to templates/monorepo/example/tsconfig.json diff --git a/templates/monorepo/package.json b/templates/monorepo/package.json index d72de6405..9b0c0b60f 100644 --- a/templates/monorepo/package.json +++ b/templates/monorepo/package.json @@ -5,6 +5,8 @@ "@types/react": "^16.9.43", "@types/react-dom": "^16.9.8", "lerna": "^3.15.0", + "react": "^16.13.1", + "react-dom": "^16.13.1", "tsdx": "^0.13.2", "typescript": "^3.9.7" }, diff --git a/templates/monorepo/packages/react/example/index.tsx b/templates/monorepo/packages/react/example/index.tsx deleted file mode 100644 index 45bb548e6..000000000 --- a/templates/monorepo/packages/react/example/index.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import './node_modules/react-app-polyfill/ie11'; -import * as React from 'react'; -import * as ReactDOM from './node_modules/react-dom'; -import { Thing } from '../.'; - -const App = () => { - return ( -
- -
- ); -}; - -ReactDOM.render(, document.getElementById('root')); diff --git a/templates/monorepo/packages/react/package.json b/templates/monorepo/packages/react/package.json index 6227a4aa7..c68f29aec 100644 --- a/templates/monorepo/packages/react/package.json +++ b/templates/monorepo/packages/react/package.json @@ -9,7 +9,7 @@ "directory": "packages/react" }, "scripts": { - "start": "tsdx watch --verbose", + "start": "tsdx watch --verbose --noClean", "build": "tsdx build --tsconfig tsconfig.build.json", "test": "tsdx test", "lint": "tsdx lint", diff --git a/templates/monorepo/packages/utils/package.json b/templates/monorepo/packages/utils/package.json index bf9842c6a..6d6f107e4 100644 --- a/templates/monorepo/packages/utils/package.json +++ b/templates/monorepo/packages/utils/package.json @@ -4,7 +4,7 @@ "description": "Internal, shared utilities", "author": "Jared Palmer ", "scripts": { - "start": "tsdx watch --verbose", + "start": "tsdx watch --verbose --noClean", "build": "tsdx build --tsconfig tsconfig.build.json", "test": "tsdx test", "lint": "tsdx lint", From 7c98c94566beaad9cfe7162c7d2ae5a1a2b39135 Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Sun, 19 Jul 2020 18:07:46 -0400 Subject: [PATCH 03/13] Add some notes about yalc --- templates/monorepo/README.md | 61 ++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/templates/monorepo/README.md b/templates/monorepo/README.md index dd10c4df5..1c151e43b 100644 --- a/templates/monorepo/README.md +++ b/templates/monorepo/README.md @@ -21,10 +21,65 @@ This will install all dependencies in each project, build them, and symlink them ## Development workflow +In one terminal, run tsdx watch in parallel: + +```sh +npm dev # or yarn dev +``` + +This builds each package to `//dist` and runs the project in watch mode so any edits you save inside `//src` causes a rebuild to `//dist`. The results wil stream to to the terminal. + +### Using the example/playground + +YOu can play with local packages in the Parcel-powered example/playground. + ```sh -npm start # or yarn start +cd example +npm install # or yarn install +npm start ``` -This builds each package to `//dist` and runs the project in watch mode so any edits you save inside `//src` causes a rebuild to `//dist`. +This will start the example/playground on `localhost:1234`. If you have lerna running watch in parallel mode in one terminal, and then you run parcel, your playground will hot reload when you make changes to any imported module whose source is inside of `packages/*/src/*`. Note that to accomplish this, each package's `start` command passes TDSX the `--noClean` flag. This prevents Parcel from exploding between rebuilds because of File Not Found errors. + +Important Safety Tip: When adding/altering packages in the playground, use `alias` object in package.json. This will tell Parcel to resolve them to the filesystem instead of trying to install the package from NPM. It also fixes duplicate React errors you may run into. + +#### Yalc + +[Yalc](https://github.com/whitecolor/yalc) is alternative to `yarn/npm link` (and Parcel aliasing) that many developer find useful because it more closely mimics how NPM works. It works kind of like local package registry via filesystem and symlinking magic. + +To do this, install yalc globally. + +Using NPM: + +```sh +npm i yalc -g +``` + +Using Yarn: + +```sh +yarn global add yalc +``` + +Then in each package's `start` command add a [`yalc publish`](https://github.com/whitecolor/yalc#publish) or `yalc push` as an TSDX `--onSuccess` hook. + +```diff +"scripts": { +- "start": "tsdx watch --verbose --noClean", ++ "start": "tsdx watch --verbose --noClean --onSuccess yalc publish", + "build": "tsdx build --tsconfig tsconfig.build.json", + "test": "tsdx test", + "lint": "tsdx lint", + "prepublish": "npm run build" + }, +``` + +In your example directory, now add each package via yalc + +```sh +yalc add +# or +yalc link +``` -In addition, this will start the example/playground on `localhost:1234` +There's definitely room for improvement with this workflow, so please contribute if you come up with something better. From 3b333fed3496cdd84bb43b180bb24d56c7d1f635 Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Mon, 20 Jul 2020 10:24:00 -0400 Subject: [PATCH 04/13] Remove unused scripts --- templates/monorepo/package.json | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/templates/monorepo/package.json b/templates/monorepo/package.json index 9b0c0b60f..828ec0eed 100644 --- a/templates/monorepo/package.json +++ b/templates/monorepo/package.json @@ -15,13 +15,10 @@ ], "scripts": { "lerna": "lerna", - "dev": "lerna run start --stream --parallel", + "start": "lerna run start --stream --parallel", "test": "lerna run test --", "build": "lerna run build", - "prepublish": "lerna run prepublish", - "git-reset": "git reset --hard HEAD", - "git-clean": "git clean -d -x -e node_modules -e packages -f", - "now-build": "npm run build-website" + "prepublish": "lerna run prepublish" }, "prettier": { "trailingComma": "es5", From 56a75c2238deb2afda44c898fe79b0d929211ed6 Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Mon, 20 Jul 2020 10:25:04 -0400 Subject: [PATCH 05/13] Not that only Yarn works --- templates/monorepo/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/monorepo/README.md b/templates/monorepo/README.md index 1c151e43b..404bb0374 100644 --- a/templates/monorepo/README.md +++ b/templates/monorepo/README.md @@ -11,10 +11,10 @@ Unlike other TSDX templates, the developer experience for this template is curre Your first order of business will be to search and replace `@mono` for the npm organization of your own. -After that you can install all the dependencies in the root directory +After that you can install all the dependencies in the root directory. Since the monorepo uses Lerna and Yarn Workspaces, npm CLI is not supported (only yarn). ```sh -npm install # or yarn install +yarn install ``` This will install all dependencies in each project, build them, and symlink them via Lerna @@ -24,7 +24,7 @@ This will install all dependencies in each project, build them, and symlink them In one terminal, run tsdx watch in parallel: ```sh -npm dev # or yarn dev +yarn start ``` This builds each package to `//dist` and runs the project in watch mode so any edits you save inside `//src` causes a rebuild to `//dist`. The results wil stream to to the terminal. @@ -35,8 +35,8 @@ YOu can play with local packages in the Parcel-powered example/playground. ```sh cd example -npm install # or yarn install -npm start +yarn install # or yarn install +yarn start ``` This will start the example/playground on `localhost:1234`. If you have lerna running watch in parallel mode in one terminal, and then you run parcel, your playground will hot reload when you make changes to any imported module whose source is inside of `packages/*/src/*`. Note that to accomplish this, each package's `start` command passes TDSX the `--noClean` flag. This prevents Parcel from exploding between rebuilds because of File Not Found errors. From 49689f55875b835ea53217213c57b6a427a3a4f8 Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Mon, 20 Jul 2020 10:25:17 -0400 Subject: [PATCH 06/13] Fix react package name --- templates/monorepo/packages/react/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/monorepo/packages/react/README.md b/templates/monorepo/packages/react/README.md index 79a5c48bc..f8be93c50 100644 --- a/templates/monorepo/packages/react/README.md +++ b/templates/monorepo/packages/react/README.md @@ -1,5 +1,5 @@ -# @formium/react +# @mono/react -[![Stable release](https://img.shields.io/npm/v/@formium/utils.svg)](https://npm.im/@formium/utils) +[![Stable release](https://img.shields.io/npm/v/@mono/utils.svg)](https://npm.im/@mono/utils) -Official React SDK for Formium +Official React SDK for @mono From 6096e7da35857ebb3ea471d883f17d58eef45af0 Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Tue, 21 Jul 2020 13:14:12 -0400 Subject: [PATCH 07/13] Add correct tsconfig for watch as well --- templates/monorepo/packages/react/package.json | 2 +- templates/monorepo/packages/utils/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/monorepo/packages/react/package.json b/templates/monorepo/packages/react/package.json index c68f29aec..f8d319683 100644 --- a/templates/monorepo/packages/react/package.json +++ b/templates/monorepo/packages/react/package.json @@ -9,7 +9,7 @@ "directory": "packages/react" }, "scripts": { - "start": "tsdx watch --verbose --noClean", + "start": "tsdx watch --tsconfig tsconfig.build.json --verbose --noClean", "build": "tsdx build --tsconfig tsconfig.build.json", "test": "tsdx test", "lint": "tsdx lint", diff --git a/templates/monorepo/packages/utils/package.json b/templates/monorepo/packages/utils/package.json index 6d6f107e4..28ba095e3 100644 --- a/templates/monorepo/packages/utils/package.json +++ b/templates/monorepo/packages/utils/package.json @@ -4,7 +4,7 @@ "description": "Internal, shared utilities", "author": "Jared Palmer ", "scripts": { - "start": "tsdx watch --verbose --noClean", + "start": "tsdx watch --tsconfig tsconfig.build.json --verbose --noClean", "build": "tsdx build --tsconfig tsconfig.build.json", "test": "tsdx test", "lint": "tsdx lint", From 4b6f445a8537fbce37aabb47b42febfe180302a7 Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Fri, 11 Sep 2020 09:57:08 -0400 Subject: [PATCH 08/13] Remove target from tsconfig.build.json --- templates/monorepo/tsconfig.build.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/monorepo/tsconfig.build.json b/templates/monorepo/tsconfig.build.json index 6a9c6cf43..5a4c2b750 100644 --- a/templates/monorepo/tsconfig.build.json +++ b/templates/monorepo/tsconfig.build.json @@ -23,7 +23,6 @@ "strictFunctionTypes": true, "strictNullChecks": true, "strictPropertyInitialization": true, - "stripInternal": true, - "target": "es5" + "stripInternal": true } } From c825a88f6a1eda238c89e188a6669b1e906c7ddc Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Fri, 11 Sep 2020 09:58:34 -0400 Subject: [PATCH 09/13] Remove website stuff from .gitignore --- templates/monorepo/.gitignore | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/templates/monorepo/.gitignore b/templates/monorepo/.gitignore index 4a12e1903..c20d8e12e 100644 --- a/templates/monorepo/.gitignore +++ b/templates/monorepo/.gitignore @@ -1,25 +1,12 @@ -dist -compiled *.log -coverage .DS_Store -next.d.ts -legacy.d.ts -.idea -*.orig +node_modules +dist node_modules package-lock.json yarn.lock !/yarn.lock -website/translated_docs -website/build -website/yarn.lock -website/node_modules -website/i18n -!website/yarn.lock - -.vercel .yalc yalc.lock \ No newline at end of file From 4d0bfa36a18698e7d89f40120d5fab5fc8231df0 Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Fri, 11 Sep 2020 09:59:04 -0400 Subject: [PATCH 10/13] Update templates/monorepo/README.md Co-authored-by: Anton Gilgur --- templates/monorepo/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/monorepo/README.md b/templates/monorepo/README.md index 404bb0374..ba9db219d 100644 --- a/templates/monorepo/README.md +++ b/templates/monorepo/README.md @@ -45,7 +45,7 @@ Important Safety Tip: When adding/altering packages in the playground, use `alia #### Yalc -[Yalc](https://github.com/whitecolor/yalc) is alternative to `yarn/npm link` (and Parcel aliasing) that many developer find useful because it more closely mimics how NPM works. It works kind of like local package registry via filesystem and symlinking magic. +[Yalc](https://github.com/whitecolor/yalc) is an alternative to `yarn/npm link` (and Parcel aliasing) that many developers find useful because it more closely mimics how NPM works. It works kind of like a local package registry via filesystem and symlinking magic. To do this, install yalc globally. From 1597c337c0e4e0553923480dc8ed057967d7df06 Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Fri, 11 Sep 2020 10:06:21 -0400 Subject: [PATCH 11/13] Clean up tsconfigs --- .../packages/react/tsconfig.build.json | 5 +-- .../packages/utils/tsconfig.build.json | 5 +-- templates/monorepo/tsconfig.build.json | 33 +++++++------------ 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/templates/monorepo/packages/react/tsconfig.build.json b/templates/monorepo/packages/react/tsconfig.build.json index 63b06198e..16bbd61d3 100644 --- a/templates/monorepo/packages/react/tsconfig.build.json +++ b/templates/monorepo/packages/react/tsconfig.build.json @@ -1,7 +1,4 @@ { "extends": "../../tsconfig.build.json", - "include": ["src", "types", "../../types"], - "compilerOptions": { - "outDir": "./dist" - } + "include": ["src", "types", "../../types"] } diff --git a/templates/monorepo/packages/utils/tsconfig.build.json b/templates/monorepo/packages/utils/tsconfig.build.json index 63b06198e..e34f92a29 100644 --- a/templates/monorepo/packages/utils/tsconfig.build.json +++ b/templates/monorepo/packages/utils/tsconfig.build.json @@ -1,7 +1,4 @@ { "extends": "../../tsconfig.build.json", - "include": ["src", "types", "../../types"], - "compilerOptions": { - "outDir": "./dist" - } + "include": ["src", "types", "../../types"] } diff --git a/templates/monorepo/tsconfig.build.json b/templates/monorepo/tsconfig.build.json index 5a4c2b750..10182cfe8 100644 --- a/templates/monorepo/tsconfig.build.json +++ b/templates/monorepo/tsconfig.build.json @@ -1,28 +1,17 @@ { "compilerOptions": { - "allowJs": true, - "allowSyntheticDefaultImports": true, - "alwaysStrict": true, - "declaration": true, - "emitDecoratorMetadata": false, - "esModuleInterop": true, - "experimentalDecorators": false, - "importHelpers": true, - "jsx": "react", + "module": "esnext", "lib": ["dom", "esnext"], - "moduleResolution": "node", - "noFallthroughCasesInSwitch": false, - "noImplicitAny": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "noUnusedLocals": false, - "noUnusedParameters": false, - "pretty": true, - "sourceMap": true, + "importHelpers": true, + "declaration": true, + "sourceMap": true, "strict": true, - "strictFunctionTypes": true, - "strictNullChecks": true, - "strictPropertyInitialization": true, - "stripInternal": true + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "moduleResolution": "node", + "jsx": "react", + "esModuleInterop": true } } From d76158626ebda9f3079cd3d6d5cb631628b52804 Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Fri, 11 Sep 2020 10:20:05 -0400 Subject: [PATCH 12/13] Update templates/monorepo/README.md Co-authored-by: Anton Gilgur --- templates/monorepo/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/monorepo/README.md b/templates/monorepo/README.md index ba9db219d..55f84458d 100644 --- a/templates/monorepo/README.md +++ b/templates/monorepo/README.md @@ -27,7 +27,7 @@ In one terminal, run tsdx watch in parallel: yarn start ``` -This builds each package to `//dist` and runs the project in watch mode so any edits you save inside `//src` causes a rebuild to `//dist`. The results wil stream to to the terminal. +This builds each package to `//dist` and runs the project in watch mode so any edits you save inside `//src` cause a rebuild to `//dist`. The results will stream to to the terminal. ### Using the example/playground From 155b7d269f8c1ff54c3870f889f23604330d4d1f Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Fri, 11 Sep 2020 10:20:19 -0400 Subject: [PATCH 13/13] Update templates/monorepo/README.md Co-authored-by: Anton Gilgur --- templates/monorepo/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/monorepo/README.md b/templates/monorepo/README.md index 55f84458d..e05e0c9e7 100644 --- a/templates/monorepo/README.md +++ b/templates/monorepo/README.md @@ -31,7 +31,7 @@ This builds each package to `//dist` and runs the project in ### Using the example/playground -YOu can play with local packages in the Parcel-powered example/playground. +You can play with local packages in the Parcel-powered example/playground. ```sh cd example