|
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'; |
10 |
| -var Thing = sqldb.Thing;<% if (filters.auth) { %> |
11 |
| -var User = sqldb.User;<% } %><% } %> |
| 9 | +import sqldb from '../sqldb';<% } %> |
| 10 | +import config from './environment/'; |
12 | 11 |
|
13 |
| -<% if (filters.mongooseModels) { %>Thing.find({}).remove()<% } |
14 |
| - if (filters.sequelizeModels) { %>Thing.sync() |
15 |
| - .then(() => { |
16 |
| - return Thing.destroy({ where: {} }); |
17 |
| - })<% } %> |
18 |
| - .then(() => { |
19 |
| - <% if (filters.mongooseModels) { %>Thing.create({<% } |
20 |
| - if (filters.sequelizeModels) { %>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.mongooseModels) { %>});<% } |
48 |
| - if (filters.sequelizeModels) { %>}]);<% } %> |
49 |
| - }); |
| 12 | +export default function seedDatabaseIfNeeded() { |
| 13 | + if(config.seedDB) { |
| 14 | + <% if (filters.sequelizeModels) { %>let Thing = sqldb.Thing;<% if (filters.auth) { %> |
| 15 | + let User = sqldb.User;<% } %><% } %> |
| 16 | + |
| 17 | + <% 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)); |
50 | 53 | <% if (filters.auth) { %>
|
51 |
| -<% if (filters.mongooseModels) { %>User.find({}).remove()<% } |
52 |
| - if (filters.sequelizeModels) { %>User.sync() |
53 |
| - .then(() => User.destroy({ where: {} }))<% } %> |
54 |
| - .then(() => { |
55 |
| - <% if (filters.mongooseModels) { %>User.create({<% } |
56 |
| - if (filters.sequelizeModels) { %>User.bulkCreate([{<% } %> |
57 |
| - provider: 'local', |
58 |
| - name: 'Test User', |
59 |
| - |
60 |
| - password: 'test' |
61 |
| - }, { |
62 |
| - provider: 'local', |
63 |
| - role: 'admin', |
64 |
| - name: 'Admin', |
65 |
| - |
66 |
| - password: 'admin' |
67 |
| - <% if (filters.mongooseModels) { %>})<% } |
68 |
| - if (filters.sequelizeModels) { %>}])<% } %> |
69 |
| - .then(() => { |
70 |
| - console.log('finished populating users'); |
| 54 | + <% 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));<% } %> |
71 | 73 | });
|
72 |
| - });<% } %> |
| 74 | + } |
| 75 | +} |
0 commit comments