|
6 | 6 | 'use strict';<% if (filters.mongooseModels) { %>
|
7 | 7 | import Thing from '../api/thing/thing.model';<% if (filters.auth) { %>
|
8 | 8 | import User from '../api/user/user.model';<% } %><% } %><% if (filters.sequelizeModels) { %>
|
9 |
| -import sqldb from '../sqldb';<% } %> |
| 9 | +import { Thing<% if (filters.auth) { %>, User<% } %> } from '../sqldb';<% if (filters.auth) { %> |
| 10 | +import Sequelize from 'sequelize';<% } %><% } %> |
10 | 11 | import config from './environment/';
|
11 | 12 |
|
12 | 13 | export default function seedDatabaseIfNeeded() {
|
13 | 14 | if(config.seedDB) {
|
14 |
| - <% if (filters.sequelizeModels) { %>let Thing = sqldb.Thing;<% if (filters.auth) { %> |
15 |
| - let User = sqldb.User;<% } %><% } %> |
16 |
| - |
17 | 15 | <% if (filters.mongooseModels) { %>Thing.find({}).remove()<% }
|
18 |
| - if (filters.sequelizeModels) { %>return Thing.destroy({ where: {} })<% } %> |
19 |
| - .then(() => { |
20 |
| - <% if (filters.mongooseModels) { %>Thing.create({<% } |
21 |
| - if (filters.sequelizeModels) { %>return Thing.bulkCreate([{<% } %> |
22 |
| - name: 'Development Tools', |
23 |
| - info: 'Integration with popular tools such as Webpack, Gulp, Babel, TypeScript, Karma, ' |
24 |
| - + 'Mocha, ESLint, Node Inspector, Livereload, Protractor, Pug, ' |
25 |
| - + 'Stylus, Sass, and Less.' |
26 |
| - }, { |
27 |
| - name: 'Server and Client integration', |
28 |
| - info: 'Built with a powerful and fun stack: MongoDB, Express, ' |
29 |
| - + 'AngularJS, and Node.' |
30 |
| - }, { |
31 |
| - name: 'Smart Build System', |
32 |
| - info: 'Build system ignores `spec` files, allowing you to keep ' |
33 |
| - + 'tests alongside code. Automatic injection of scripts and ' |
34 |
| - + 'styles into your index.html' |
35 |
| - }, { |
36 |
| - name: 'Modular Structure', |
37 |
| - info: 'Best practice client and server structures allow for more ' |
38 |
| - + 'code reusability and maximum scalability' |
39 |
| - }, { |
40 |
| - name: 'Optimized Build', |
41 |
| - info: 'Build process packs up your templates as a single JavaScript ' |
42 |
| - + 'payload, minifies your scripts/css/images, and rewrites asset ' |
43 |
| - + 'names for caching.' |
44 |
| - }, { |
45 |
| - name: 'Deployment Ready', |
46 |
| - info: 'Easily deploy your app to Heroku or Openshift with the heroku ' |
47 |
| - + 'and openshift subgenerators' |
48 |
| - <% if (filters.mongooseModels) { %>});<% } |
49 |
| - if (filters.sequelizeModels) { %>}]);<% } %> |
50 |
| - }) |
51 |
| - .then(() => console.log('finished populating things')) |
52 |
| - .catch(err => console.log('error populating things', err)); |
53 |
| -<% if (filters.auth) { %> |
| 16 | + if (filters.sequelizeModels) { %>return <% if (filters.auth) { %>Sequelize.Promise.all([ |
| 17 | + <% } %>Thing.destroy({ where: {} })<% } %> |
| 18 | + .then(() =><% if (filters.mongooseModels) { %> { |
| 19 | + Thing.create({<% } if (filters.sequelizeModels) { %> |
| 20 | + Thing.bulkCreate([{<% } %> |
| 21 | + name: 'Development Tools', |
| 22 | + info: 'Integration with popular tools such as Webpack, Gulp, Babel, TypeScript, Karma, ' |
| 23 | + + 'Mocha, ESLint, Node Inspector, Livereload, Protractor, Pug, ' |
| 24 | + + 'Stylus, Sass, and Less.' |
| 25 | + }, { |
| 26 | + name: 'Server and Client integration', |
| 27 | + info: 'Built with a powerful and fun stack: MongoDB, Express, ' |
| 28 | + + 'AngularJS, and Node.' |
| 29 | + }, { |
| 30 | + name: 'Smart Build System', |
| 31 | + info: 'Build system ignores `spec` files, allowing you to keep ' |
| 32 | + + 'tests alongside code. Automatic injection of scripts and ' |
| 33 | + + 'styles into your index.html' |
| 34 | + }, { |
| 35 | + name: 'Modular Structure', |
| 36 | + info: 'Best practice client and server structures allow for more ' |
| 37 | + + 'code reusability and maximum scalability' |
| 38 | + }, { |
| 39 | + name: 'Optimized Build', |
| 40 | + info: 'Build process packs up your templates as a single JavaScript ' |
| 41 | + + 'payload, minifies your scripts/css/images, and rewrites asset ' |
| 42 | + + 'names for caching.' |
| 43 | + }, { |
| 44 | + name: 'Deployment Ready', |
| 45 | + info: 'Easily deploy your app to Heroku or Openshift with the heroku ' |
| 46 | + + 'and openshift subgenerators' |
| 47 | + }<% if (filters.sequelizeModels) { %>]<% } %>)<% if (filters.mongooseModels) { %>; |
| 48 | + }<% } %>) |
| 49 | + .then(() => console.log('seeded things'))<% if (filters.sequelizeModels && filters.auth) { %>,<% } if (filters.auth) { %> |
54 | 50 | <% if (filters.mongooseModels) { %>User.find({}).remove()<% }
|
55 |
| - if (filters.sequelizeModels) { %>User.destroy({ where: {} })<% } %> |
56 |
| - .then(() => { |
57 |
| - <% if (filters.mongooseModels) { %>User.create({<% } |
58 |
| - if (filters.sequelizeModels) { %>return User.bulkCreate([{<% } %> |
59 |
| - provider: 'local', |
60 |
| - name: 'Test User', |
61 |
| - |
62 |
| - password: 'test' |
63 |
| - }, { |
64 |
| - provider: 'local', |
65 |
| - role: 'admin', |
66 |
| - name: 'Admin', |
67 |
| - |
68 |
| - password: 'admin' |
69 |
| - <% if (filters.mongooseModels) { %>})<% } |
70 |
| - if (filters.sequelizeModels) { %>}])<% } %> |
71 |
| - .then(() => console.log('finished populating users')) |
72 |
| - .catch(err => console.log('error populating users', err));<% } %> |
73 |
| - }); |
| 51 | + if (filters.sequelizeModels) { %> User.destroy({ where: {} })<% } %> |
| 52 | + .then(() =><% if (filters.mongooseModels) { %> {<% } %> |
| 53 | + <% if (filters.mongooseModels) { %>User.create({<% } |
| 54 | + if (filters.sequelizeModels) { %>User.bulkCreate([{<% } %> |
| 55 | + provider: 'local', |
| 56 | + name: 'Test User', |
| 57 | + |
| 58 | + password: 'test' |
| 59 | + }, { |
| 60 | + provider: 'local', |
| 61 | + role: 'admin', |
| 62 | + name: 'Admin', |
| 63 | + |
| 64 | + password: 'admin' |
| 65 | + }<% if (filters.mongooseModels) { %>); |
| 66 | + })<% } |
| 67 | + if (filters.sequelizeModels) { %>])<% } %> |
| 68 | + .then(() => console.log('seeded users'))<% if (filters.sequelizeModels) { %>)]) |
| 69 | + .then(() => console.log('seeded database'))<% } %><% } %> |
| 70 | + <% if (filters.sequelizeModels && !filters.auth) { %> <% } %><% if (filters.mongooseModels) { %> <% } %>.catch(err => console.log('Seeding error: ', err)); |
74 | 71 | }
|
75 | 72 | }
|
0 commit comments