nitro-web 0.0.1 → 0.0.3

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 (37) hide show
  1. package/.eslintrc.json +2 -5
  2. package/_example/{.env-example → .env} +3 -3
  3. package/_example/client/config.ts +1 -5
  4. package/_example/client/index.ts +1 -18
  5. package/_example/components/auth.api.js +1 -1
  6. package/_example/components/index.tsx +11 -3
  7. package/_example/components/settings.api.js +1 -1
  8. package/_example/package.json +109 -0
  9. package/_example/server/config.js +3 -16
  10. package/_example/server/index.js +4 -3
  11. package/_example/tailwind.config.js +12 -21
  12. package/_example/tsconfig.json +2 -2
  13. package/_example/types/index.d.ts +13 -0
  14. package/_example/types/twin.d.ts +19 -0
  15. package/_example/webpack.config.js +2 -3
  16. package/client/index.js +42 -0
  17. package/components/auth/signin.jsx +9 -1
  18. package/components/partials/element/modal.jsx +1 -1
  19. package/components/partials/form/drop-handler.jsx +1 -1
  20. package/components/partials/form/input-currency.jsx +5 -2
  21. package/components/partials/form/input-date.jsx +6 -6
  22. package/components/partials/form/input.jsx +9 -9
  23. package/components/partials/layout/layout2.jsx +1 -1
  24. package/components/partials/styleguide.jsx +6 -7
  25. package/components/settings/settings-account.jsx +1 -1
  26. package/components/settings/settings-business.jsx +1 -4
  27. package/components/settings/settings-team--member.jsx +1 -1
  28. package/package.json +28 -97
  29. package/readme.md +39 -9
  30. package/server/email/index.js +12 -10
  31. package/server/index.js +23 -0
  32. package/server/router.js +4 -8
  33. package/util.js +13 -0
  34. package/webpack.config.js +43 -42
  35. package/_example/types.d.ts +0 -7
  36. package/client.js +0 -42
  37. package/server.js +0 -20
package/webpack.config.js CHANGED
@@ -7,7 +7,7 @@ import HtmlWebpackPlugin from 'html-webpack-plugin'
7
7
  import MiniCssExtractPlugin from 'mini-css-extract-plugin'
8
8
  import webpackNodeExternals from 'webpack-node-externals'
9
9
  import path from 'path'
10
- import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'
10
+ // import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'
11
11
  import tailwindcss from 'tailwindcss'
12
12
  import webpack from 'webpack'
13
13
  import ESLintPlugin from 'eslint-webpack-plugin'
@@ -15,31 +15,27 @@ import postcssImport from 'postcss-import'
15
15
  import postcssNested from 'postcss-nested'
16
16
  import postcssFor from 'postcss-for'
17
17
  import { createRequire } from 'module'
18
- import postcssImportResolver from 'postcss-import-resolver'
19
- const _require = createRequire(import.meta.url)
18
+ import { getDirectories } from './util.js'
20
19
 
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'
20
+ const _require = createRequire(import.meta.url)
21
+ const pick = (object, list) => list.reduce((o, e) => ((o[e] = object[e]), o), {})
22
+ const isBuild = process.env.NODE_ENV == 'production'
27
23
 
28
- const pick = (object, list) => list.reduce((o, e) => ((o[e] = object[e]), o), {})
24
+ axiosRetry(axios, {
25
+ retries: 10,
26
+ retryDelay: () => 150,
27
+ retryCondition: (e) => e.code == 'ECONNREFUSED',
28
+ })
29
29
 
