presetter-preset-react 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ <div align="center">
2
+
3
+ ![Logo](https://github.com/alvis/presetter/raw/master/assets/logo.svg)
4
+
5
+ ๐Ÿ„๐Ÿป _A collection of opinionated configurations for a React project in typescript for presetter_
6
+
7
+ โ€ขโ€ƒ โ€ƒ[Quick Start](#quick-start)โ€ƒ โ€ƒโ€ขโ€ƒ โ€ƒ[Project Structure](#project-structure)โ€ƒ โ€ƒโ€ขโ€ƒ โ€ƒ[Customisation](#customisation)โ€ƒ โ€ƒโ€ขโ€ƒ โ€ƒ[Scripts](#script-template-summary)โ€ƒ โ€ƒโ€ข
8
+
9
+ [![npm](https://img.shields.io/npm/v/presetter-preset-react?style=flat-square)](https://github.com/alvis/presetter/releases)
10
+ [![build](https://img.shields.io/github/workflow/status/alvis/presetter/code%20test?style=flat-square)](https://github.com/alvis/presetter/actions)
11
+ [![maintainability](https://img.shields.io/codeclimate/maintainability/alvis/presetter?style=flat-square)](https://codeclimate.com/github/alvis/presetter/maintainability)
12
+ [![coverage](https://img.shields.io/codeclimate/coverage/alvis/presetter?style=flat-square)](https://codeclimate.com/github/alvis/presetter/test_coverage)
13
+ [![security](https://img.shields.io/snyk/vulnerabilities/github/alvis/presetter/packages/preset-react/package.json.svg?style=flat-square)](https://snyk.io/test/github/alvis/presetter?targetFile=packages/preset-react/package.json&style=flat-square)
14
+ [![dependencies](https://img.shields.io/david/alvis/presetter?path=packages/preset-react&style=flat-square)](https://david-dm.org/alvis/presetter?path=packages/preset-react)
15
+ [![license](https://img.shields.io/github/license/alvis/presetter.svg?style=flat-square)](https://github.com/alvis/presetter/blob/master/LICENSE)
16
+
17
+ </div>
18
+
19
+ ## Features
20
+
21
+ **presetter-preset-react** is an opinionated preset for you to setup a React project in a fraction of time you usually take via [**presetter**](https://github.com/alvis/presetter).
22
+
23
+ - โœจ TSX support
24
+ - ๐Ÿงช @testing-library/react
25
+ - ๐Ÿ“ Recommended rules from eslint-plugin-react
26
+
27
+ ## Quick Start
28
+
29
+ [**FULL DOCUMENTATION IS AVAILABLE HERE**](https://github.com/alvis/presetter/blob/master/README.md)
30
+
31
+ 1. Bootstrap your project with `presetter-preset-essentials` & `presetter-preset-react`
32
+
33
+ ```shell
34
+ npx presetter use presetter-preset presetter-preset-react
35
+ ```
36
+
37
+ That's. One command and you're set.
38
+
39
+ 2. Develop and run life cycle scripts provided by the preset
40
+
41
+ At this point, all development packages specified in the preset are installed,
42
+ and now you can try to run some example life cycle scripts (e.g. run prepare).
43
+
44
+ ![Demo](https://raw.githubusercontent.com/alvis/presetter/master/assets/demo.gif)
45
+
46
+ ## Project Structure
47
+
48
+ After installation, your project file structure should resemble the following or with more configuration files if you also installed other presets such as [`presetter-preset-essentials`](https://github.com/alvis/presetter/blob/master/packages/preset-essentials).
49
+
50
+ Implement your business logic under `source` and prepare tests under `spec`. The `.d.ts` files are handy type definitions for you to import `.css` or image files in typescript.
51
+
52
+ **TIPS** You can always change the source directory to other (e.g. src) by setting the `source` variable in `.presetterrc.json`. See the [customisation](https://github.com/alvis/presetter/blob/master/packages/preset-react#customisation) section below for more details.
53
+
54
+ ```
55
+ (root)
56
+ โ”œโ”€ .eslintrc.json
57
+ โ”œโ”€ .git
58
+ โ”œโ”€ .preseterrc.json
59
+ โ”œโ”€ node_modules
60
+ โ”œโ”€ source
61
+ โ”‚ โ”œโ”€ <folders>
62
+ โ”‚ โ”œโ”€ index.ts
63
+ โ”‚ โ”œโ”€ (auxiliary).ts
64
+ โ”œโ”€ spec
65
+ โ”‚ โ”œโ”€ *.spec.ts
66
+ โ”œโ”€ types
67
+ โ”‚ โ”œโ”€ image.d.ts
68
+ โ”‚ โ”œโ”€ style.d.ts
69
+ โ”‚ โ”œโ”€ (type).d.ts
70
+ โ”œโ”€ package.json
71
+ โ””โ”€ tsconfig.json
72
+ ```
73
+
74
+ ## Customisation
75
+
76
+ By default, this preset exports a handy configuration set for a React project written in typescript.
77
+ But you can further customise (either extending or replacing) the configuration by specifying the change in the config file (`.presetterrc` or `.presetterrc.json`).
78
+
79
+ These settings are available in the `config` field in the config file. For directories, the setting is specified in the `variable` field.
80
+
81
+ The structure of `.presetterrc` should follow the interface below:
82
+
83
+ ```ts
84
+ interface PresetterRC {
85
+ /** name(s) of the preset e.g. presetter-preset-react */
86
+ name: string | string[];
87
+ /** additional configuration passed to the preset for generating the configuration files */
88
+ config?: {
89
+ // โ”Œโ”€ configuration for other tools via other presets (e.g. presetter-preset-essentials)
90
+ // ...
91
+
92
+ /** configuration to be merged with .eslintrc */
93
+ eslint?: Record<string, unknown>;
94
+ /** configuration to be merged with tsconfig.json */
95
+ tsconfig?: Record<string, unknown>;
96
+ /** variables to be substituted in templates */
97
+ variable?: {
98
+ /** the directory containing all source code (default: source) */
99
+ source?: string;
100
+ /** the directory containing all typing files (default: types) */
101
+ types?: string;
102
+ /** the directory containing all output tile (default: source) */
103
+ output?: string;
104
+ };
105
+ };
106
+ }
107
+ ```
@@ -0,0 +1,14 @@
1
+ rules:
2
+ '@typescript-eslint/naming-convention':
3
+ - error
4
+ - selector: variable
5
+ types:
6
+ - function
7
+ format:
8
+ - camelCase
9
+ - PascalCase
10
+ jsdoc/require-returns: # tell us what the function is expected to return
11
+ 1:
12
+ contexts:
13
+ - FunctionDeclaration:has(BlockStatement > ReturnStatement:not([argument.type='JSXElement']))
14
+ - ArrowFunctionExpression:has(BlockStatement > ReturnStatement:not([argument.type='JSXElement']))
@@ -0,0 +1,5 @@
1
+ collectCoverageFrom:
2
+ - src/**/*.tsx
3
+ testEnvironment: jsdom
4
+ testMatch:
5
+ - '**/?(*.)+(spec).tsx'
@@ -0,0 +1,2 @@
1
+ '{source}/**/*.[tj]sx':
2
+ - presetter run stage
@@ -0,0 +1,3 @@
1
+ external:
2
+ - react
3
+ - react-dom
package/lib/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { PresetAsset } from 'presetter';
2
+ export declare type PresetConfig = {
3
+ eslint?: Record<string, unknown>;
4
+ tsconfig?: Record<string, unknown>;
5
+ };
6
+ export declare type Variable = {
7
+ source?: string;
8
+ types?: string;
9
+ output?: string;
10
+ };
11
+ export declare const DEFAULT_VARIABLE: Variable;
12
+ export default function (): Promise<PresetAsset>;
package/lib/index.js ADDED
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ exports.DEFAULT_VARIABLE = void 0;
8
+
9
+ var _path = require("path");
10
+
11
+ /*
12
+ * *** MIT LICENSE ***
13
+ * -------------------------------------------------------------------------
14
+ * This code may be modified and distributed under the MIT license.
15
+ * See the LICENSE file for details.
16
+ * -------------------------------------------------------------------------
17
+ *
18
+ * @summary Preset for a React project
19
+ *
20
+ * @author Alvis HT Tang <alvis@hilbert.space>
21
+ * @license MIT
22
+ * @copyright Copyright (c) 2021 - All Rights Reserved.
23
+ * -------------------------------------------------------------------------
24
+ */
25
+ // paths to the template directory
26
+ const TEMPLATES = (0, _path.resolve)(__dirname, '..', 'templates');
27
+ const CONFIGS = (0, _path.resolve)(__dirname, '..', 'configs');
28
+ /** config for this preset */
29
+
30
+ const DEFAULT_VARIABLE = {
31
+ source: 'source',
32
+ types: 'types',
33
+ output: 'lib'
34
+ };
35
+ exports.DEFAULT_VARIABLE = DEFAULT_VARIABLE;
36
+ const IMAGE_TYPE = 'image.d.ts';
37
+ const STYLE_TYPE = 'style.d.ts';
38
+
39
+ const template = ({
40
+ custom: {
41
+ variable: {
42
+ types
43
+ }
44
+ }
45
+ }) => ({
46
+ '.eslintrc.json': (0, _path.resolve)(TEMPLATES, 'eslintrc.yaml'),
47
+ 'tsconfig.json': (0, _path.resolve)(TEMPLATES, 'tsconfig.yaml'),
48
+ [(0, _path.join)(types, IMAGE_TYPE)]: (0, _path.resolve)(TEMPLATES, IMAGE_TYPE),
49
+ [(0, _path.join)(types, STYLE_TYPE)]: (0, _path.resolve)(TEMPLATES, STYLE_TYPE)
50
+ });
51
+
52
+ const noSymlinks = ({
53
+ custom: {
54
+ variable: {
55
+ types
56
+ }
57
+ }
58
+ }) => [(0, _path.join)(types, IMAGE_TYPE), (0, _path.join)(types, STYLE_TYPE)];
59
+
60
+ const supplementaryConfig = {
61
+ eslint: (0, _path.resolve)(CONFIGS, 'eslint.yaml'),
62
+ gitignore: ({
63
+ custom: {
64
+ variable: {
65
+ types
66
+ }
67
+ }
68
+ }) => [(0, _path.join)('/', types, IMAGE_TYPE), (0, _path.join)('/', types, STYLE_TYPE)],
69
+ jest: (0, _path.resolve)(CONFIGS, 'jest.yaml'),
70
+ lintstaged: (0, _path.resolve)(CONFIGS, 'lintstaged.yaml'),
71
+ rollup: (0, _path.resolve)(CONFIGS, 'rollup.yaml')
72
+ };
73
+ /**
74
+ * get the list of templates provided by this preset
75
+ * @returns list of preset templates
76
+ */
77
+
78
+ async function _default() {
79
+ return {
80
+ template,
81
+ noSymlinks,
82
+ supplementaryConfig,
83
+ variable: DEFAULT_VARIABLE
84
+ };
85
+ }
86
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../source/index.ts"],"names":["TEMPLATES","__dirname","CONFIGS","DEFAULT_VARIABLE","source","types","output","IMAGE_TYPE","STYLE_TYPE","template","custom","variable","noSymlinks","supplementaryConfig","eslint","gitignore","jest","lintstaged","rollup"],"mappings":";;;;;;;;AAeA;;AAfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMA;AACA,MAAMA,SAAS,GAAG,mBAAQC,SAAR,EAAmB,IAAnB,EAAyB,WAAzB,CAAlB;AACA,MAAMC,OAAO,GAAG,mBAAQD,SAAR,EAAmB,IAAnB,EAAyB,SAAzB,CAAhB;AAEA;;AAkBO,MAAME,gBAA0B,GAAG;AACxCC,EAAAA,MAAM,EAAE,QADgC;AAEx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,EAAiB,iBAAjB,CARkD;AAS9DgB,EAAAA,MAAM,EAAE,mBAAQhB,OAAR,EAAiB,aAAjB;AATsD,CAAhE;AAYA;AACA;AACA;AACA;;AACe,0BAAwC;AACrD,SAAO;AACLO,IAAAA,QADK;AAELG,IAAAA,UAFK;AAGLC,IAAAA,mBAHK;AAILF,IAAAA,QAAQ,EAAER;AAJL,GAAP;AAMD","sourcesContent":["/*\n * *** MIT LICENSE ***\n * -------------------------------------------------------------------------\n * This code may be modified and distributed under the MIT license.\n * See the LICENSE file for details.\n * -------------------------------------------------------------------------\n *\n * @summary Preset for a React project\n *\n * @author Alvis HT Tang <alvis@hilbert.space>\n * @license MIT\n * @copyright Copyright (c) 2021 - All Rights Reserved.\n * -------------------------------------------------------------------------\n */\n\nimport { join, resolve } from 'path';\n\nimport type { PresetAsset } from 'presetter';\n\n// paths to the template directory\nconst TEMPLATES = resolve(__dirname, '..', 'templates');\nconst CONFIGS = resolve(__dirname, '..', 'configs');\n\n/** config for this preset */\nexport type PresetConfig = {\n /** configuration to be merged with .eslintrc */\n eslint?: Record<string, unknown>;\n /** configuration to be merged with tsconfig.json */\n tsconfig?: Record<string, unknown>;\n};\n\n/** list of configurable variables */\nexport type Variable = {\n /** the directory containing all source code (default: source) */\n source?: string;\n /** the directory containing all extra typing files (default: types) */\n types?: string;\n /** the directory containing all the compiled files (default: lib) */\n output?: string;\n};\n\nexport const DEFAULT_VARIABLE: Variable = {\n source: 'source',\n types: 'types',\n output: 'lib',\n};\n\nconst IMAGE_TYPE = 'image.d.ts';\nconst STYLE_TYPE = 'style.d.ts';\n\nconst template: PresetAsset['template'] = ({\n custom: {\n variable: { types },\n },\n}) => ({\n '.eslintrc.json': resolve(TEMPLATES, 'eslintrc.yaml'),\n 'tsconfig.json': resolve(TEMPLATES, 'tsconfig.yaml'),\n [join(types, IMAGE_TYPE)]: resolve(TEMPLATES, IMAGE_TYPE),\n [join(types, STYLE_TYPE)]: resolve(TEMPLATES, STYLE_TYPE),\n});\n\nconst noSymlinks: PresetAsset['noSymlinks'] = ({\n custom: {\n variable: { types },\n },\n}) => [join(types, IMAGE_TYPE), join(types, STYLE_TYPE)];\n\nconst supplementaryConfig: PresetAsset['supplementaryConfig'] = {\n eslint: resolve(CONFIGS, 'eslint.yaml'),\n gitignore: ({\n custom: {\n variable: { types },\n },\n }) => [join('/', types, IMAGE_TYPE), join('/', types, STYLE_TYPE)],\n jest: resolve(CONFIGS, 'jest.yaml'),\n lintstaged: resolve(CONFIGS, 'lintstaged.yaml'),\n rollup: resolve(CONFIGS, 'rollup.yaml'),\n};\n\n/**\n * get the list of templates provided by this preset\n * @returns list of preset templates\n */\nexport default async function (): Promise<PresetAsset> {\n return {\n template,\n noSymlinks,\n supplementaryConfig,\n variable: DEFAULT_VARIABLE,\n };\n}\n"],"file":"index.js"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "presetter-preset-react",
3
+ "version": "3.0.0",
4
+ "description": "An opinionated presetter preset for a React project",
5
+ "keywords": [
6
+ "presetter",
7
+ "preset"
8
+ ],
9
+ "homepage": "https://github.com/alvis/presetter#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/alvis/presetter/issues"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Alvis HT Tang <alvis@hilbert.space>",
15
+ "main": "lib/index.js",
16
+ "types": "lib/index.d.ts",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/alvis/presetter.git"
20
+ },
21
+ "scripts": {
22
+ "bootstrap": "presetter bootstrap && run prepare",
23
+ "build": "run build",
24
+ "coverage": "run coverage",
25
+ "lint": "run lint",
26
+ "prepublishOnly": "run prepare && run prepublishOnly",
27
+ "release": "run-s release:peer:*",
28
+ "release:peer:presetter": "npm pkg set peerDependencies.presetter=^$(npx -c 'echo $npm_package_version')",
29
+ "test": "run test",
30
+ "watch": "run watch"
31
+ },
32
+ "peerDependencies": {
33
+ "@babel/preset-react": "^7.0.0",
34
+ "@testing-library/react": "^12.0.0",
35
+ "@types/react": "^17.0.0",
36
+ "eslint-plugin-react": "^7.0.0",
37
+ "presetter": "^3.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "presetter": "file:../presetter",
41
+ "presetter-preset-strict": "file:../preset-strict"
42
+ }
43
+ }
@@ -0,0 +1,12 @@
1
+ extends:
2
+ - plugin:react/recommended
3
+ rules:
4
+ react/boolean-prop-naming: warn
5
+ react/button-has-type: warn
6
+ react/destructuring-assignment: warn
7
+ react/prop-types: 'off'
8
+ react/sort-comp: warn
9
+ react/jsx-sort-props:
10
+ - warn
11
+ - callbacksLast: true
12
+ shorthandFirst: true
@@ -0,0 +1,48 @@
1
+ /// <reference types="react" />
2
+ /// <reference types="react-dom" />
3
+
4
+ declare module '*.avif' {
5
+ const src: string;
6
+ export default src;
7
+ }
8
+
9
+ declare module '*.bmp' {
10
+ const src: string;
11
+ export default src;
12
+ }
13
+
14
+ declare module '*.gif' {
15
+ const src: string;
16
+ export default src;
17
+ }
18
+
19
+ declare module '*.jpg' {
20
+ const src: string;
21
+ export default src;
22
+ }
23
+
24
+ declare module '*.jpeg' {
25
+ const src: string;
26
+ export default src;
27
+ }
28
+
29
+ declare module '*.png' {
30
+ const src: string;
31
+ export default src;
32
+ }
33
+
34
+ declare module '*.webp' {
35
+ const src: string;
36
+ export default src;
37
+ }
38
+
39
+ declare module '*.svg' {
40
+ import * as React from 'react';
41
+
42
+ export const ReactComponent: React.FunctionComponent<
43
+ React.SVGProps<SVGSVGElement> & { title?: string }
44
+ >;
45
+
46
+ const src: string;
47
+ export default src;
48
+ }
@@ -0,0 +1,19 @@
1
+ declare module '*.css' {
2
+ const classes: { readonly [key: string]: string };
3
+ export default classes;
4
+ }
5
+
6
+ declare module '*.less' {
7
+ const classes: { readonly [key: string]: string };
8
+ export default classes;
9
+ }
10
+
11
+ declare module '*.scss' {
12
+ const classes: { readonly [key: string]: string };
13
+ export default classes;
14
+ }
15
+
16
+ declare module '*.sass' {
17
+ const classes: { readonly [key: string]: string };
18
+ export default classes;
19
+ }
@@ -0,0 +1,37 @@
1
+ compilerOptions:
2
+ # emittance
3
+ outDir: '{output}'
4
+ module: commonjs # node doesn't support anything non commonjs code yet
5
+ target: ES2017 # use ES2017 as it's the latest standard node 10 can be fully compatible with
6
+ declaration: true
7
+ sourceMap: true
8
+
9
+ # compatibility
10
+ allowSyntheticDefaultImports: true
11
+ esModuleInterop: true
12
+ experimentalDecorators: true
13
+ emitDecoratorMetadata: true
14
+ isolatedModules: false
15
+ jsx: react
16
+
17
+ # module resolution
18
+ moduleResolution: node
19
+ resolveJsonModule: true
20
+ baseUrl: .
21
+ paths:
22
+ '#*':
23
+ - '{source}/*'
24
+ '*':
25
+ - '{types}/*'
26
+
27
+ # libraries
28
+ lib:
29
+ - ES2020
30
+ - ESNext
31
+ - DOM
32
+ include:
33
+ - '**/*.json'
34
+ - '**/*.ts'
35
+ - '**/*.tsx'
36
+ exclude:
37
+ - '**/node_modules'