Skip to content

Commit 3218601

Browse files
committed
init
0 parents  commit 3218601

19 files changed

+5188
-0
lines changed

.editorconfig

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.php]
12+
indent_style = tab
13+
indent_size = 4
14+
15+
[*.py]
16+
charset = utf-8
17+
indent_style = space
18+
indent_size = 4
19+
end_of_line = lf
20+
insert_final_newline = true
21+
trim_trailing_whitespace = true
22+
23+
[Makefile]
24+
indent_style = tab
25+
indent_size = 4
26+
27+
[*.sln]
28+
indent_style = tab
29+
30+
[*.{md,mdx}]
31+
trim_trailing_whitespace = false

.eslintignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.config.js
2+
*.config.ts
3+
*.test.js
4+
*.test.ts
5+
cjs
6+
esm
7+
umd
8+
dist
9+
types

.eslintrc.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
extends: ['plugin:@typescript-eslint/recommended', 'prettier'],
4+
parserOptions: {
5+
sourceType: 'module',
6+
},
7+
rules: {
8+
'prettier/prettier': 'error',
9+
},
10+
plugins: ['@typescript-eslint', 'prettier'],
11+
}

.gitignore

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
cjs
2+
esm
3+
umd
4+
# dist
5+
types
6+
7+
8+
# Logs
9+
logs
10+
*.log
11+
npm-debug.log*
12+
yarn-debug.log*
13+
yarn-error.log*
14+
lerna-debug.log*
15+
16+
# Diagnostic reports (https://nodejs.org/api/report.html)
17+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
18+
19+
# Runtime data
20+
pids
21+
*.pid
22+
*.seed
23+
*.pid.lock
24+
25+
# Directory for instrumented libs generated by jscoverage/JSCover
26+
lib-cov
27+
28+
# Coverage directory used by tools like istanbul
29+
coverage
30+
*.lcov
31+
32+
# nyc test coverage
33+
.nyc_output
34+
35+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
36+
.grunt
37+
38+
# Bower dependency directory (https://bower.io/)
39+
bower_components
40+
41+
# node-waf configuration
42+
.lock-wscript
43+
44+
# Compiled binary addons (https://nodejs.org/api/addons.html)
45+
build/Release
46+
47+
# Dependency directories
48+
node_modules/
49+
jspm_packages/
50+
51+
# Snowpack dependency directory (https://snowpack.dev/)
52+
web_modules/
53+
54+
# TypeScript cache
55+
*.tsbuildinfo
56+
57+
# Optional npm cache directory
58+
.npm
59+
60+
# Optional eslint cache
61+
.eslintcache
62+
63+
# Microbundle cache
64+
.rpt2_cache/
65+
.rts2_cache_cjs/
66+
.rts2_cache_es/
67+
.rts2_cache_umd/
68+
69+
# Optional REPL history
70+
.node_repl_history
71+
72+
# Output of 'npm pack'
73+
*.tgz
74+
75+
# Yarn Integrity file
76+
.yarn-integrity
77+
78+
# dotenv environment variables file
79+
.env
80+
.env.test
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# Serverless directories
104+
.serverless/
105+
106+
# FuseBox cache
107+
.fusebox/
108+
109+
# DynamoDB Local files
110+
.dynamodb/
111+
112+
# TernJS port file
113+
.tern-port
114+
115+
# Stores VSCode versions used for testing VSCode extensions
116+
.vscode-test
117+
118+
# yarn v2
119+
.yarn/cache
120+
.yarn/unplugged
121+
.yarn/build-state.yml
122+
.yarn/install-state.gz
123+
.pnp.*

.prettierrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
semi: false,
3+
singleQuote: true,
4+
trailingComma: 'es5',
5+
arrowParens: 'always',
6+
printWidth: 80,
7+
}

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Example TypeScript Package ready to be published on npm
2+
3+
Example TypeScript Package ready to be published on npm.
4+
5+
It generates CommonJS (in **cjs** folder), ES Modules (in **esm** folder), bundled and minified UMD (in **umd** folder), as well as TypeScript declaration files (in **types** folder).
6+
7+
It uses yarn, TypeScript compiler, jest, webpack, eslint, prettier, and primarily designed to be used with VS Code.
8+
9+
## Development
10+
11+
```bash
12+
yarn
13+
yarn build
14+
```
15+
16+
## Notes
17+
18+
* It uses yarn but you can easily switch to npm, of course (remember to change `scripts`.`build` in **package.json**)
19+
* Whether you use npm as your package manager ≠ Whether you can publish to the npm registry
20+
21+
* Works fine in VS Code. Consider installing VS Code extensions [ES Lint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode). In my configuration **.eslintrc** and **.prettierrc** cooperate perfectly
22+
* You probably already know that: the shortcuts for formatting of a code file are <kbd>Shift</kbd> + <kbd>Alt</kbd> + <kbd>F</kbd> (Windows); <kbd>Shift</kbd> + <kbd>Option (Alt)</kbd> + <kbd>F</kbd> (MacOS); <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>I</kbd> (Linux)
23+
24+
* See `scripts`.`build` in **package.json** for other predefined script commands