30
- axiosRetry(axios, {
31
- retries: 10,
32
- retryDelay: () => 150,
33
- retryCondition: (e) => e.code == 'ECONNREFUSED',
34
- })
30
+ // process.traceDeprecation = true
31
+ export const getConfig = (config) => {
32
+ const { clientDir, componentsDir, distDir, imgsDir, fontsDir } = getDirectories(path, config.pwd)
35
33
 
36
- // process.traceDeprecation = true
37
- // eslint-disable-next-line
38
34
  return (env, argv) => [{
39
- devtool: build ? false : 'source-map',
35
+ devtool: isBuild ? false : 'source-map',
40
36
  entry: clientDir + 'index.ts',
41
- // entry: build ? './client/index.tsx' : ['webpack-plugin-serve/client', './client/index.tsx'], // check this
42
- mode: build ? 'production' : 'development',
37
+ // entry: isBuild ? './client/index.tsx' : ['webpack-plugin-serve/client', './client/index.tsx'], // check this
38
+ mode: isBuild ? 'production' : 'development',
43
39
  // target=node ignores node_modules
44
40
  externals: argv.target?.[0] == 'node' ? [webpackNodeExternals()] : [],
45
41
  // target=node ignores builtin modules
@@ -94,17 +90,18 @@ export function getWebpackConfig(config) {
94
90
  { loader: 'postcss-loader', options: {
95
91
  postcssOptions: {
96
92
  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
- }),
93
+ postcssImport,
94
+ // postcssImport({
95
+ // resolve: postcssImportResolver({
96
+ // alias: {
97
+ // 'nitro-web/client/css/components.css': path.resolve(nitroDir, 'client/css/components.css'),
98
+ // 'nitro-web/client/css/fonts.css': path.resolve(nitroDir, 'client/css/fonts.css'),
99
+ // },
100
+ // }),
101
+ // }),
105
102
  postcssNested,
106
103
  postcssFor,
107
- tailwindcss({ config: `./${isNitro ? '_example/' : ''}tailwind.config.js` }),
104
+ tailwindcss({ config: path.resolve(config.pwd, 'tailwind.config.js') }),
108
105
  autoprefixer,
109
106
  ],
110
107
  },
@@ -119,6 +116,7 @@ export function getWebpackConfig(config) {
119
116
  // Dont transpile node modules except for date-fns, which uses ES6
120
117
  return path.includes('node_modules')
121
118
  && !path.includes('node_modules/date-fns')
119
+ && !path.includes('node_modules/nitro-web')
122
120
  }
123
121
  ),
124
122
  use: [
@@ -127,19 +125,25 @@ export function getWebpackConfig(config) {
127
125
  options: {
128
126
  presets: [
129
127
  ['@babel/preset-env', { debug: false }],
130
- ['@babel/preset-react', { runtime: 'automatic', importSource: '@emotion/react' }],
131
128
  ['@babel/preset-typescript', { allowNamespaces: true }],
129
+ ['@babel/preset-react', { runtime: 'automatic', importSource: '@emotion/react', development: !isBuild }],
132
130
  ],
133
131
  plugins: [
134
132
  'react-html-attrs',
135
133
  '@babel/plugin-syntax-dynamic-import',
136
134
  '@babel/plugin-transform-runtime',
137
135
  '@emotion/babel-plugin',
138
- // Below allows us to reference tailwindcss theme variables in emotion
136
+ // Below allows us to reference tailwindcss theme variables in emotion blocks
137
+ // https://github.com/ben-rogerson/twin.macro/blob/master/docs/options.md
139
138
  // 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'),
139
+ // https://github.com/ben-rogerson/twin.examples/tree/master/react-emotion-typescript#complete-the-typescript-setup
140
+ ['babel-plugin-macros', {
141
+ 'twin': {
142
+ preset: 'emotion',
143
+ config: path.resolve(config.pwd, 'tailwind.config.js'),
144
+ },
145
+ }],
146
+ // 'react-refresh/babel', // !isBuild && _require.resolve('react-refresh/babel'),
143
147
  ].filter(Boolean),
144
148
  },
145
149
  },
@@ -231,7 +235,7 @@ export function getWebpackConfig(config) {
231
235
  // We are outputing assets into a handy subdir to allow for easier asset cache control. We can't
232
236
  // simply use `path` because webpack-dev-server won't work when writeFiles=false (in memory).
233
237
  // Because of this we manually need to prefix all output filenames with `assets/`.
234
- filename: `assets/bundle.[name]${build ? '.[contenthash]' : ''}.js`,
238
+ filename: `assets/bundle.[name]${isBuild ? '.[contenthash]' : ''}.js`,
235
239
  path: distDir,
236
240
  publicPath: '/',
237
241
  },
@@ -249,7 +253,7 @@ export function getWebpackConfig(config) {
249
253
  },
250
254
  },
251
255
  },
252
- minimize: build,
256
+ minimize: isBuild,
253
257
  },
254
258
  plugins: [
255
259
  // new (require('webpack-bundle-analyzer').BundleAnalyzerPlugin)(),
@@ -270,10 +274,10 @@ export function getWebpackConfig(config) {
270
274
  extensions: ['js', 'mjs', 'jsx'],
271
275
  exclude: ['node_modules'],
272
276
  }),
273
- new MiniCssExtractPlugin({ filename: `assets/bundle.[name]${build ? '.[contenthash]' : ''}.css` }),
277
+ new MiniCssExtractPlugin({ filename: `assets/bundle.[name]${isBuild ? '.[contenthash]' : ''}.css` }),
274
278
  new HtmlWebpackPlugin({ template: clientDir + 'index.html', filename: distDir + 'index.html' }),
