-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add models and migrations examples
- Loading branch information
1 parent
535f861
commit dc188e1
Showing
53 changed files
with
10,480 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# EditorConfig helps developers define and maintain consistent | ||
# coding styles between different editors and IDEs | ||
# http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": [ | ||
"airbnb-base", | ||
"plugin:jest/recommended" | ||
], | ||
"plugins": ["jest"], | ||
"env": { | ||
"jest/globals": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,7 @@ dist | |
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Zone Identifiers | ||
*.Identifier | ||
**/.Identifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
.DS_Store | ||
|
||
# Built assets | ||
build/**/* | ||
!build/assets/.gitkeep | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
.idea | ||
.envrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"trailingComma" : "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
config: path.resolve('src', 'config', 'database.js'), | ||
'migrations-path': path.resolve('src', 'migrations'), | ||
'models-path': path.resolve('src', 'models'), | ||
'seeders-path': path.resolve('src', 'seeds'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"@iic2513/generator-template": { | ||
"projectName": "test-app" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: yarn start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Gud Reads | ||
Código de ejemplo en el contexto de las cápsulas desarrolladas para demostrar usos básicos del template del curso. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = function babelConfig(api) { | ||
const babelEnv = api.env(); | ||
const presets = [ | ||
['@babel/env', { | ||
targets: { | ||
ie: '9', | ||
browsers: ['>1%', 'last 3 versions'], | ||
}, | ||
modules: babelEnv === 'test' ? 'auto' : false, | ||
useBuiltIns: 'usage', | ||
corejs: 3, | ||
}], | ||
['@babel/preset-react', { | ||
development: babelEnv === 'development', | ||
}], | ||
]; | ||
|
||
const plugins = [ | ||
'react-hot-loader/babel', | ||
]; | ||
return { presets, plugins }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* eslint no-console: "off" */ | ||
|
||
const app = require('./src/app'); | ||
const db = require('./src/models'); | ||
|
||
const PORT = process.env.PORT || 3000; | ||
|
||
db.sequelize | ||
.authenticate() | ||
.then(() => { | ||
console.log('Connection to the database has been established successfully.'); | ||
app.listen(PORT, (err) => { | ||
if (err) { | ||
return console.error('Failed', err); | ||
} | ||
console.log(`Listening on port ${PORT}`); | ||
return app; | ||
}); | ||
}) | ||
.catch((err) => console.error('Unable to connect to the database:', err)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ignore": ["src/assets", "build"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ | ||
"name": "test-app", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "node index.js", | ||
"dev": "nodemon index.js", | ||
"lint": "eslint ./src index.js", | ||
"lint-fix": "eslint --fix ./src index.js", | ||
"build-assets": "yarn run clean-assets && NODE_ENV=production webpack -p", | ||
"clean-assets": "rm -rf build/assets", | ||
"heroku-postbuild": "yarn run build-assets && sequelize db:migrate", | ||
"test": "jest" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.11.6", | ||
"@babel/core": "^7.11.6", | ||
"@babel/preset-env": "^7.11.5", | ||
"@babel/preset-react": "^7.10.4", | ||
"babel-jest": "^26.3.0", | ||
"babel-loader": "^8.1.0", | ||
"css-loader": "^4.3.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-airbnb": "^18.2.0", | ||
"eslint-config-airbnb-base": "^14.2.0", | ||
"eslint-plugin-import": "^2.22.0", | ||
"eslint-plugin-jest": "^24.0.0", | ||
"eslint-plugin-jsx-a11y": "^6.3.1", | ||
"eslint-plugin-react": "^7.20.6", | ||
"eslint-plugin-react-hooks": "^4.1.2", | ||
"file-loader": "^6.1.0", | ||
"jest": "^26.4.2", | ||
"koa-webpack": "^6.0.0", | ||
"mini-css-extract-plugin": "^0.11.1", | ||
"node-sass": "^4.14.1", | ||
"nodemon": "^2.0.4", | ||
"react-test-renderer": "^16.13.1", | ||
"sass-loader": "^10.0.2", | ||
"style-loader": "^1.2.1", | ||
"supertest": "^4.0.2", | ||
"webpack": "^4.44.1", | ||
"webpack-command": "^0.5.0", | ||
"webpack-manifest-plugin": "^2.2.0" | ||
}, | ||
"dependencies": { | ||
"core-js": "^3.6.5", | ||
"dotenv": "^8.2.0", | ||
"koa": "^2.13.0", | ||
"koa-body": "^4.2.0", | ||
"koa-ejs": "^4.3.0", | ||
"koa-flash-message": "^0.1.6", | ||
"koa-logger": "^3.2.1", | ||
"koa-override-method": "^1.0.0", | ||
"koa-router": "^9.4.0", | ||
"koa-session": "^6.0.0", | ||
"koa-static": "^5.0.0", | ||
"nodemailer": "^6.4.11", | ||
"pg": "^8.3.3", | ||
"pg-hstore": "^2.3.3", | ||
"prop-types": "^15.7.2", | ||
"react": "^16.13.1", | ||
"react-dom": "^16.13.1", | ||
"react-hot-loader": "^4.12.21", | ||
"sequelize": "^6.3.5", | ||
"sequelize-cli": "^6.2.0" | ||
}, | ||
"engines": { | ||
"node": "10.x || 12.x", | ||
"yarn": "^1.22.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const path = require('path'); | ||
const Koa = require('koa'); | ||
const koaBody = require('koa-body'); | ||
const koaLogger = require('koa-logger'); | ||
const koaFlashMessage = require('koa-flash-message').default; | ||
const koaStatic = require('koa-static'); | ||
const render = require('koa-ejs'); | ||
const session = require('koa-session'); | ||
const override = require('koa-override-method'); | ||
const assets = require('./assets'); | ||
const mailer = require('./mailers'); | ||
const routes = require('./routes'); | ||
const orm = require('./models'); | ||
|
||
// App constructor | ||
const app = new Koa(); | ||
|
||
const developmentMode = app.env === 'development'; | ||
const testMode = app.env === 'test'; | ||
|
||
app.keys = [ | ||
'these secret keys are used to sign HTTP cookies', | ||
'to make sure only this app can generate a valid one', | ||
'and thus preventing someone just writing a cookie', | ||
'saying he is logged in when it\'s really not', | ||
]; | ||
|
||
// expose ORM through context's prototype | ||
app.context.orm = orm; | ||
|
||
/** | ||
* Middlewares | ||
*/ | ||
|
||
// expose running mode in ctx.state | ||
app.use((ctx, next) => { | ||
ctx.state.env = ctx.app.env; | ||
return next(); | ||
}); | ||
|
||
// log requests | ||
if (!testMode) { | ||
app.use(koaLogger()); | ||
} | ||
|
||
// webpack middleware for dev mode only | ||
if (developmentMode) { | ||
// eslint-disable-next-line import/no-extraneous-dependencies, global-require | ||
const koaWebpack = require('koa-webpack'); | ||
koaWebpack() | ||
.then((middleware) => app.use(middleware)) | ||
.catch(console.error); // eslint-disable-line no-console | ||
} | ||
|
||
app.use(koaStatic(path.join(__dirname, '..', 'build'), {})); | ||
|
||
// expose a session hash to store information across requests from same client | ||
app.use(session({ | ||
maxAge: 14 * 24 * 60 * 60 * 1000, // 2 weeks | ||
}, app)); | ||
|
||
// flash messages support | ||
app.use(koaFlashMessage); | ||
|
||
// parse request body | ||
app.use(koaBody({ | ||
multipart: true, | ||
keepExtensions: true, | ||
})); | ||
|
||
app.use((ctx, next) => { | ||
ctx.request.method = override.call(ctx, ctx.request.body.fields || ctx.request.body); | ||
return next(); | ||
}); | ||
|
||
// Configure EJS views | ||
app.use(assets(developmentMode)); | ||
render(app, { | ||
root: path.join(__dirname, 'views'), | ||
viewExt: 'html.ejs', | ||
cache: !developmentMode, | ||
}); | ||
|
||
mailer(app); | ||
|
||
// Routing middleware | ||
app.use(routes.routes()); | ||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
let manifest; | ||
|
||
try { | ||
// eslint-disable-next-line global-require,import/no-unresolved | ||
manifest = require('../build/assets/manifest.json'); | ||
} catch (err) { | ||
// noop | ||
} | ||
|
||
module.exports = function assetsBuilder(developmentMode) { | ||
function assetPath(path) { | ||
return (!developmentMode && manifest && manifest[path]) || `/assets/${path}`; | ||
} | ||
return function assets(ctx, next) { | ||
ctx.state.assetPath = assetPath; | ||
return next(); | ||
}; | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "airbnb", | ||
"env": { | ||
"browser": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import App from './components/App'; | ||
|
||
const reactAppContainer = document.getElementById('react-app'); | ||
|
||
if (reactAppContainer) { | ||
ReactDOM.render(<App />, reactAppContainer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '../images/logo.png'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
import { hot } from 'react-hot-loader'; | ||
|
||
function App() { | ||
return <div>Hello React World!</div>; | ||
} | ||
|
||
export default hot(module)(App); |
Oops, something went wrong.