-
-
Notifications
You must be signed in to change notification settings - Fork 151
/
make-example
executable file
·152 lines (135 loc) · 3.43 KB
/
make-example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
readonly MODULE="examples/$1"
readonly AUTHOR="Karsten Schmidt"
readonly EMAIL="k+npm@thi.ng"
echo "generating module: $MODULE"
mkdir -p "$MODULE"
echo "creating /src folder..."
mkdir -p "$MODULE"/src
cat << EOF > "$MODULE"/src/index.ts
import { } from "@thi.ng/hdom";
if (process.env.NODE_ENV !== "production") {
const hot = (<any>module).hot;
hot && hot.dispose(() => {});
}
EOF
cat << EOF > "$MODULE"/src/webpack.d.ts
declare module "*.jpg";
declare module "*.png";
declare module "*.svg";
declare module "*.json";
EOF
echo "writing package.json..."
cat << EOF > "$MODULE"/package.json
{
"name": "$1",
"version": "0.0.1",
"description": "TODO",
"repository": "https://github.com/thi-ng/umbrella",
"author": "$AUTHOR <$EMAIL>",
"license": "Apache-2.0",
"scripts": {
"clean": "rm -rf .cache build out",
"build": "yarn clean && parcel build index.html -d out --public-url ./ --no-source-maps --no-cache --detailed-report --experimental-scope-hoisting",
"build:webpack": "../../node_modules/.bin/webpack --mode production",
"start": "parcel index.html -p 8080 --open"
},
"devDependencies": {
"parcel-bundler": "^1.12.4",
"terser": "^4.6.13",
"typescript": "^3.9.2"
},
"dependencies": {
"@thi.ng/api": "latest"
},
"browserslist": [
"last 3 Chrome versions"
],
"browser": {
"process": false
},
"thi.ng": {
}
}
EOF
echo "writing tsconfig.json..."
cat << EOF > "$MODULE"/tsconfig.json
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": ".",
"target": "es6",
"sourceMap": true
},
"include": [
"./src/**/*.ts"
]
}
EOF
echo "writing .gitignore..."
cat << EOF > "$MODULE"/.gitignore
.cache
out
node_modules
yarn.lock
*.js
*.map
!src/*.d.ts
!*.config.js
EOF
echo "writing index.html..."
cat << EOF > "$MODULE"/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>$1</title>
<link href="https://unpkg.com/tachyons@4/css/tachyons.min.css" rel="stylesheet">
<style>
</style>
</head>
<body class="sans-serif">
<div id="app"></div>
<div><a class="link" href="https://github.com/thi-ng/umbrella/tree/develop/examples/$1">Source code</a></div>
<script type="text/javascript" src="./src/index.ts"></script>
</body>
</html>
EOF
echo "writing README.md..."
cat << EOF > "$MODULE"/README.md
# $1
[Live demo](http://demo.thi.ng/umbrella/$1/)
Please refer to the [example build instructions](https://github.com/thi-ng/umbrella/wiki/Example-build-instructions) on the wiki.
## Authors
- $AUTHOR
## License
© 2020 $AUTHOR // Apache Software License 2.0
EOF
echo "writing webpack.config.js..."
cat << EOF > "$MODULE"/webpack.config.js
module.exports = {
entry: "./src/index.ts",
output: {
filename: "bundle.[hash].js",
path: __dirname + "/out"
},
resolve: {
extensions: [".ts", ".js"]
},
module: {
rules: [
{
test: /\.(png|jpg|gif)$/,
loader: "file-loader",
options: { name: "[path][hash].[ext]" }
},
{ test: /\.ts$/, use: "ts-loader" }
]
},
node: {
process: false
}
};
EOF