create-application-template 0.3.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/.babelrc ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "presets": [
3
+ "@babel/preset-env",
4
+ [
5
+ "@babel/preset-react",
6
+ {
7
+ "runtime": "automatic"
8
+ }
9
+ ],
10
+ "@babel/preset-typescript"
11
+ ],
12
+ "plugins": [
13
+ [
14
+ "@babel/plugin-transform-runtime",
15
+ {
16
+ "regenerator": true
17
+ },
18
+ "react-refresh/babel"
19
+ ]
20
+ ]
21
+ }
package/.eslintrc.js ADDED
@@ -0,0 +1,304 @@
1
+ const restrictedGlobals = require('confusing-browser-globals')
2
+
3
+ // NOTE use following to address: 'Parsing error: __classPrivateFieldGet(...).at is not a function error'
4
+ // '@typescript-eslint/eslint-plugin': '6.5.0',
5
+ // '@typescript-eslint/parser': '6.5.0',
6
+
7
+ module.exports = {
8
+ root: true,
9
+ parser: '@typescript-eslint/parser',
10
+ parserOptions: {
11
+ ecmaVersion: 2020,
12
+ sourceType: 'module',
13
+ },
14
+ settings: {
15
+ react: {
16
+ version: 'detect',
17
+ },
18
+ },
19
+ extends: [
20
+ 'plugin:react/recommended',
21
+ 'plugin:react-hooks/recommended',
22
+ 'plugin:@typescript-eslint/recommended',
23
+ 'plugin:import/errors',
24
+ 'plugin:import/warnings',
25
+ 'plugin:import/typescript',
26
+ 'plugin:jsx-a11y/recommended',
27
+ 'plugin:eslint-comments/recommended',
28
+ ],
29
+ rules: {
30
+ // 📜 @typescript-eslint
31
+ 'quotes': 'off',
32
+ '@typescript-eslint/quotes': ['error', 'single'],
33
+ 'no-dupe-class-members': 'off', // handled by .ts
34
+ 'no-undef': 'off', // handled by .ts
35
+ '@typescript-eslint/consistent-type-assertions': 'error',
36
+ 'no-array-constructor': 'off',
37
+ '@typescript-eslint/no-array-constructor': 'error',
38
+ 'no-var': 'error', // makes 'no-redeclare' irrelevant
39
+ // 'no-redeclare': 'off', // see above
40
+ // '@typescript-eslint/no-redeclare': 'error', // see above
41
+ 'no-use-before-define': 'off',
42
+ '@typescript-eslint/no-use-before-define': [
43
+ 'error',
44
+ {
45
+ 'functions': true,
46
+ 'classes': true,
47
+ 'variables': true,
48
+ 'allowNamedExports': true,
49
+ 'enums': true,
50
+ 'typedefs': true,
51
+ 'ignoreTypeReferences': true,
52
+ },
53
+ ],
54
+ 'no-unused-expressions': 'off',
55
+ '@typescript-eslint/no-unused-expressions': [
56
+ 'error',
57
+ {
58
+ 'allowShortCircuit': true,
59
+ 'allowTernary': true,
60
+ 'allowTaggedTemplates': true,
61
+ },
62
+ ],
63
+ 'no-unused-vars': 'off',
64
+ '@typescript-eslint/no-unused-vars': [
65
+ 'error',
66
+ {
67
+ 'ignoreRestSiblings': true,
68
+ },
69
+ ],
70
+ 'no-useless-constructor': 'off',
71
+ '@typescript-eslint/no-useless-constructor': 'error',
72
+ '@typescript-eslint/no-var-requires': 'off',
73
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
74
+
75
+ // 📜 eslint
76
+ 'array-callback-return': 'error',
77
+ 'default-case': 'error',
78
+ 'dot-location': ['error', 'property'],
79
+ 'eqeqeq': ['error', 'always'],
80
+ 'new-parens': 'error',
81
+ 'no-caller': 'error',
82
+ 'no-cond-assign': ['error', 'except-parens'],
83
+ 'no-const-assign': 'error',
84
+ 'no-control-regex': 'error',
85
+ 'no-delete-var': 'error',
86
+ 'no-dupe-args': 'error',
87
+ 'no-dupe-keys': 'error',
88
+ 'no-duplicate-case': 'error',
89
+ 'no-empty-character-class': 'error',
90
+ 'no-empty-pattern': 'error',
91
+ 'no-eval': 'error',
92
+ 'no-ex-assign': 'error',
93
+ 'no-extend-native': 'error',
94
+ 'no-extra-bind': 'error',
95
+ 'no-extra-label': 'error',
96
+ 'no-fallthrough': 'error',
97
+ 'no-func-assign': 'error',
98
+ 'no-implied-eval': 'error',
99
+ 'no-invalid-regexp': 'error',
100
+ 'no-iterator': 'error',
101
+ 'no-label-var': 'error',
102
+ 'no-labels': [
103
+ 'error',
104
+ {
105
+ 'allowLoop': true,
106
+ 'allowSwitch': false,
107
+ },
108
+ ],
109
+ 'no-lone-blocks': 'error',
110
+ 'no-loop-func': 'error',
111
+ 'no-mixed-operators': [
112
+ 'error',
113
+ {
114
+ 'groups': [
115
+ ['&', '|', '^', '~', '<<', '>>', '>>>'],
116
+ ['==', '!=', '===', '!==', '>', '>=', '<', '<='],
117
+ ['&&', '||'],
118
+ ['in', 'instanceof'],
119
+ ],
120
+ 'allowSamePrecedence': false,
121
+ },
122
+ ],
123
+ 'no-multi-str': 'error',
124
+ 'no-native-reassign': 'error',
125
+ 'no-negated-in-lhs': 'error',
126
+ 'no-new-func': 'error',
127
+ 'no-new-object': 'error',
128
+ 'no-new-symbol': 'error',
129
+ 'no-new-wrappers': 'error',
130
+ 'no-obj-calls': 'error',
131
+ 'no-octal': 'error',
132
+ 'no-octal-escape': 'error',
133
+ 'no-redeclare': 'error',
134
+ 'no-regex-spaces': 'error',
135
+ 'no-restricted-syntax': ['error', 'WithStatement'],
136
+ 'no-script-url': 'error',
137
+ 'no-self-assign': 'error',
138
+ 'no-self-compare': 'error',
139
+ 'no-sequences': 'error',
140
+ 'no-shadow-restricted-names': 'error',
141
+ 'no-sparse-arrays': 'error',
142
+ 'no-template-curly-in-string': 'error',
143
+ 'no-this-before-super': 'error',
144
+ 'no-throw-literal': 'error',
145
+ 'no-restricted-globals': ['error'].concat(restrictedGlobals),
146
+ 'no-unreachable': 'error',
147
+ 'no-unused-labels': 'error',
148
+ 'no-useless-computed-key': 'error',
149
+ 'no-useless-concat': 'error',
150
+ 'no-useless-escape': 'error',
151
+ 'no-useless-rename': [
152
+ 'error',
153
+ {
154
+ 'ignoreDestructuring': false,
155
+ 'ignoreImport': false,
156
+ 'ignoreExport': false,
157
+ },
158
+ ],
159
+ 'no-with': 'error',
160
+ 'no-whitespace-before-property': 'error',
161
+ 'react-hooks/exhaustive-deps': 'error',
162
+ 'require-yield': 'error',
163
+ 'rest-spread-spacing': ['error', 'never'],
164
+ 'strict': ['error', 'never'],
165
+ 'unicode-bom': ['error', 'never'],
166
+ 'use-isnan': 'error',
167
+ 'valid-typeof': 'error',
168
+ 'no-restricted-properties': [
169
+ 'error',
170
+ {
171
+ 'object': 'require',
172
+ 'property': 'ensure',
173
+ 'message': 'use import() instead',
174
+ },
175
+ {
176
+ 'object': 'System',
177
+ 'property': 'import',
178
+ 'message': 'use import() instead',
179
+ },
180
+ ],
181
+ 'getter-return': 'error',
182
+
183
+ // 📜 eslint, some additional styles
184
+ 'array-element-newline': ['error', 'consistent'],
185
+ 'comma-dangle': ['error', {
186
+ 'arrays': 'always-multiline',
187
+ 'objects': 'always-multiline',
188
+ 'imports': 'always-multiline',
189
+ 'exports': 'always-multiline',
190
+ // 'functions': 'never'
191
+ }],
192
+ 'semi': ['error', 'never'],
193
+ 'curly': ['error', 'multi-line'],
194
+ 'indent': [
195
+ 'error',
196
+ 2,
197
+ {
198
+ 'SwitchCase': 1,
199
+ },
200
+ ],
201
+ 'arrow-spacing': ['error'],
202
+ 'object-curly-spacing': ['error', 'always'],
203
+ 'array-bracket-spacing': ['error', 'never'],
204
+ 'no-irregular-whitespace': ['error'],
205
+ 'eol-last': ['error', 'always'],
206
+ 'no-trailing-spaces': [
207
+ 'error',
208
+ {
209
+ 'skipBlankLines': false,
210
+ 'ignoreComments': true,
211
+ },
212
+ ],
213
+ 'jsx-quotes': ['error', 'prefer-single'],
214
+
215
+ // 📜 import
216
+ 'import/first': 'error',
217
+ 'import/no-amd': 'error',
218
+ 'import/no-anonymous-default-export': 'error',
219
+ 'import/no-webpack-loader-syntax': 'error',
220
+
221
+ // 📜 react
222
+ 'react/prop-types': 'off',
223
+ 'react/jsx-uses-react': 'off',
224
+ 'react/react-in-jsx-scope': 'off',
225
+ 'react/forbid-foreign-prop-types': [
226
+ 'error',
227
+ {
228
+ 'allowInPropTypes': true,
229
+ },
230
+ ],
231
+ 'react/jsx-no-comment-textnodes': 'error',
232
+ 'react/jsx-no-duplicate-props': 'error',
233
+ 'react/jsx-no-target-blank': 'error',
234
+ 'react/jsx-no-undef': 'error',
235
+ 'react/jsx-pascal-case': [
236
+ 'error',
237
+ {
238
+ 'allowAllCaps': true,
239
+ 'ignore': [],
240
+ },
241
+ ],
242
+ 'react/no-danger-with-children': 'error',
243
+ // Disabled because of undesirable warnings
244
+ // 'react/no-deprecated': 'error',
245
+ 'react/no-direct-mutation-state': 'error',
246
+ 'react/no-is-mounted': 'error',
247
+ 'react/no-typos': 'error',
248
+ 'react/require-render-return': 'error',
249
+ 'react/style-prop-object': 'error',
250
+
251
+ // 📜 react, some additional styles
252
+ 'react/jsx-child-element-spacing': 'error',
253
+ 'react/jsx-closing-bracket-location': 'error',
254
+ 'react/jsx-closing-tag-location': 'error',
255
+ 'react/jsx-curly-newline': [
256
+ 'error',
257
+ {
258
+ 'multiline': 'consistent',
259
+ 'singleline': 'consistent',
260
+ },
261
+ ],
262
+ 'react/jsx-equals-spacing': ['error', 'never'],
263
+ 'react/jsx-indent': ['error', 2],
264
+ 'react/jsx-indent-props': ['error', 2],
265
+ 'react/jsx-props-no-multi-spaces': 'error',
266
+
267
+ // 📜 jsx-a11y
268
+ 'jsx-a11y/click-events-have-key-events': 'off', // could cause accidental clicks
269
+ 'jsx-a11y/alt-text': 'error',
270
+ 'jsx-a11y/anchor-has-content': 'error',
271
+ 'jsx-a11y/anchor-is-valid': [
272
+ 'error',
273
+ {
274
+ 'aspects': ['noHref', 'invalidHref'],
275
+ },
276
+ ],
277
+ 'jsx-a11y/aria-activedescendant-has-tabindex': 'error',
278
+ 'jsx-a11y/aria-props': 'error',
279
+ 'jsx-a11y/aria-proptypes': 'error',
280
+ 'jsx-a11y/aria-role': [
281
+ 'error',
282
+ {
283
+ 'ignoreNonDOM': true,
284
+ },
285
+ ],
286
+ 'jsx-a11y/aria-unsupported-elements': 'error',
287
+ 'jsx-a11y/heading-has-content': 'error',
288
+ 'jsx-a11y/iframe-has-title': 'error',
289
+ 'jsx-a11y/img-redundant-alt': 'error',
290
+ 'jsx-a11y/no-access-key': 'error',
291
+ 'jsx-a11y/no-distracting-elements': 'error',
292
+ 'jsx-a11y/no-redundant-roles': 'error',
293
+ 'jsx-a11y/role-has-required-aria-props': 'error',
294
+ 'jsx-a11y/role-supports-aria-props': 'error',
295
+ 'jsx-a11y/scope': 'error',
296
+
297
+ // 📜 react-hooks
298
+ 'react-hooks/rules-of-hooks': 'error',
299
+
300
+ // 'flowtype/define-flow-type': 'error',
301
+ // 'flowtype/require-valid-file-annotation': 'error',
302
+ // 'flowtype/use-flow-type': 'error',
303
+ },
304
+ }
@@ -0,0 +1,3 @@
1
+ npm run lint:fix
2
+ npm run stylelint:fix
3
+ npm run test
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ extends: [
3
+ 'stylelint-config-standard',
4
+ 'stylelint-config-recess-order',
5
+ ],
6
+ ignoreFiles: [],
7
+ rules: {
8
+ 'selector-class-pattern': null,
9
+ 'keyframes-name-pattern': null,
10
+ 'comment-empty-line-before': 'never',
11
+ 'declaration-empty-line-before': 'never',
12
+ },
13
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 daveKontro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ <img src='./src/assets/cat.svg' style='height: 300px; display: block; margin-left: auto; margin-right: auto;'>
2
+
3
+ # Create Application Template
4
+ Create Application Template aims to provide a configured application template for you to build upon.
5
+
6
+ All configuration is fully visable and under your control to augment as you see fit.
7
+
8
+ The template is a typescript enabled React application with a test suite and code linting.
9
+
10
+ ## installation
11
+ first install globally
12
+ ```
13
+ npm install -g create-application-template
14
+ ```
15
+
16
+ then create your project
17
+ ```
18
+ npx create-application-template --name={my-project}
19
+ ```
20
+
21
+ ## usage
22
+ webpack is used for code bundling and the development server
23
+
24
+ run development server and test suite
25
+ ```
26
+ npm run dev
27
+ ```
28
+
29
+ build static bundle
30
+ ```
31
+ npm run build
32
+ ```
33
+
34
+ ## tsconfig
35
+ focused on type checking; using babel for transpiling
36
+
37
+ ## pre-commit
38
+ scripts in `.husky/pre-commit` are run to check commits
39
+
40
+ add or remove scripts as you see fit
41
+
42
+ ## test suite
43
+ to create a test follow this file naming format: `*.{spec,test}.{ts,tsx}`
44
+
45
+ run the test suite stand alone like so
46
+ ```
47
+ npm run test
48
+ ```
49
+
50
+ ## code linting
51
+ linting rules are in `.eslintrc.js`, install the ESLint pluggin if using vscode
52
+ ```
53
+ npm run lint
54
+ ```
55
+
56
+ css linting rules are in `.stylelintrc.js`, install the Stylelint pluggin if using vscode
57
+ ```
58
+ npm run stylelint
59
+ ```
60
+
61
+ ## environmental settings
62
+ access environmental variables in code like so
63
+ ```
64
+ console.log(process.env.PORT)
65
+ ```
66
+
67
+ ### `NODE_ENV` settings
68
+ set to `production` for build
69
+
70
+ set to `develop` for dev server
71
+
72
+ ### `.env` variables
73
+ add new environmental variables via the `.env` file in project
74
+
75
+ the following variables exist in the current configuration and can be altered
76
+
77
+ #### develop (dev server)
78
+ ```
79
+ # optional
80
+ PORT={port number}
81
+ INLINE_SIZE_LIMIT={default is 10000}
82
+ ```
83
+
84
+ #### production (build)
85
+ ```
86
+ # optional
87
+ INLINE_SIZE_LIMIT={default is 10000}
88
+ ```
@@ -0,0 +1,75 @@
1
+ #! /usr/bin/env node
2
+ const { writeFile } = require('fs/promises')
3
+ const { execSync } = require('child_process')
4
+ const yargs = require('yargs/yargs')
5
+ const { hideBin } = require('yargs/helpers')
6
+ const packageJson = require('../package.json')
7
+
8
+ const run = async () => {
9
+ const repo = 'https://github.com/daveKontro/create-application-template/tarball/main'
10
+
11
+ const execCommand = (command) => {
12
+ try {
13
+ execSync(command, { stdio: 'inherit' })
14
+ } catch (error) {
15
+ console.error(`${command} failed`, error)
16
+ process.exit(1)
17
+ }
18
+
19
+ return true
20
+ }
21
+
22
+ // consume arguments
23
+ const argv = yargs(hideBin(process.argv)).argv
24
+
25
+ if (!argv.name) {
26
+ console.error('WARNING add a project name like so: npx create-application-template --name={my-project}')
27
+ process.exit(1)
28
+ } else {
29
+ console.info('')
30
+ console.info(`Your project name is: ${argv.name}`)
31
+ console.info('')
32
+ }
33
+
34
+ const projectPaths = {
35
+ root: `./${argv.name}`,
36
+ get env() { return `${this.root}/.env` },
37
+ get packageJson() { return `${this.root}/package.json` },
38
+ }
39
+
40
+ // create project
41
+ execCommand(`curl -L ${repo} | tar zx --one-top-level=${argv.name} --strip-components 1`)
42
+
43
+ // groom project
44
+ if (packageJson.hasOwnProperty('name')) packageJson.name = argv.name
45
+ if (packageJson.hasOwnProperty('version')) packageJson.version = '1.0.0'
46
+ if (packageJson.hasOwnProperty('description')) packageJson.description = ''
47
+ if (packageJson.hasOwnProperty('author')) packageJson.author = ''
48
+ if (packageJson.hasOwnProperty('bin')) delete packageJson.bin
49
+ if (packageJson.hasOwnProperty('repository')) delete packageJson.repository
50
+ if (packageJson.dependencies.hasOwnProperty('yargs')) delete packageJson.dependencies.yargs
51
+
52
+ execCommand(`rm ${projectPaths.packageJson}`)
53
+
54
+ try {
55
+ await writeFile(projectPaths.packageJson, JSON.stringify(packageJson, null, 2), {
56
+ encoding: 'utf8',
57
+ })
58
+ } catch (error) {
59
+ console.error('package.json creation failed', error)
60
+ process.exit(1)
61
+ }
62
+
63
+ execCommand(`touch ${projectPaths.env}`)
64
+
65
+ // install project dependencies
66
+ execCommand(`npm --prefix ${projectPaths.root} install`)
67
+
68
+ // finish up
69
+ console.info('')
70
+ console.info('Thanks for using Create Application Template!')
71
+
72
+ process.exit(0)
73
+ }
74
+
75
+ run()
@@ -0,0 +1,13 @@
1
+ // turning style imports into empty objects
2
+ // https://jestjs.io/docs/code-transformation
3
+
4
+ module.exports = {
5
+ process() {
6
+ return {
7
+ code: 'module.exports = {}',
8
+ }
9
+ },
10
+ getCacheKey() {
11
+ return 'cssTransform'
12
+ },
13
+ }
package/jest/setup.js ADDED
@@ -0,0 +1,5 @@
1
+ // make a browser-like environment
2
+
3
+ if (typeof window !== 'undefined') {
4
+ require('whatwg-fetch') // fetch() polyfill
5
+ }
@@ -0,0 +1,15 @@
1
+ require('dotenv-flow').config()
2
+
3
+ // additional jest matchers
4
+ // https://jest-extended.jestcommunity.dev/docs/matchers
5
+ const matchers = require('jest-extended')
6
+ expect.extend(matchers)
7
+
8
+ // custom jest matchers for asserting on DOM nodes
9
+ // https://www.npmjs.com/package/@testing-library/jest-dom
10
+ require('@testing-library/jest-dom')
11
+ // require('@testing-library/jest-dom/jest-globals')
12
+
13
+ afterEach(() => {
14
+ jest.useRealTimers()
15
+ })
@@ -0,0 +1,12 @@
1
+ // turning svg imports into empty objects
2
+
3
+ module.exports = {
4
+ process() {
5
+ return {
6
+ code: 'module.exports = {}',
7
+ }
8
+ },
9
+ getCacheKey() {
10
+ return 'svgTransform'
11
+ },
12
+ }
package/jest.config.js ADDED
@@ -0,0 +1,50 @@
1
+ /** @returns {Promise<import('jest').Config>} */
2
+ module.exports = async () => {
3
+ return {
4
+ rootDir: __dirname,
5
+ roots: [
6
+ '<rootDir>/src',
7
+ ],
8
+ automock: false,
9
+ collectCoverage: true,
10
+ collectCoverageFrom: [
11
+ 'src/**/*.{js,jsx,ts,tsx}',
12
+ '!**/node_modules/**',
13
+ 'src/**/*.d.ts',
14
+ ],
15
+ coverageDirectory: '<rootDir>/jest/coverage',
16
+ coverageThreshold: undefined,
17
+ displayName: 'UI',
18
+ globals: {},
19
+ maxConcurrency: 5, // 5 is default (see test.concurrent)
20
+ moduleNameMapper: {
21
+ '^.+\\.module\\.(css)$': 'identity-obj-proxy',
22
+ },
23
+ resetMocks: true,
24
+ setupFiles: [
25
+ '<rootDir>/jest/setup.js',
26
+ ],
27
+ setupFilesAfterEnv: [
28
+ '<rootDir>/jest/setupTests.js',
29
+ ],
30
+ testMatch: [
31
+ '<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}',
32
+ ],
33
+ testEnvironment: 'jsdom',
34
+ transform: {
35
+ // https://babeljs.io/docs/config-files#jest
36
+ '^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': 'babel-jest',
37
+ '^.+\\.css$': '<rootDir>/jest/cssTransform.js',
38
+ '^.+\\.svg$': '<rootDir>/jest/svgTransform.js',
39
+ },
40
+ // transformIgnorePatterns: [
41
+ // '[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$',
42
+ // '^.+\\.module\\.(css|sass|scss)$',
43
+ // ],
44
+ verbose: true,
45
+ watchPlugins: [
46
+ 'jest-watch-typeahead/filename',
47
+ 'jest-watch-typeahead/testname',
48
+ ],
49
+ }
50
+ }