forked from bcgov/esm-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.sh
executable file
·131 lines (104 loc) · 3.56 KB
/
new.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
# echo "Name of module (lowercase) => "
# read NAME
# echo "Plural name (lowercase) => "
# read PLURAL
# echo "Model name (capitalized camel) => "
# read MODEL
NAME=$1
PLURAL=$2
MODEL=$3
echo "Creating module $NAME $PLURAL $MODEL";
mkdir modules/$PLURAL
mkdir modules/$PLURAL/server
mkdir modules/$PLURAL/server/controllers
mkdir modules/$PLURAL/server/policies
mkdir modules/$PLURAL/server/models
mkdir modules/$PLURAL/server/routes
mkdir modules/$PLURAL/client
mkdir modules/$PLURAL/client/services
cat > modules/$PLURAL/client/$NAME.client.module.js <<EOFMOD
'use strict';
// Use Applicaion configuration module to register a new module
ApplicationConfiguration.registerModule('${NAME}');
EOFMOD
cat > modules/$PLURAL/client/services/$NAME.model.service.js <<EOFCC
'use strict';
// =========================================================================
//
// this is the data model (service). This is how all data
// is accessed through the front end
//
// =========================================================================
angular.module('${NAME}').factory ('${MODEL}Model', function (ModelBase, _) {
//
// build the model by extending the base model. the base model will
// have all the basic crud stuff built in
//
var Class = ModelBase.extend ({
urlName : '${NAME}'
});
return new Class ();
});
EOFCC
cat > modules/$PLURAL/server/controllers/$NAME.controller.js <<EOFC
'use strict';
// =========================================================================
//
// Controller for $PLURAL
//
// =========================================================================
var path = require('path');
var DBModel = require (path.resolve('./modules/core/server/controllers/core.dbmodel.controller'));
var _ = require ('lodash');
module.exports = DBModel.extend ({
name : '${MODEL}',
});
EOFC
cat > modules/$PLURAL/server/models/$NAME.model.js <<EOFM
'use strict';
// =========================================================================
//
// Model for $PLURAL
//
// =========================================================================
module.exports = require ('../../../core/server/controllers/core.models.controller')
.generateModel ('${MODEL}', {
__audit : true,
__access : true,
__tracking : true,
__status : ['Not Started', 'Not Required', 'In Progress', 'Complete'],
__codename : true,
project : { type:'ObjectId', ref:'Project', default:null, index:true}
});
EOFM
cat > modules/$PLURAL/server/routes/$NAME.routes.js <<EOFR
'use strict';
// =========================================================================
//
// Routes for $PLURAL
//
// =========================================================================
var policy = require ('../policies/$NAME.policy');
var $MODEL = require ('../controllers/$NAME.controller');
var helpers = require ('../../../core/server/controllers/core.helpers.controller');
module.exports = function (app) {
helpers.setCRUDRoutes (app, '${NAME}', $MODEL, policy);
};
EOFR
cat > modules/$PLURAL/server/policies/$NAME.policy.js <<EOFP
'use strict';
// =========================================================================
//
// Policies for $PLURAL
//
// =========================================================================
var acl = require ('acl');
acl = new acl (new acl.memoryBackend ());
var helpers = require (require('path').resolve('./modules/core/server/controllers/core.helpers.controller'));
exports.invokeRolesPolicies = function () {
helpers.setCRUDPermissions (acl, '${NAME}');
};
exports.isAllowed = helpers.isAllowed (acl);
EOFP
#./link.sh