275
279
  new CleanTerminalPlugin({ skipFirstRun: true }),
276
- !build && new ReactRefreshWebpackPlugin({ overlay: false }),
280
+ // !isBuild && new ReactRefreshWebpackPlugin({ overlay: false }),
277
281
  ].filter(Boolean),
278
282
  resolve: {
279
283
  extensions: ['.js', '.jsx', '.ts', '.tsx'],
@@ -281,8 +285,6 @@ export function getWebpackConfig(config) {
281
285
  alias: {
282
286
  // required for auto-importing page components into nitro app.js router
283
287
  '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
288
  },
287
289
  },
288
290
  stats: {
@@ -298,5 +300,4 @@ export function getWebpackConfig(config) {
298
300
  ignored: new RegExp(`(${componentsDir}.*\\.api\\.js$|node_modules/(?!cherry))`),
299
301
  },
300
302
  }]
301
-
302
- }
303
+ }
@@ -1,7 +0,0 @@
1
- declare module '*.svg' {
2
- const content: string | React.FC<React.SVGProps<SVGElement>>
3
- export default content
4
- }
5
- declare global {
6
- const sharedStore: any
7
- }
package/client.js DELETED
@@ -1,42 +0,0 @@
1
- export * from './client/app.js'
2
- export * from './util.js'
3
- export * as util from './util.js'
4
-
5
- // Components: Pages
6
- export { Signin } from './components/auth/signin.jsx'
7
- export { Signup } from './components/auth/signup.jsx'
8
- export { ResetInstructions, ResetPassword } from './components/auth/reset.jsx'
9
- // export { SettingsAccount } from './components/settings/settings-account.jsx'
10
- // export { SettingsBusiness } from './components/settings/settings-business.jsx'
11
- // export { SettingsTeamMember } from './components/settings/settings-team--member.jsx'
12
- // export { SettingsTeam } from './components/settings/settings-team.jsx'
13
-
14
- // Components: partials: elements
15
- export { Accordion } from './components/partials/element/accordion.jsx'
16
- export { Avatar } from './components/partials/element/avatar.jsx'
17
- export { Button } from './components/partials/element/button.jsx'
18
- export { Dropdown } from './components/partials/element/dropdown.jsx'
19
- export { Initials } from './components/partials/element/initials.jsx'
20
- export { Message } from './components/partials/element/message.jsx'
21
- // export { Modal } from './components/partials/element/modal.jsx'
22
- export { Sidebar } from './components/partials/element/sidebar.jsx'
23
- export { Tooltip } from './components/partials/element/tooltip.jsx'
24
- export { Topbar } from './components/partials/element/topbar.jsx'
25
-
26
- // Components: partials: form
27
- export { Checkbox } from './components/partials/form/checkbox.jsx'
28
- export { Drop } from './components/partials/form/drop.jsx'
29
- export { FormError } from './components/partials/form/form-error.jsx'
30
- export { Input } from './components/partials/form/input.jsx'
31
- export { Location } from './components/partials/form/location.jsx'
32
- export { Select } from './components/partials/form/select.jsx'
33
- export { Toggle } from './components/partials/form/toggle.jsx'
34
-
35
- // Components: partials: layouts
36
- export { Layout1 } from './components/partials/layout/layout1.jsx'
37
- export { Layout2 } from './components/partials/layout/layout2.jsx'
38
-
39
- // Components: partials: other
40
- export { IsFirstRender } from './components/partials/is-first-render.js'
41
- export { NotFound } from './components/partials/not-found.jsx'
42
- export { Styleguide } from './components/partials/styleguide.jsx'
package/server.js DELETED
@@ -1,20 +0,0 @@
1
- // Export models
2
- import userModel from './server/models/user.js'
3
- import companyModel from './server/models/company.js'
4
- async function setupDefaultModels(db) {
5
- // Load default nitro models, if they don't exist already
6
- if (!db.models.user) await db.model('user', userModel)
7
- if (!db.models.company) await db.model('company', companyModel)
8
- }
9
- export { userModel, companyModel, setupDefaultModels }
10
-
11
- // Export router
12
- export { setupRouter } from './server/router.js'
13
-
14
- // Export email util
15
- export { sendEmail } from './server/email/index.js'
16
-
17
- // Export api default controllers
18
- export { default as auth } from './components/auth/auth.api.js'
19
- export { default as settings } from './components/settings/settings.api.js'
20
- export { default as stripe } from './components/billing/stripe.api.js'