Skip to content

Commit

Permalink
feat: add typescript support
Browse files Browse the repository at this point in the history
  • Loading branch information
rocwind committed Feb 8, 2022
1 parent 7644969 commit 6b1a5d7
Show file tree
Hide file tree
Showing 53 changed files with 187 additions and 45 deletions.
134 changes: 134 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@
],
"author": "shihuimiao",
"bin": {
"code-push-server": "./bin/www",
"code-push-server-db": "./bin/db"
"code-push-server": "./bin/www.js",
"code-push-server-db": "./bin/db.js"
},
"engines": {
"node": ">= 6.0",
"npm": ">= 3.10.8"
},
"scripts": {
"dev": "LOG_LEVEL=debug supervisor ./bin/www",
"start": "node ./bin/www",
"init": "node ./bin/db init",
"upgrade": "node ./bin/db upgrade",
"release": "npm test && standard-version && git push --follow-tags origin master && npm publish",
"dev": "npm run build && concurrently npm:dev:tsc npm:dev:run",
"dev:tsc": "tsc --watch",
"dev:run": "LOG_LEVEL=debug supervisor ./bin/www.js",
"start": "node ./bin/www.js",
"init": "node ./bin/db.js init",
"upgrade": "node ./bin/db.js upgrade",
"build": "rm -rf bin && tsc",
"release": "npm run build && npm test && standard-version && git push --follow-tags origin master && npm publish",
"release-docker": "make release-docker",
"test": "make test"
},
Expand Down Expand Up @@ -69,23 +72,20 @@
},
"devDependencies": {
"@shm-open/eslint-config-bundle": "1.8.1",
"concurrently": "7.0.0",
"mocha": "9.2.0",
"should": "13.2.3",
"standard-version": "9.3.2",
"supertest": "6.2.2",
"supervisor": "0.12.0"
"supervisor": "0.12.0",
"typescript": "4.5.5"
},
"files": [
"bin",
"config",
"core",
"docs",
"models",
"public",
"routes",
"sql",
"views",
"app.js",
"README.md",
"LICENSE"
]
Expand Down
4 changes: 2 additions & 2 deletions process.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"name": "code-push-server",
"max_memory_restart": "500M",
"script": "code-push-server",
"instances": "max", //开启实例数量,max为cpu核数
"exec_mode": "cluster", //集群模式,最大提升网站并发
"instances": "max",
"exec_mode": "cluster",
"env": {
"NODE_ENV": "production"
}
Expand Down
4 changes: 2 additions & 2 deletions app.js → src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ app.use(
}),
);
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('views', path.join(__dirname, '../views'));
app.set('view engine', 'pug');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, '../public')));

logger.debug('use set Access-Control Header');
app.all('*', function (req, res, next) {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion core/config.js → src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { setLogTransports, ConsoleTransport, LogLevelFilter, logger } = require('

const env = process.env.NODE_ENV || 'development';

let CONFIG_PATH = path.join(__dirname, '../config/config.js');
let CONFIG_PATH = path.join(__dirname, '../config.js');
if (process.env.CONFIG_FILE) {
CONFIG_PATH = path.join(__dirname, path.relative(__dirname, process.env.CONFIG_FILE));
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion bin/db → src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var fs = require('fs');
var path = require('path');
var _ = require('lodash');
var mysql = require('mysql2');
var constConfig = require('../core/const');
var constConfig = require('./core/const');
var yargs = require('yargs');
var argv = yargs
.usage('Usage: $0 <command> [options]')
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion models/index.js → src/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var path = require('path');
var Sequelize = require('sequelize');
var basename = path.basename(module.filename);
var _ = require('lodash');
var config = _.get(require(__dirname + '/../core/config'), 'db', {});
var config = _.get(require('../core/config'), 'db', {});
var db = {};

var sequelize = new Sequelize(config.database, config.username, config.password, config);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions bin/www → src/www.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ var { logger } = require('kv-logger');
var http = require('http');
var validator = require('validator');
var _ = require('lodash');
var config = require('../core/config');
var constConfig = require('../core/const');
var config = require('./core/config');
var constConfig = require('./core/const');
var models = require('./models');

var app = require('../app');
var app = require('./app');

/**
* Get port from environment and store in Express.
Expand Down Expand Up @@ -40,12 +41,11 @@ var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
var models = require('../models');
models.Versions.findOne({ where: { type: 1 } })
.then(function (v) {
if (!v || v.get('version') != constConfig.CURRENT_DB_VERSION) {
throw new Error(
'Please upgrade your database. usage `npm run upgrade` or `code-push-server-db upgrade`',
'Please upgrade your database. use `npm run upgrade` or `code-push-server-db upgrade`',
);
}
server.listen(port, host);
Expand All @@ -57,7 +57,7 @@ models.Versions.findOne({ where: { type: 1 } })
if (_.startsWith(e.message, 'ER_NO_SUCH_TABLE')) {
logger.error(
new Error(
`Please upgrade your database. usage bin/db upgrade or code-push-server-db upgrade`,
'Please upgrade your database. use `npm run upgrade` or `code-push-server-db upgrade`',
),
);
} else {
Expand Down
4 changes: 1 addition & 3 deletions tests/api/accessKeys/accessKeys.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
var app = require('../../../app');
var app = require('../../../bin/app');
var request = require('supertest')(app);
var should = require('should');
var security = require('../../../core/utils/security');
var factory = require('../../../core/utils/factory');
var _ = require('lodash');

describe('api/accessKeys/accessKeys.test.js', function () {
Expand Down
4 changes: 1 addition & 3 deletions tests/api/account/account.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
var app = require('../../../app');
var app = require('../../../bin/app');
var request = require('supertest')(app);
var should = require('should');
var security = require('../../../core/utils/security');
var factory = require('../../../core/utils/factory');
var _ = require('lodash');

describe('api/account/account.test.js', function () {
Expand Down
4 changes: 1 addition & 3 deletions tests/api/apps/apps.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
var app = require('../../../app');
var app = require('../../../bin/app');
var request = require('supertest')(app);
var should = require('should');
var security = require('../../../core/utils/security');
var factory = require('../../../core/utils/factory');
var _ = require('lodash');

describe('api/apps/apps.test.js', function () {
Expand Down
5 changes: 2 additions & 3 deletions tests/api/apps/release.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
var app = require('../../../app');
var app = require('../../../bin/app');
var request = require('supertest')(app);
var should = require('should');
var path = require('path');
var security = require('../../../core/utils/security');
var factory = require('../../../core/utils/factory');
var _ = require('lodash');

const SLEEP_TIME = 5000;

describe('api/apps/release.test.js', function () {
Expand Down
5 changes: 3 additions & 2 deletions tests/api/auth/auth.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
var app = require('../../../app');
var app = require('../../../bin/app');
var request = require('supertest')(app);
var should = require('should');
var config = require('../../../core/config');
var _ = require('lodash');

var config = require('../../../bin/core/config');

describe('api/auth/test.js', function () {
var account = '[email protected]';
var password = '123456';
Expand Down
2 changes: 1 addition & 1 deletion tests/api/index/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var app = require('../../../app');
var app = require('../../../bin/app');
var request = require('supertest')(app);
var should = require('should');
var _ = require('lodash');
Expand Down
2 changes: 1 addition & 1 deletion tests/api/init/database.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var config = require('../../../core/config');
var config = require('../../../bin/core/config');
var mysql = require('mysql2');
var redis = require('redis');
var should = require('should');
Expand Down
Loading

0 comments on commit 6b1a5d7

Please sign in to comment.