nitro-web 0.0.1

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.
Files changed (152) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintrc.json +86 -0
  3. package/_example/.env-example +16 -0
  4. package/_example/client/config.ts +5 -0
  5. package/_example/client/css/index.css +35 -0
  6. package/_example/client/fonts/Roboto-Bold.ttf +0 -0
  7. package/_example/client/fonts/Roboto-BoldItalic.ttf +0 -0
  8. package/_example/client/fonts/Roboto-Italic.ttf +0 -0
  9. package/_example/client/fonts/Roboto-Medium.ttf +0 -0
  10. package/_example/client/fonts/Roboto-MediumItalic.ttf +0 -0
  11. package/_example/client/fonts/Roboto-Regular.ttf +0 -0
  12. package/_example/client/fonts/inter-v13-latin-300.woff2 +0 -0
  13. package/_example/client/fonts/inter-v13-latin-500.woff2 +0 -0
  14. package/_example/client/fonts/inter-v13-latin-600.woff2 +0 -0
  15. package/_example/client/fonts/inter-v13-latin-700.woff2 +0 -0
  16. package/_example/client/fonts/inter-v13-latin-800.woff2 +0 -0
  17. package/_example/client/fonts/inter-v13-latin-900.woff2 +0 -0
  18. package/_example/client/fonts/inter-v13-latin-regular.woff2 +0 -0
  19. package/_example/client/imgs/android-chrome-512x512.png +0 -0
  20. package/_example/client/imgs/favicon.png +0 -0
  21. package/_example/client/imgs/icons/calendar.svg +3 -0
  22. package/_example/client/imgs/icons/email.svg +6 -0
  23. package/_example/client/imgs/icons/eye-open.svg +4 -0
  24. package/_example/client/imgs/icons/eye.svg +5 -0
  25. package/_example/client/imgs/icons/filter.svg +7 -0
  26. package/_example/client/imgs/icons/left-circle.svg +3 -0
  27. package/_example/client/imgs/icons/left.svg +3 -0
  28. package/_example/client/imgs/icons/line-options.svg +5 -0
  29. package/_example/client/imgs/icons/line.svg +3 -0
  30. package/_example/client/imgs/icons/person.svg +7 -0
  31. package/_example/client/imgs/icons/plus-circle.svg +5 -0
  32. package/_example/client/imgs/icons/plus.svg +5 -0
  33. package/_example/client/imgs/icons/right-circle.svg +3 -0
  34. package/_example/client/imgs/icons/right.svg +3 -0
  35. package/_example/client/imgs/icons/search.svg +3 -0
  36. package/_example/client/imgs/icons/shield.svg +6 -0
  37. package/_example/client/imgs/icons/tick-circle-solid.svg +8 -0
  38. package/_example/client/imgs/icons/tick-circle.svg +6 -0
  39. package/_example/client/imgs/icons/tick.svg +5 -0
  40. package/_example/client/imgs/icons/up2-small.svg +4 -0
  41. package/_example/client/imgs/icons/up2.svg +4 -0
  42. package/_example/client/imgs/icons/updown.svg +6 -0
  43. package/_example/client/imgs/icons/v-big-dark.svg +3 -0
  44. package/_example/client/imgs/icons/v-dark.svg +3 -0
  45. package/_example/client/imgs/icons/v.svg +3 -0
  46. package/_example/client/imgs/icons/v2-active.svg +6 -0
  47. package/_example/client/imgs/icons/x1.svg +4 -0
  48. package/_example/client/imgs/logo/logo-white.svg +20 -0
  49. package/_example/client/imgs/logo/logo.svg +20 -0
  50. package/_example/client/imgs/no-image.jpg +0 -0
  51. package/_example/client/imgs/user.jpg +0 -0
  52. package/_example/client/index.html +12 -0
  53. package/_example/client/index.ts +47 -0
  54. package/_example/components/auth.api.js +1 -0
  55. package/_example/components/index.tsx +225 -0
  56. package/_example/components/partials/layouts.tsx +5 -0
  57. package/_example/components/settings.api.js +1 -0
  58. package/_example/server/config.js +120 -0
  59. package/_example/server/email/welcome.html +27 -0
  60. package/_example/server/index.js +32 -0
  61. package/_example/tailwind.config.js +84 -0
  62. package/_example/tsconfig.json +32 -0
  63. package/_example/types.d.ts +7 -0
  64. package/_example/webpack.config.js +4 -0
  65. package/client/app.js +300 -0
  66. package/client/css/components.css +84 -0
  67. package/client/css/fonts.css +67 -0
  68. package/client/imgs/icons/calendar.svg +3 -0
  69. package/client/imgs/icons/email.svg +6 -0
  70. package/client/imgs/icons/eye-open.svg +4 -0
  71. package/client/imgs/icons/eye.svg +5 -0
  72. package/client/imgs/icons/filter.svg +7 -0
  73. package/client/imgs/icons/left-circle.svg +3 -0
  74. package/client/imgs/icons/left.svg +3 -0
  75. package/client/imgs/icons/line-options.svg +5 -0
  76. package/client/imgs/icons/line.svg +3 -0
  77. package/client/imgs/icons/person.svg +7 -0
  78. package/client/imgs/icons/plus-circle.svg +5 -0
  79. package/client/imgs/icons/plus.svg +5 -0
  80. package/client/imgs/icons/right-circle.svg +3 -0
  81. package/client/imgs/icons/right.svg +3 -0
  82. package/client/imgs/icons/search.svg +3 -0
  83. package/client/imgs/icons/shield.svg +6 -0
  84. package/client/imgs/icons/tick-circle-solid.svg +8 -0
  85. package/client/imgs/icons/tick-circle.svg +6 -0
  86. package/client/imgs/icons/tick.svg +5 -0
  87. package/client/imgs/icons/up2-small.svg +4 -0
  88. package/client/imgs/icons/up2.svg +4 -0
  89. package/client/imgs/icons/updown.svg +6 -0
  90. package/client/imgs/icons/v-big-dark.svg +3 -0
  91. package/client/imgs/icons/v-dark.svg +3 -0
  92. package/client/imgs/icons/v.svg +3 -0
  93. package/client/imgs/icons/v2-active.svg +6 -0
  94. package/client/imgs/icons/x1.svg +4 -0
  95. package/client.js +42 -0
  96. package/components/auth/auth.api.js +419 -0
  97. package/components/auth/reset.jsx +88 -0
  98. package/components/auth/signin.jsx +74 -0
  99. package/components/auth/signup.jsx +62 -0
  100. package/components/billing/stripe.api.js +267 -0
  101. package/components/partials/element/accordion.jsx +82 -0
  102. package/components/partials/element/avatar.jsx +28 -0
  103. package/components/partials/element/button.jsx +66 -0
  104. package/components/partials/element/dropdown.jsx +185 -0
  105. package/components/partials/element/initials.jsx +56 -0
  106. package/components/partials/element/message.jsx +124 -0
  107. package/components/partials/element/modal.jsx +229 -0
  108. package/components/partials/element/sidebar.jsx +166 -0
  109. package/components/partials/element/tooltip.jsx +146 -0
  110. package/components/partials/element/topbar.jsx +25 -0
  111. package/components/partials/form/checkbox.jsx +74 -0
  112. package/components/partials/form/drop-handler.jsx +62 -0
  113. package/components/partials/form/drop.jsx +125 -0
  114. package/components/partials/form/form-error.jsx +21 -0
  115. package/components/partials/form/input-color.jsx +77 -0
  116. package/components/partials/form/input-currency.jsx +133 -0
  117. package/components/partials/form/input-date.jsx +223 -0
  118. package/components/partials/form/input.jsx +131 -0
  119. package/components/partials/form/location.jsx +212 -0
  120. package/components/partials/form/select.jsx +369 -0
  121. package/components/partials/form/toggle.jsx +46 -0
  122. package/components/partials/is-first-render.js +15 -0
  123. package/components/partials/layout/layout1.jsx +32 -0
  124. package/components/partials/layout/layout2.jsx +47 -0
  125. package/components/partials/not-found.jsx +7 -0
  126. package/components/partials/styleguide.jsx +252 -0
  127. package/components/settings/settings-account.jsx +143 -0
  128. package/components/settings/settings-business.jsx +121 -0
  129. package/components/settings/settings-team--member.jsx +108 -0
  130. package/components/settings/settings-team.jsx +76 -0
  131. package/components/settings/settings.api.js +54 -0
  132. package/package.json +175 -0
  133. package/readme.md +43 -0
  134. package/server/email/index.js +192 -0
  135. package/server/email/partials/email.css +153 -0
  136. package/server/email/partials/layout1.swig +92 -0
  137. package/server/email/partials/line.swig +8 -0
  138. package/server/email/partials/vert-10.swig +8 -0
  139. package/server/email/partials/vert-15.swig +8 -0
  140. package/server/email/partials/vert-20.swig +8 -0
  141. package/server/email/partials/vert-25.swig +8 -0
  142. package/server/email/partials/vert-30.swig +8 -0
  143. package/server/email/partials/vert-35.swig +8 -0
  144. package/server/email/partials/vert-50.swig +8 -0
  145. package/server/email/reset-password.html +21 -0
  146. package/server/email/welcome.html +21 -0
  147. package/server/models/company.js +76 -0
  148. package/server/models/user.js +45 -0
  149. package/server/router.js +355 -0
  150. package/server.js +20 -0
  151. package/util.js +1145 -0
  152. package/webpack.config.js +302 -0
