nsgm-cli 1.0.25 → 1.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/README.md +162 -162
- package/generation/.babelrc +9 -9
- package/generation/README.md +18 -18
- package/generation/app.js +2 -2
- package/generation/client/layout/index.tsx +223 -223
- package/generation/client/redux/reducers.ts +5 -5
- package/generation/client/redux/store.ts +44 -44
- package/generation/client/redux/template/manage/actions.ts +190 -190
- package/generation/client/redux/template/manage/reducers.ts +118 -118
- package/generation/client/redux/template/manage/types.ts +24 -24
- package/generation/client/service/template/manage.ts +73 -73
- package/generation/client/styled/common.ts +28 -28
- package/generation/client/styled/layout/index.ts +13 -13
- package/generation/client/styled/template/manage.ts +51 -51
- package/generation/client/utils/common.ts +45 -45
- package/generation/client/utils/fetch.ts +25 -25
- package/generation/client/utils/menu.tsx +26 -26
- package/generation/gitignore +3 -3
- package/generation/mysql.config.js +12 -12
- package/generation/next-env.d.ts +2 -2
- package/generation/next.config.js +6 -6
- package/generation/package.json +20 -20
- package/generation/pages/_app.tsx +44 -44
- package/generation/pages/_document.tsx +53 -53
- package/generation/pages/index.tsx +54 -54
- package/generation/pages/template/manage.tsx +280 -280
- package/generation/project.config.js +12 -12
- package/generation/server/apis/template.js +18 -18
- package/generation/server/modules/template/resolver.js +231 -231
- package/generation/server/modules/template/schema.js +33 -33
- package/generation/server/rest.js +20 -20
- package/generation/server/sql/template.sql +8 -8
- package/generation/tsconfig.json +29 -29
- package/index.js +10 -10
- package/lib/args.d.ts +6 -6
- package/lib/args.js +47 -47
- package/lib/generate.d.ts +3 -3
- package/lib/generate.js +590 -590
- package/lib/index.d.ts +2 -2
- package/lib/index.js +182 -182
- package/lib/server/db.d.ts +5 -5
- package/lib/server/db.js +47 -47
- package/lib/server/graphql.d.ts +7 -7
- package/lib/server/graphql.js +119 -119
- package/lib/server/plugins/date.d.ts +5 -5
- package/lib/server/plugins/date.js +16 -16
- package/mysql.config.js +14 -14
- package/next.config.js +210 -210
- package/package.json +113 -113
- package/project.config.js +14 -14
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
export declare const startExpress: (options: any, callback: any) => void;
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
export declare const startExpress: (options: any, callback: any) => void;
|
package/lib/index.js
CHANGED
|
@@ -1,182 +1,182 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.startExpress = void 0;
|
|
8
|
-
var next_1 = __importDefault(require("next"));
|
|
9
|
-
var express_1 = __importDefault(require("express"));
|
|
10
|
-
var url_1 = require("url");
|
|
11
|
-
var fs_1 = __importDefault(require("fs"));
|
|
12
|
-
var path_1 = __importDefault(require("path"));
|
|
13
|
-
var child_process_1 = require("child_process");
|
|
14
|
-
var body_parser_1 = __importDefault(require("body-parser"));
|
|
15
|
-
var express_fileupload_1 = __importDefault(require("express-fileupload"));
|
|
16
|
-
var args_1 = require("./args");
|
|
17
|
-
var graphql_1 = __importDefault(require("./server/graphql"));
|
|
18
|
-
var config_1 = __importDefault(require("next/config"));
|
|
19
|
-
var generate_1 = require("./generate");
|
|
20
|
-
var lodash_1 = __importDefault(require("lodash"));
|
|
21
|
-
var resolve = path_1.default.resolve;
|
|
22
|
-
var curFolder = process.cwd();
|
|
23
|
-
var processArgvs = args_1.getProcessArgvs(2);
|
|
24
|
-
console.log('processArgvs', processArgvs);
|
|
25
|
-
var command = processArgvs.command, dictionary = processArgvs.dictionary, controller = processArgvs.controller, action = processArgvs.action;
|
|
26
|
-
var handleServer = function (server) {
|
|
27
|
-
var serverPath = resolve(curFolder + '/server/');
|
|
28
|
-
if (fs_1.default.existsSync(serverPath)) {
|
|
29
|
-
var list = fs_1.default.readdirSync(serverPath);
|
|
30
|
-
list.forEach(function (item) {
|
|
31
|
-
var resolverPath = resolve(serverPath + '/' + item);
|
|
32
|
-
var stat = fs_1.default.statSync(resolverPath);
|
|
33
|
-
var isFile = stat.isFile();
|
|
34
|
-
if (isFile) {
|
|
35
|
-
var filename = item;
|
|
36
|
-
if (item.indexOf('.') !== -1) {
|
|
37
|
-
filename = item.split('.')[0];
|
|
38
|
-
}
|
|
39
|
-
// console.log('resolverPath', resolverPath, filename)
|
|
40
|
-
if (server && filename !== undefined && filename !== '') {
|
|
41
|
-
server.use('/' + filename, require(resolverPath));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
var startExpress = function (options, callback) {
|
|
48
|
-
// console.info('startExpress', curFolder)
|
|
49
|
-
var app = next_1.default(options);
|
|
50
|
-
var handle = app.getRequestHandler();
|
|
51
|
-
app
|
|
52
|
-
.prepare()
|
|
53
|
-
.then(function () {
|
|
54
|
-
if (callback) {
|
|
55
|
-
callback();
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
var server = express_1.default();
|
|
59
|
-
server.use(body_parser_1.default.urlencoded({
|
|
60
|
-
extended: false
|
|
61
|
-
}));
|
|
62
|
-
server.use(body_parser_1.default.json());
|
|
63
|
-
server.use(express_fileupload_1.default());
|
|
64
|
-
server.use('/static', express_1.default.static(path_1.default.join(__dirname, 'public')));
|
|
65
|
-
server.use('/graphql', graphql_1.default(command));
|
|
66
|
-
handleServer(server);
|
|
67
|
-
server.get('*', function (req, res) {
|
|
68
|
-
// console.log('originalUrl', req.originalUrl)
|
|
69
|
-
var parsedUrl = url_1.parse(req.url, true);
|
|
70
|
-
return handle(req, res, parsedUrl);
|
|
71
|
-
});
|
|
72
|
-
var nextConfig = config_1.default();
|
|
73
|
-
var publicRuntimeConfig = nextConfig.publicRuntimeConfig;
|
|
74
|
-
var protocol = publicRuntimeConfig.protocol, host = publicRuntimeConfig.host, port = publicRuntimeConfig.port;
|
|
75
|
-
server.listen(port, function () {
|
|
76
|
-
console.log('> Ready on http://' + host + ':' + port);
|
|
77
|
-
});
|
|
78
|
-
})
|
|
79
|
-
.catch(function (ex) {
|
|
80
|
-
console.error(ex.stack);
|
|
81
|
-
process.exit(1);
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
exports.startExpress = startExpress;
|
|
85
|
-
switch (command) {
|
|
86
|
-
case 'dev':
|
|
87
|
-
exports.startExpress({ dev: true }, null);
|
|
88
|
-
break;
|
|
89
|
-
case 'start':
|
|
90
|
-
exports.startExpress({ dev: false }, null);
|
|
91
|
-
break;
|
|
92
|
-
case 'build':
|
|
93
|
-
case 'export':
|
|
94
|
-
var shellCommand = 'next ' + command;
|
|
95
|
-
if (command === 'export') {
|
|
96
|
-
if (dictionary === '') {
|
|
97
|
-
shellCommand += ' -o webapp';
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
shellCommand += ' -o ' + dictionary;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
child_process_1.exec(shellCommand, {}, function (err, stdout, stderr) {
|
|
104
|
-
if (err) {
|
|
105
|
-
console.log(err);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
console.log("stdout: "
|
|
109
|
-
});
|
|
110
|
-
break;
|
|
111
|
-
case 'init':
|
|
112
|
-
var initFlag_1 = true;
|
|
113
|
-
// console.log('process.argv', process.argv)
|
|
114
|
-
var argvArr = process.argv;
|
|
115
|
-
var argvArrLen = argvArr.length;
|
|
116
|
-
var fileName = '';
|
|
117
|
-
if (argvArrLen > 2) {
|
|
118
|
-
fileName = argvArr[2];
|
|
119
|
-
}
|
|
120
|
-
else if (argvArrLen > 1) {
|
|
121
|
-
fileName = argvArr[1];
|
|
122
|
-
}
|
|
123
|
-
// console.log('fileName', fileName)
|
|
124
|
-
if (fileName !== '') {
|
|
125
|
-
if (fileName.indexOf('\\') !== -1) {
|
|
126
|
-
fileName = fileName.replace(/\\/g, '/');
|
|
127
|
-
console.log('fileName2', fileName);
|
|
128
|
-
}
|
|
129
|
-
var fileNameArr = fileName.split('/');
|
|
130
|
-
var fileNameArrLen = fileNameArr.length;
|
|
131
|
-
var fileNameStr = fileNameArr[fileNameArrLen - 1];
|
|
132
|
-
// console.log('fileNameStr', fileNameStr)
|
|
133
|
-
if (fileNameStr === 'app') {
|
|
134
|
-
initFlag_1 = false;
|
|
135
|
-
}
|
|
136
|
-
lodash_1.default.each(fileNameArr, function (item, index) {
|
|
137
|
-
if (item === 'pm2') {
|
|
138
|
-
initFlag_1 = false;
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
console.log('initFlag', initFlag_1);
|
|
144
|
-
if (initFlag_1) {
|
|
145
|
-
generate_1.initFiles(dictionary);
|
|
146
|
-
}
|
|
147
|
-
break;
|
|
148
|
-
case 'upgrade':
|
|
149
|
-
generate_1.initFiles(dictionary, true);
|
|
150
|
-
break;
|
|
151
|
-
case 'create':
|
|
152
|
-
console.log(command, controller, action);
|
|
153
|
-
if (controller !== '') {
|
|
154
|
-
if (action === '') {
|
|
155
|
-
generate_1.createFiles(controller, 'manage');
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
generate_1.createFiles(controller, action);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
break;
|
|
162
|
-
case 'delete':
|
|
163
|
-
console.log(command, controller, action);
|
|
164
|
-
if (controller !== '') {
|
|
165
|
-
if (action === '' || action === 'all') {
|
|
166
|
-
generate_1.deleteFiles(controller, 'all');
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
generate_1.deleteFiles(controller, action);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
break;
|
|
173
|
-
case 'version':
|
|
174
|
-
exports.startExpress({ dev: true }, function () {
|
|
175
|
-
var nextConfig = config_1.default();
|
|
176
|
-
var publicRuntimeConfig = nextConfig.publicRuntimeConfig;
|
|
177
|
-
var version = publicRuntimeConfig.version;
|
|
178
|
-
console.log('version: ' + version);
|
|
179
|
-
process.exit(0);
|
|
180
|
-
});
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.startExpress = void 0;
|
|
8
|
+
var next_1 = __importDefault(require("next"));
|
|
9
|
+
var express_1 = __importDefault(require("express"));
|
|
10
|
+
var url_1 = require("url");
|
|
11
|
+
var fs_1 = __importDefault(require("fs"));
|
|
12
|
+
var path_1 = __importDefault(require("path"));
|
|
13
|
+
var child_process_1 = require("child_process");
|
|
14
|
+
var body_parser_1 = __importDefault(require("body-parser"));
|
|
15
|
+
var express_fileupload_1 = __importDefault(require("express-fileupload"));
|
|
16
|
+
var args_1 = require("./args");
|
|
17
|
+
var graphql_1 = __importDefault(require("./server/graphql"));
|
|
18
|
+
var config_1 = __importDefault(require("next/config"));
|
|
19
|
+
var generate_1 = require("./generate");
|
|
20
|
+
var lodash_1 = __importDefault(require("lodash"));
|
|
21
|
+
var resolve = path_1.default.resolve;
|
|
22
|
+
var curFolder = process.cwd();
|
|
23
|
+
var processArgvs = (0, args_1.getProcessArgvs)(2);
|
|
24
|
+
console.log('processArgvs', processArgvs);
|
|
25
|
+
var command = processArgvs.command, dictionary = processArgvs.dictionary, controller = processArgvs.controller, action = processArgvs.action;
|
|
26
|
+
var handleServer = function (server) {
|
|
27
|
+
var serverPath = resolve(curFolder + '/server/');
|
|
28
|
+
if (fs_1.default.existsSync(serverPath)) {
|
|
29
|
+
var list = fs_1.default.readdirSync(serverPath);
|
|
30
|
+
list.forEach(function (item) {
|
|
31
|
+
var resolverPath = resolve(serverPath + '/' + item);
|
|
32
|
+
var stat = fs_1.default.statSync(resolverPath);
|
|
33
|
+
var isFile = stat.isFile();
|
|
34
|
+
if (isFile) {
|
|
35
|
+
var filename = item;
|
|
36
|
+
if (item.indexOf('.') !== -1) {
|
|
37
|
+
filename = item.split('.')[0];
|
|
38
|
+
}
|
|
39
|
+
// console.log('resolverPath', resolverPath, filename)
|
|
40
|
+
if (server && filename !== undefined && filename !== '') {
|
|
41
|
+
server.use('/' + filename, require(resolverPath));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var startExpress = function (options, callback) {
|
|
48
|
+
// console.info('startExpress', curFolder)
|
|
49
|
+
var app = (0, next_1.default)(options);
|
|
50
|
+
var handle = app.getRequestHandler();
|
|
51
|
+
app
|
|
52
|
+
.prepare()
|
|
53
|
+
.then(function () {
|
|
54
|
+
if (callback) {
|
|
55
|
+
callback();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
var server = (0, express_1.default)();
|
|
59
|
+
server.use(body_parser_1.default.urlencoded({
|
|
60
|
+
extended: false
|
|
61
|
+
}));
|
|
62
|
+
server.use(body_parser_1.default.json());
|
|
63
|
+
server.use((0, express_fileupload_1.default)());
|
|
64
|
+
server.use('/static', express_1.default.static(path_1.default.join(__dirname, 'public')));
|
|
65
|
+
server.use('/graphql', (0, graphql_1.default)(command));
|
|
66
|
+
handleServer(server);
|
|
67
|
+
server.get('*', function (req, res) {
|
|
68
|
+
// console.log('originalUrl', req.originalUrl)
|
|
69
|
+
var parsedUrl = (0, url_1.parse)(req.url, true);
|
|
70
|
+
return handle(req, res, parsedUrl);
|
|
71
|
+
});
|
|
72
|
+
var nextConfig = (0, config_1.default)();
|
|
73
|
+
var publicRuntimeConfig = nextConfig.publicRuntimeConfig;
|
|
74
|
+
var protocol = publicRuntimeConfig.protocol, host = publicRuntimeConfig.host, port = publicRuntimeConfig.port;
|
|
75
|
+
server.listen(port, function () {
|
|
76
|
+
console.log('> Ready on http://' + host + ':' + port);
|
|
77
|
+
});
|
|
78
|
+
})
|
|
79
|
+
.catch(function (ex) {
|
|
80
|
+
console.error(ex.stack);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
exports.startExpress = startExpress;
|
|
85
|
+
switch (command) {
|
|
86
|
+
case 'dev':
|
|
87
|
+
(0, exports.startExpress)({ dev: true }, null);
|
|
88
|
+
break;
|
|
89
|
+
case 'start':
|
|
90
|
+
(0, exports.startExpress)({ dev: false }, null);
|
|
91
|
+
break;
|
|
92
|
+
case 'build':
|
|
93
|
+
case 'export':
|
|
94
|
+
var shellCommand = 'next ' + command;
|
|
95
|
+
if (command === 'export') {
|
|
96
|
+
if (dictionary === '') {
|
|
97
|
+
shellCommand += ' -o webapp';
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
shellCommand += ' -o ' + dictionary;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
(0, child_process_1.exec)(shellCommand, {}, function (err, stdout, stderr) {
|
|
104
|
+
if (err) {
|
|
105
|
+
console.log(err);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
console.log("stdout: ".concat(stdout));
|
|
109
|
+
});
|
|
110
|
+
break;
|
|
111
|
+
case 'init':
|
|
112
|
+
var initFlag_1 = true;
|
|
113
|
+
// console.log('process.argv', process.argv)
|
|
114
|
+
var argvArr = process.argv;
|
|
115
|
+
var argvArrLen = argvArr.length;
|
|
116
|
+
var fileName = '';
|
|
117
|
+
if (argvArrLen > 2) {
|
|
118
|
+
fileName = argvArr[2];
|
|
119
|
+
}
|
|
120
|
+
else if (argvArrLen > 1) {
|
|
121
|
+
fileName = argvArr[1];
|
|
122
|
+
}
|
|
123
|
+
// console.log('fileName', fileName)
|
|
124
|
+
if (fileName !== '') {
|
|
125
|
+
if (fileName.indexOf('\\') !== -1) {
|
|
126
|
+
fileName = fileName.replace(/\\/g, '/');
|
|
127
|
+
console.log('fileName2', fileName);
|
|
128
|
+
}
|
|
129
|
+
var fileNameArr = fileName.split('/');
|
|
130
|
+
var fileNameArrLen = fileNameArr.length;
|
|
131
|
+
var fileNameStr = fileNameArr[fileNameArrLen - 1];
|
|
132
|
+
// console.log('fileNameStr', fileNameStr)
|
|
133
|
+
if (fileNameStr === 'app') {
|
|
134
|
+
initFlag_1 = false;
|
|
135
|
+
}
|
|
136
|
+
lodash_1.default.each(fileNameArr, function (item, index) {
|
|
137
|
+
if (item === 'pm2') {
|
|
138
|
+
initFlag_1 = false;
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
console.log('initFlag', initFlag_1);
|
|
144
|
+
if (initFlag_1) {
|
|
145
|
+
(0, generate_1.initFiles)(dictionary);
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
case 'upgrade':
|
|
149
|
+
(0, generate_1.initFiles)(dictionary, true);
|
|
150
|
+
break;
|
|
151
|
+
case 'create':
|
|
152
|
+
console.log(command, controller, action);
|
|
153
|
+
if (controller !== '') {
|
|
154
|
+
if (action === '') {
|
|
155
|
+
(0, generate_1.createFiles)(controller, 'manage');
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
(0, generate_1.createFiles)(controller, action);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
case 'delete':
|
|
163
|
+
console.log(command, controller, action);
|
|
164
|
+
if (controller !== '') {
|
|
165
|
+
if (action === '' || action === 'all') {
|
|
166
|
+
(0, generate_1.deleteFiles)(controller, 'all');
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
(0, generate_1.deleteFiles)(controller, action);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
case 'version':
|
|
174
|
+
(0, exports.startExpress)({ dev: true }, function () {
|
|
175
|
+
var nextConfig = (0, config_1.default)();
|
|
176
|
+
var publicRuntimeConfig = nextConfig.publicRuntimeConfig;
|
|
177
|
+
var version = publicRuntimeConfig.version;
|
|
178
|
+
console.log('version: ' + version);
|
|
179
|
+
process.exit(0);
|
|
180
|
+
});
|
|
181
|
+
break;
|
|
182
|
+
}
|
package/lib/server/db.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
declare const _default: {
|
|
2
|
-
getMysqlConfig: () => null;
|
|
3
|
-
getConnection: () => Promise<unknown> | undefined;
|
|
4
|
-
};
|
|
5
|
-
export default _default;
|
|
1
|
+
declare const _default: {
|
|
2
|
+
getMysqlConfig: () => null;
|
|
3
|
+
getConnection: () => Promise<unknown> | undefined;
|
|
4
|
+
};
|
|
5
|
+
export default _default;
|
package/lib/server/db.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var mysql_1 = __importDefault(require("mysql"));
|
|
7
|
-
var fs_1 = __importDefault(require("fs"));
|
|
8
|
-
var mysqlConfig = null;
|
|
9
|
-
var getMysqlConfig = function () {
|
|
10
|
-
if (mysqlConfig == null) {
|
|
11
|
-
var curFolder = process.cwd();
|
|
12
|
-
var curMysqlConfigPath = curFolder + '/mysql.config.js';
|
|
13
|
-
if (fs_1.default.existsSync(curMysqlConfigPath)) {
|
|
14
|
-
mysqlConfig = require(curMysqlConfigPath);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
mysqlConfig = require('../../mysql.config.js');
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
// console.log('mysqlConfig', mysqlConfig)
|
|
21
|
-
return mysqlConfig;
|
|
22
|
-
};
|
|
23
|
-
var getConnection = function () {
|
|
24
|
-
mysqlConfig = getMysqlConfig();
|
|
25
|
-
if (mysqlConfig != null) {
|
|
26
|
-
var mysqlOptions_1 = mysqlConfig.mysqlOptions;
|
|
27
|
-
return new Promise(function (resolve, reject) {
|
|
28
|
-
if (mysqlOptions_1) {
|
|
29
|
-
var connection = mysql_1.default.createConnection(mysqlOptions_1);
|
|
30
|
-
if (connection) {
|
|
31
|
-
connection.connect();
|
|
32
|
-
resolve(connection);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
reject();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
reject();
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
exports.default = {
|
|
45
|
-
getMysqlConfig: getMysqlConfig,
|
|
46
|
-
getConnection: getConnection
|
|
47
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var mysql_1 = __importDefault(require("mysql"));
|
|
7
|
+
var fs_1 = __importDefault(require("fs"));
|
|
8
|
+
var mysqlConfig = null;
|
|
9
|
+
var getMysqlConfig = function () {
|
|
10
|
+
if (mysqlConfig == null) {
|
|
11
|
+
var curFolder = process.cwd();
|
|
12
|
+
var curMysqlConfigPath = curFolder + '/mysql.config.js';
|
|
13
|
+
if (fs_1.default.existsSync(curMysqlConfigPath)) {
|
|
14
|
+
mysqlConfig = require(curMysqlConfigPath);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
mysqlConfig = require('../../mysql.config.js');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// console.log('mysqlConfig', mysqlConfig)
|
|
21
|
+
return mysqlConfig;
|
|
22
|
+
};
|
|
23
|
+
var getConnection = function () {
|
|
24
|
+
mysqlConfig = getMysqlConfig();
|
|
25
|
+
if (mysqlConfig != null) {
|
|
26
|
+
var mysqlOptions_1 = mysqlConfig.mysqlOptions;
|
|
27
|
+
return new Promise(function (resolve, reject) {
|
|
28
|
+
if (mysqlOptions_1) {
|
|
29
|
+
var connection = mysql_1.default.createConnection(mysqlOptions_1);
|
|
30
|
+
if (connection) {
|
|
31
|
+
connection.connect();
|
|
32
|
+
resolve(connection);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
reject();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
reject();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.default = {
|
|
45
|
+
getMysqlConfig: getMysqlConfig,
|
|
46
|
+
getConnection: getConnection
|
|
47
|
+
};
|
package/lib/server/graphql.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
declare const _default: (command: string) => (request: import("http").IncomingMessage & {
|
|
3
|
-
url: string;
|
|
4
|
-
}, response: import("http").ServerResponse & {
|
|
5
|
-
json?: ((data: unknown) => void) | undefined;
|
|
6
|
-
}) => Promise<void>;
|
|
7
|
-
export default _default;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
declare const _default: (command: string) => (request: import("http").IncomingMessage & {
|
|
3
|
+
url: string;
|
|
4
|
+
}, response: import("http").ServerResponse & {
|
|
5
|
+
json?: ((data: unknown) => void) | undefined;
|
|
6
|
+
}) => Promise<void>;
|
|
7
|
+
export default _default;
|