cleanup.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* eslint-disable */
2+
const fs = require('fs')
3+
const Path = require('path')
4+
/* eslint-enable */
5+
6+
const deleteFolderRecursive = (path) => {
7+
if (fs.existsSync(path)) {
8+
fs.readdirSync(path).forEach((file) => {
9+
const curPath = Path.join(path, file)
10+
if (fs.lstatSync(curPath).isDirectory()) {
11+
deleteFolderRecursive(curPath)
12+
} else {
13+
fs.unlinkSync(curPath)
14+
}
15+
})
16+
fs.rmdirSync(path)
17+
}
18+
}
19+
20+
const folder = process.argv.slice(2)[0]
21+
22+
if (folder) {
23+
deleteFolderRecursive(folder)
24+
} else {
25+
deleteFolderRecursive('cjs')
26+
deleteFolderRecursive('esm')
27+
deleteFolderRecursive('umd')
28+
deleteFolderRecursive('types')
29+
}

config/tsconfig.base.json

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"compilerOptions": {
3+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
4+
5+
/* Basic Options */
6+
// "incremental": true, /* Enable incremental compilation */
7+
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
8+
// "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9+
// "lib": [], /* Specify library files to be included in the compilation. */
10+
// "allowJs": true, /* Allow javascript files to be compiled. */
11+
// "checkJs": true, /* Report errors in .js files. */
12+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
14+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15+
// "sourceMap": true, /* Generates corresponding '.map' file. */
16+
// "outFile": "./", /* Concatenate and emit output to single file. */
17+
// "outDir": "./", /* Redirect output structure to the directory. */
18+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
19+
// "composite": true, /* Enable project compilation */
20+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
21+
// "removeComments": true, /* Do not emit comments to output. */
22+
// "noEmit": true, /* Do not emit outputs. */
23+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
24+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
25+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
26+
27+
/* Strict Type-Checking Options */
28+
"strict": true /* Enable all strict type-checking options. */,
29+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
30+
// "strictNullChecks": true, /* Enable strict null checks. */
31+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
32+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
33+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
34+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
35+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
36+
37+
/* Additional Checks */
38+
// "noUnusedLocals": true, /* Report errors on unused locals. */
39+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
40+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
41+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
42+
43+
/* Module Resolution Options */
44+
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
45+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
46+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
47+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
48+
// "typeRoots": [], /* List of folders to include type definitions from. */
49+
// "types": [], /* Type declaration files to be included in compilation. */
50+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
51+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
52+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
53+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
54+
55+
/* Source Map Options */
56+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
57+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
58+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
59+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
60+
61+
/* Experimental Options */
62+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
63+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
64+
65+
/* Advanced Options */
66+
// "skipLibCheck": true, /* Skip type checking of declaration files. */
67+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
68+
},
69+
"include": ["../src/**/*"]
70+
}

config/tsconfig.cjs.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.base",
3+
"compilerOptions": {
4+
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
5+
"outDir": "../cjs" /* Redirect output structure to the directory. */
6+
}
7+
}

config/tsconfig.esm.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.base",
3+
"compilerOptions": {
4+
"module": "ESNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
5+
"outDir": "../esm" /* Redirect output structure to the directory. */
6+
}
7+
}

config/tsconfig.types.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.base",
3+
"compilerOptions": {
4+
"declaration": true /* Generates corresponding '.d.ts' file. */,
5+
"emitDeclarationOnly": true,
6+
"outDir": "../types" /* Redirect output structure to the directory. */
7+
}
8+
}

config/tsconfig.umd.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.base",
3+
"compilerOptions": {
4+
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
5+
// "outDir": "../dist" /* Redirect output structure to the directory. */,
6+
"declaration": false /* Generates corresponding '.d.ts' file. */
7+
}
8+
}

config/webpack.config.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const path = require('path')
2+
3+
module.exports = {
4+
mode: 'production',
5+
entry: './src/index.ts',
6+
output: {
7+
path: path.resolve(__dirname, '../umd'),
8+
filename: 'index.js',
9+
library: 'exampleTypescriptPackage',
10+
libraryTarget: 'umd',
11+
},
12+
module: {
13+
rules: [
14+
{
15+
test: /\.ts(x*)?$/,
16+
exclude: /node_modules/,
17+
use: {
18+
loader: 'ts-loader',
19+
options: {
20+
configFile: 'config/tsconfig.umd.json',
21+
},
22+
},
23+
},
24+
],
25+
},
26+
resolve: {
27+
extensions: ['.ts', '.js'],
28+
},
29+
}

jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
roots: ['<rootDir>/test'],
3+
testMatch: [
4+
'**/__tests__/**/*.+(ts|tsx|js)',
5+
'**/?(*.)+(spec|test).+(ts|tsx|js)',
6+
],
7+
transform: {
8+
'^.+\\.(ts|tsx)$': 'ts-jest',
9+
},
10+
}

0 commit comments

Comments
 (0)