@@ -0,0 +1,302 @@
1
+ import axios from '@hokify/axios'
2
+ import axiosRetry from 'axios-retry'
3
+ import autoprefixer from 'autoprefixer'
4
+ import CleanTerminalPlugin from 'clean-terminal-webpack-plugin'
5
+ import CopyWebpackPlugin from 'copy-webpack-plugin'
6
+ import HtmlWebpackPlugin from 'html-webpack-plugin'
7
+ import MiniCssExtractPlugin from 'mini-css-extract-plugin'
8
+ import webpackNodeExternals from 'webpack-node-externals'
9
+ import path from 'path'
10
+ import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'
11
+ import tailwindcss from 'tailwindcss'
12
+ import webpack from 'webpack'
13
+ import ESLintPlugin from 'eslint-webpack-plugin'
14
+ import postcssImport from 'postcss-import'
15
+ import postcssNested from 'postcss-nested'
16
+ import postcssFor from 'postcss-for'
17
+ import { createRequire } from 'module'
18
+ import postcssImportResolver from 'postcss-import-resolver'
19
+ const _require = createRequire(import.meta.url)
20
+
21
+ export function getWebpackConfig(config) {
22
+ // Configurables
23
+ const { clientDir, componentsDir, distDir, isNitro, nitroDir } = config
24
+ const imgsDir = path.join(clientDir, 'imgs/')
25
+ const fontsDir = path.join(clientDir, 'fonts/')
26
+ const build = process.env.NODE_ENV == 'production'
27
+
28
+ const pick = (object, list) => list.reduce((o, e) => ((o[e] = object[e]), o), {})
29
+
30
+ axiosRetry(axios, {
31
+ retries: 10,
32
+ retryDelay: () => 150,
33
+ retryCondition: (e) => e.code == 'ECONNREFUSED',
34
+ })
35
+
36
+ // process.traceDeprecation = true
37
+ // eslint-disable-next-line
38
+ return (env, argv) => [{
39
+ devtool: build ? false : 'source-map',
40
+ entry: clientDir + 'index.ts',
41
+ // entry: build ? './client/index.tsx' : ['webpack-plugin-serve/client', './client/index.tsx'], // check this
42
+ mode: build ? 'production' : 'development',
43
+ // target=node ignores node_modules
44
+ externals: argv.target?.[0] == 'node' ? [webpackNodeExternals()] : [],
45
+ // target=node ignores builtin modules
46
+ target: argv.target?.[0] || 'web',
47
+ devServer: {
48
+ // needed when connecting to the devserver through a domain
49
+ allowedHosts: 'all',
50
+ client: {
51
+ logging: 'warn', // 'info'
52
+ overlay: true,
53
+ },
54
+ compress: false,
55
+ devMiddleware: {
56
+ writeToDisk: false,
57
+ },
58
+ historyApiFallback: true,
59
+ host: '0.0.0.0',
60
+ hot: true,
61
+ port: 3000,
62
+ proxy: {
63
+ '/api': {
64
+ logLevel: 'silent',
65
+ target: 'http://0.0.0.0:3001',
66
+ // bypass: async function (req, res, proxyOptions) {
67
+ // // // wait for pong, indicating express has restarted
68
+ // // // all non-asset routes are triggered (even the main page)
69
+ // // // another method: https://codeburst.io/dont-use-nodemon-there-are-better-ways-fc016b50b45e
70
+ // // if (!req.url.match(/^\/api\//)) return
71
+ // // await axios.get('http://0.0.0.0:3001/ping')
72
+ // },
73
+ },
74
+ '/server/email/templates': {
75
+ logLevel: 'silent',
76
+ target: 'http://0.0.0.0:3001',
77
+ },
78
+ },
79
+ },
80
+ infrastructureLogging: {
81
+ level: 'info',
82
+ // debug: [(name) => !name.match(/webpack-dev-server/)],
83
+ // console: (a, b, c) => { // webpack v5.3.1
84
+ // console.log(1, a, b, c)
85
+ // },
86
+ },
87
+ module: {
88
+ rules: [
89
+ {
90
+ test: /\.css$/,
91
+ use: [
92
+ { loader: MiniCssExtractPlugin.loader },
93
+ { loader: 'css-loader', options: { sourceMap: true } },
94
+ { loader: 'postcss-loader', options: {
95
+ postcssOptions: {
96
+ plugins: [
97
+ !isNitro ? postcssImport : postcssImport({
98
+ resolve: postcssImportResolver({
99
+ alias: {
100
+ 'nitro-web/client/css/components.css': path.resolve(nitroDir, 'client/css/components.css'),
101
+ 'nitro-web/client/css/fonts.css': path.resolve(nitroDir, 'client/css/fonts.css'),
102
+ },
103
+ }),
104
+ }),
105
+ postcssNested,
106
+ postcssFor,
107
+ tailwindcss({ config: `./${isNitro ? '_example/' : ''}tailwind.config.js` }),
108
+ autoprefixer,
109
+ ],
110
+ },
111
+ sourceMap: true,
112
+ }},
113
+ ],
114
+ },
115
+ {
116
+ test: /\.(m?js|jsx|ts|tsx)$/,
117
+ exclude: (
118
+ (path) => {
119
+ // Dont transpile node modules except for date-fns, which uses ES6
120
+ return path.includes('node_modules')
121
+ && !path.includes('node_modules/date-fns')
122
+ }
123
+ ),
124
+ use: [
125
+ {
126
+ loader: 'babel-loader',
127
+ options: {
128
+ presets: [
129
+ ['@babel/preset-env', { debug: false }],
130
+ ['@babel/preset-react', { runtime: 'automatic', importSource: '@emotion/react' }],
131
+ ['@babel/preset-typescript', { allowNamespaces: true }],
132
+ ],
133
+ plugins: [
134
+ 'react-html-attrs',
135
+ '@babel/plugin-syntax-dynamic-import',
136
+ '@babel/plugin-transform-runtime',
137
+ '@emotion/babel-plugin',
138
+ // Below allows us to reference tailwindcss theme variables in emotion
139
+ // https://medium.com/fredwong-it/emotion-tailwind-twin-macro-7fdc5f2ae5f9
140
+ // https://github.com/ben-rogerson/twin.examples/tree/master/webpack-emotion-typescript
141
+ 'babel-plugin-macros',
142
+ !build && _require.resolve('react-refresh/babel'),
143
+ ].filter(Boolean),
144
+ },
145
+ },
146
+ ],
147
+ },
148
+ {
149
+ // Workaround to hide emotion's pseudo console noise (bug)
150
+ // https://github.com/emotion-js/emotion/issues/1105#issuecomment-547247291
151
+ test: /node_modules\/@emotion\/cache\/(src|dist)/,
152
+ loader: 'string-replace-loader',
153
+ options: {
154
+ search: 'if (unsafePseudoClasses',
155
+ replace: 'if (false && unsafePseudoClasses',
156
+ },
157
+ },
158
+ {
159
+ test: /styleguide\.html$/i,
160
+ exclude: [/\/server\/email/],
161
+ loader: 'html-loader',
162
+ },
163
+ {
164
+ test: /\.csv$/,
165
+ use: [
166
+ {
167
+ loader: 'csv-loader',
168
+ options: {
169
+ delimiter: ',',
170
+ header: true,
171
+ skipEmptyLines: true,
172
+ },
173
+ },
174
+ ],
175
+ },
176
+ {
177
+ test: /\.svg$/,
178
+ use: [
179
+ {
180
+ loader: '@svgr/webpack',
181
+ options: {
182
+ svgoConfig: {
183
+ plugins: [
184
+ {
185
+ name: 'preset-default',
186
+ params: {
187
+ overrides: {
188
+ removeViewBox: false,
189
+ convertPathData: false,
190
+ cleanupNumericValues: false,
191
+ convertShapeToPath: false,
192
+ },
193
+ },
194
+ },
195
+ // {
196
+ // name: 'addClassesToSVGElement',
197
+ // params: {
198
+ // className: (node, info) => {
199
+ // console.log(info)
200
+ // return `svg-${info?.path?.split('.')[0]}`
201
+ // },
202
+ // },
203
+ // },
204
+ {
205
+ // until svgr updated to svgo@4 for addClassesToSVGElement fns support
206
+ name: 'add-data-id-to-svg-icons',
207
+ fn: (root, _params, info) => {
208
+ const { basename } = info.path.match(/.*\/(?<basename>.*)\.svg$/).groups
209
+ if (root.children[0].name === 'svg') {
210
+ root.children[0].attributes.className = `svg-${basename}`
211
+ }
212
+ },
213
+ },
214
+ ],
215
+ },
216
+ },
217
+ },
218
+ ],
219
+ },
220
+ ],
221
+ },
222
+ output: {
223
+ // devtoolModuleFilenameTemplate: (info) => {
224
+ // // DevTools doesn't link webpack:// sourcemap filepaths, force file://.
225
+ // let path = 'file://' + encodeURI(info.absoluteResourcePath)
226
+ // // React only: append ?2 to all paths so devtools can link to the CSS-in-JS
227
+ // if (path.match(/\.jsx$/)) return path + '?2'
228
+ // // Vue only: fix Vue:CSS paths
229
+ // else return path.replace(/(\/components\/).*?components\//, '$1')
230
+ // },
231
+ // We are outputing assets into a handy subdir to allow for easier asset cache control. We can't
232
+ // simply use `path` because webpack-dev-server won't work when writeFiles=false (in memory).
233
+ // Because of this we manually need to prefix all output filenames with `assets/`.
234
+ filename: `assets/bundle.[name]${build ? '.[contenthash]' : ''}.js`,
235
+ path: distDir,
236
+ publicPath: '/',
237
+ },
238
+ performance: {
239
+ hints: false,
240
+ },
241
+ optimization: {
242
+ // Split chunks into seperate emitted assets
243
+ splitChunks: {
244
+ cacheGroups: {
245
+ vendor: {
246
+ test: /[\\/]node_modules[\\/].*\.js/,
247
+ name: 'vendor',
248
+ chunks: 'all',
249
+ },
250
+ },
251
+ },
252
+ minimize: build,
253
+ },
254
+ plugins: [
255
+ // new (require('webpack-bundle-analyzer').BundleAnalyzerPlugin)(),
256
+ new CopyWebpackPlugin({
257
+ patterns: [
258
+ { from: imgsDir + 'favicon.png', to: './favicon.png' },
259
+ { from: imgsDir, to: './assets/imgs' },
260
+ { from: fontsDir, to: './assets/fonts' },
261
+ ],
262
+ }),
263
+ new webpack.DefinePlugin({
264
+ CONFIG: JSON.stringify({
265
+ ...pick(config, config.inject ? config.inject.split(' ') : []),
266
+ version: config.version,
267
+ }),
268
+ }),
269
+ new ESLintPlugin({
270
+ extensions: ['js', 'mjs', 'jsx'],
271
+ exclude: ['node_modules'],
272
+ }),
273
+ new MiniCssExtractPlugin({ filename: `assets/bundle.[name]${build ? '.[contenthash]' : ''}.css` }),
274
+ new HtmlWebpackPlugin({ template: clientDir + 'index.html', filename: distDir + 'index.html' }),
275
+ new CleanTerminalPlugin({ skipFirstRun: true }),
276
+ !build && new ReactRefreshWebpackPlugin({ overlay: false }),
277
+ ].filter(Boolean),
278
+ resolve: {
279
+ extensions: ['.js', '.jsx', '.ts', '.tsx'],
280
+ // fallback: { fs: false },
281
+ alias: {
282
+ // required for auto-importing page components into nitro app.js router
283
+ 'componentsDir': componentsDir,
284
+ // needed only for only the example app. There are also css aliases above in postcss plugins
285
+ 'nitro-web': isNitro ? path.resolve(nitroDir, 'client.js') : undefined,
286
+ },
287
+ },
288
+ stats: {
289
+ all: false,
290
+ assets: !process.env.WEBPACK_SERVE,
291
+ errors: true,
292
+ errorDetails: true,
293
+ timings: !process.env.WEBPACK_SERVE,
294
+ warnings: true,
295
+ },
296
+ watchOptions: {
297
+ aggregateTimeout: 50,
298
+ ignored: new RegExp(`(${componentsDir}.*\\.api\\.js$|node_modules/(?!cherry))`),
299
+ },
300
+ }]
301
+
302
+ }