File tree Expand file tree Collapse file tree 3 files changed +62
-1
lines changed Expand file tree Collapse file tree 3 files changed +62
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ const rateLimiter = require("express-rate-limit");
14
14
// Require Internal Dependencies
15
15
const server = require ( "./src/httpServer" ) ;
16
16
const models = require ( "./src/models" ) ;
17
+ const initDefaultData = require ( "./src/initDefaultData" ) ;
18
+
19
+ // ARGV
20
+ const [ initData = null ] = process . argv . slice ( 2 ) ;
17
21
18
22
// CONSTANTS
19
23
const PORT = process . env . PORT || 1338 ;
@@ -45,6 +49,9 @@ async function main() {
45
49
let isClosed = false ;
46
50
47
51
await sequelize . sync ( ) ;
52
+ if ( initData !== null ) {
53
+ await initDefaultData ( tables ) ;
54
+ }
48
55
49
56
// Cleanup Interval
50
57
setInterval ( async ( ) => {
Original file line number Diff line number Diff line change 4
4
"description" : " SlimIO Addons registry" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
7
- "start" : " node index.js" ,
7
+ "start" : " node index.js init " ,
8
8
"prepublishOnly" : " pkg-ok" ,
9
9
"hydrate" : " node scripts/hydrate.js" ,
10
10
"test" : " cross-env psp && node test/test.js" ,
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ // Require Third-party Dependencies
4
+ const argon2 = require ( "argon2" ) ;
5
+
6
+ /**
7
+ * @function initDefaultData
8
+ * @param {* } tables Sequelize tables
9
+ * @returns {void }
10
+ */
11
+ async function initDefaultData ( tables ) {
12
+ console . log ( "INIT DEFAULT DATA!" ) ;
13
+ const [ user ] = await tables . Users . findOrCreate ( {
14
+ where : {
15
+ username : "fraxken"
16
+ } ,
17
+ defaults : {
18
+ username : "fraxken" ,
19
+ active : true ,
20
+
21
+ password : await argon2 . hash ( process . env . ADMIN_PASSWORD || "admin" )
22
+ }
23
+ } ) ;
24
+
25
+ const [ org ] = await tables . Organisation . findOrCreate ( {
26
+ where : {
27
+ name : "SlimIO"
28
+ } ,
29
+ defaults : {
30
+ name : "SlimIO" ,
31
+ description : "SlimIO Official Organisation" ,
32
+ ownerId : user . id
33
+ }
34
+ } ) ;
35
+
36
+ await tables . Addons . findOrCreate ( {
37
+ where : {
38
+ name : "cpu"
39
+ } ,
40
+ defaults : {
41
+ name : "cpu" ,
42
+ description : "CPU Addon" ,
43
+ latest : "1.0.0" ,
44
+ version : {
45
+ version : "1.0.0" ,
46
+ git : "https://github.com/SlimIO/cpu-addon"
47
+ } ,
48
+ authorId : user . id ,
49
+ organisationId : org . id
50
+ }
51
+ } ) ;
52
+ }
53
+
54
+ module . exports = initDefaultData ;
You can’t perform that action at this time.
0 commit comments