@celljs/vercel-adapter 3.0.0
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 +21 -0
- package/README.md +1 -0
- package/cell-remote.yml +10 -0
- package/cell.yml +2 -0
- package/lib/hooks/build.d.ts +4 -0
- package/lib/hooks/build.d.ts.map +1 -0
- package/lib/hooks/build.js +30 -0
- package/lib/hooks/build.js.map +1 -0
- package/lib/hooks/deploy.d.ts +4 -0
- package/lib/hooks/deploy.d.ts.map +1 -0
- package/lib/hooks/deploy.js +25 -0
- package/lib/hooks/deploy.js.map +1 -0
- package/lib/node/context.d.ts +4 -0
- package/lib/node/context.d.ts.map +1 -0
- package/lib/node/context.js +7 -0
- package/lib/node/context.js.map +1 -0
- package/lib/node/http-application-entry.d.ts +2 -0
- package/lib/node/http-application-entry.d.ts.map +1 -0
- package/lib/node/http-application-entry.js +22 -0
- package/lib/node/http-application-entry.js.map +1 -0
- package/lib/node/index.d.ts +2 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +18 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/module.d.ts +3 -0
- package/lib/node/module.d.ts.map +1 -0
- package/lib/node/module.js +5 -0
- package/lib/node/module.js.map +1 -0
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +4 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +49 -0
- package/src/hooks/build.ts +29 -0
- package/src/hooks/deploy.ts +22 -0
- package/src/node/context.ts +3 -0
- package/src/node/http-application-entry.ts +21 -0
- package/src/node/index.ts +1 -0
- package/src/node/module.ts +3 -0
- package/src/package.spec.ts +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Cellbang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Cell - Vercel Adapter Component
|
package/cell-remote.yml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
cell:
|
|
2
|
+
vercel:
|
|
3
|
+
config:
|
|
4
|
+
version: 2
|
|
5
|
+
builds:
|
|
6
|
+
- src: ${ 'dist/backend/**' | onTarget('backend') || 'dist/frontend/**' }
|
|
7
|
+
use: ${ '@vercel/node' | onTarget('backend') || '@vercel/static' }
|
|
8
|
+
routes:
|
|
9
|
+
- src: ${ '/api' | onTarget('backend') || '/(.*).js' }
|
|
10
|
+
dest: ${ 'dist/backend/index.js' | onTarget('backend') || 'dist/frontend/$1.js' }
|
package/cell.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/hooks/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyD,MAAM,oBAAoB,CAAC;kCAI1E,YAAY;AAA3C,wBAwBE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cli_common_1 = require("@celljs/cli-common");
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs_extra_1 = require("fs-extra");
|
|
6
|
+
exports.default = async (context) => {
|
|
7
|
+
const { cfg } = context;
|
|
8
|
+
let vercelConfig = {};
|
|
9
|
+
for (const target of [cli_common_1.BACKEND_TARGET, cli_common_1.FRONTEND_TARGET]) {
|
|
10
|
+
if (cli_common_1.ConfigUtil.support(cfg, target)) {
|
|
11
|
+
const config = cli_common_1.ConfigUtil.getCellConfig(cfg, target).vercel.config;
|
|
12
|
+
if (target === cli_common_1.BACKEND_TARGET) {
|
|
13
|
+
vercelConfig = cli_common_1.ConfigUtil.merge(config, vercelConfig);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
vercelConfig = cli_common_1.ConfigUtil.merge(vercelConfig, config);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (!cli_common_1.ConfigUtil.support(cfg, cli_common_1.FRONTEND_TARGET)) {
|
|
21
|
+
vercelConfig.routes.push({
|
|
22
|
+
src: '/.*',
|
|
23
|
+
dest: 'dist/backend/index.js'
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
await (0, fs_extra_1.ensureDir)(cli_common_1.PathUtil.getProjectHomePath());
|
|
27
|
+
const configPath = (0, path_1.resolve)(cli_common_1.PathUtil.getProjectHomePath(), 'vercel.json');
|
|
28
|
+
await (0, fs_extra_1.writeJSON)(configPath, vercelConfig, { spaces: 2 });
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/hooks/build.ts"],"names":[],"mappings":";;AAAA,mDAAyG;AACzG,+BAA+B;AAC/B,uCAAgD;AAEhD,kBAAe,KAAK,EAAE,OAAqB,EAAE,EAAE;IAC3C,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IACxB,IAAI,YAAY,GAAQ,EAAE,CAAC;IAE3B,KAAK,MAAM,MAAM,IAAI,CAAE,2BAAc,EAAE,4BAAe,CAAE,EAAE;QACtD,IAAI,uBAAU,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE;YACjC,MAAM,MAAM,GAAG,uBAAU,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;YACnE,IAAI,MAAM,KAAK,2BAAc,EAAE;gBAC3B,YAAY,GAAG,uBAAU,CAAC,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;aACzD;iBAAM;gBACH,YAAY,GAAG,uBAAU,CAAC,KAAK,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;aACzD;SACJ;KACJ;IAED,IAAI,CAAC,uBAAU,CAAC,OAAO,CAAC,GAAG,EAAE,4BAAe,CAAC,EAAE;QAC3C,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC;YACrB,GAAG,EAAE,KAAK;YACV,IAAI,EAAE,uBAAuB;SAChC,CAAC,CAAC;KACN;IACD,MAAM,IAAA,oBAAS,EAAC,qBAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,IAAA,cAAO,EAAC,qBAAQ,CAAC,kBAAkB,EAAE,EAAE,aAAa,CAAC,CAAC;IACzE,MAAM,IAAA,oBAAS,EAAC,UAAU,EAAE,YAAY,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;AAC7D,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/hooks/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAY,MAAM,oBAAoB,CAAC;kCAM9B,aAAa;AAA5C,wBAeE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cli_common_1 = require("@celljs/cli-common");
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
const commandExists = require('command-exists');
|
|
8
|
+
exports.default = async (context) => {
|
|
9
|
+
const { pkg, prod } = context;
|
|
10
|
+
console.log(`Deploying ${chalk.bold.yellow(pkg.pkg.name)} to Vercel...`);
|
|
11
|
+
try {
|
|
12
|
+
await commandExists('vercel');
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
console.log(chalk `The vercel command does not exist, please install it first: {yellow.bold npm i -g vercel}`);
|
|
16
|
+
process.exit(-1);
|
|
17
|
+
}
|
|
18
|
+
const args = [];
|
|
19
|
+
if (prod) {
|
|
20
|
+
args.push('--prod');
|
|
21
|
+
}
|
|
22
|
+
args.push(...['--local-config', (0, path_1.join)(cli_common_1.PathUtil.getProjectHomePath(), 'vercel.json')]);
|
|
23
|
+
(0, child_process_1.spawnSync)('vercel', { cwd: cli_common_1.PathUtil.getProjectHomePath(), stdio: 'inherit' });
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=deploy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/hooks/deploy.ts"],"names":[],"mappings":";;AAAA,mDAA6D;AAC7D,+BAA4B;AAC5B,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAC/B,iDAA0C;AAC1C,MAAM,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAEhD,kBAAe,KAAK,EAAE,OAAsB,EAAE,EAAE;IAC5C,MAAM,EAAE,GAAG,EAAE,IAAI,EAAC,GAAG,OAAO,CAAC;IAC7B,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACzE,IAAI;QACA,MAAM,aAAa,CAAC,QAAQ,CAAC,CAAC;KACjC;IAAC,OAAO,GAAG,EAAE;QACV,OAAO,CAAC,GAAG,CAAC,KAAK,CAAA,2FAA2F,CAAC,CAAC;QAC9G,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;KACpB;IACD,MAAM,IAAI,GAAG,EAAE,CAAC;IAChB,IAAI,IAAI,EAAE;QACN,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KACvB;IACD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAA,WAAI,EAAC,qBAAQ,CAAC,kBAAkB,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACrF,IAAA,yBAAS,EAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,qBAAQ,CAAC,kBAAkB,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/node/context.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB;;CAElC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/node/context.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG;IAClC,IAAI,EAAE,IAAI;CACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-application-entry.d.ts","sourceRoot":"","sources":["../../src/node/http-application-entry.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const dynamic_container_1 = require("@celljs/core/lib/common/container/dynamic-container");
|
|
4
|
+
const node_1 = require("@celljs/web/lib/node");
|
|
5
|
+
const express = require("express");
|
|
6
|
+
const context_1 = require("./context");
|
|
7
|
+
const core_1 = require("@celljs/core");
|
|
8
|
+
dynamic_container_1.container.then(async (c) => {
|
|
9
|
+
core_1.ContainerProvider.set(c);
|
|
10
|
+
await c.get(core_1.Application).start();
|
|
11
|
+
const configProvider = c.get(core_1.ConfigProvider);
|
|
12
|
+
const { port } = configProvider.get('cell.server', context_1.DEFAULT_SERVER_OPTIONS);
|
|
13
|
+
const app = express();
|
|
14
|
+
app.all('*', async (req, res) => {
|
|
15
|
+
const dispatcher = c.get(node_1.Dispatcher);
|
|
16
|
+
const httpContext = new node_1.Context(req, res);
|
|
17
|
+
node_1.Context.run(() => dispatcher.dispatch(httpContext));
|
|
18
|
+
});
|
|
19
|
+
app.listen(port);
|
|
20
|
+
console.log(`serve ${port}`);
|
|
21
|
+
});
|
|
22
|
+
//# sourceMappingURL=http-application-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-application-entry.js","sourceRoot":"","sources":["../../src/node/http-application-entry.ts"],"names":[],"mappings":";;AAAA,2FAAgF;AAChF,+CAA2D;AAC3D,mCAAmC;AACnC,uCAAmD;AACnD,uCAA8E;AAE9E,6BAAS,CAAC,IAAI,CAAC,KAAK,EAAC,CAAC,EAAC,EAAE;IACrB,wBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzB,MAAM,CAAC,CAAC,GAAG,CAAc,kBAAW,CAAC,CAAC,KAAK,EAAE,CAAC;IAC9C,MAAM,cAAc,GAAG,CAAC,CAAC,GAAG,CAAiB,qBAAc,CAAC,CAAC;IAC7D,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC,GAAG,CAAM,aAAa,EAAE,gCAAsB,CAAC,CAAC;IAEhF,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;IACtB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAQ,EAAE,GAAQ,EAAE,EAAE;QACtC,MAAM,UAAU,GAAG,CAAC,CAAC,GAAG,CAAsB,iBAAU,CAAC,CAAC;QAC1D,MAAM,WAAW,GAAG,IAAI,cAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC1C,cAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACjB,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;AACjC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./context"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":";AAEA,wBAA0B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AAExC,kBAAe,IAAA,eAAQ,GAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=package.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.d.ts","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"AAAA,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IAEpC,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@celljs/vercel-adapter",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "lib/node/index.js",
|
|
6
|
+
"typings": "lib/node/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@celljs/cli-common": "3.0.0",
|
|
9
|
+
"@celljs/core": "3.0.0",
|
|
10
|
+
"@celljs/web": "3.0.0",
|
|
11
|
+
"chalk": "^4.1.0",
|
|
12
|
+
"command-exists": "^1.2.9",
|
|
13
|
+
"express": "^4.17.1",
|
|
14
|
+
"fs-extra": "^9.0.13"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"cell-component"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/cellbang/cell.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/cellbang/cell/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/cellbang/cell",
|
|
31
|
+
"files": [
|
|
32
|
+
"lib",
|
|
33
|
+
"src",
|
|
34
|
+
"cell.yml",
|
|
35
|
+
"cell-remote.yml"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"lint": "cell-component lint",
|
|
39
|
+
"build": "cell-component build",
|
|
40
|
+
"watch": "cell-component watch",
|
|
41
|
+
"clean": "cell-component clean",
|
|
42
|
+
"test": "cell-component test:js"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@celljs/cli-service": "3.0.0",
|
|
46
|
+
"@celljs/component": "3.0.0"
|
|
47
|
+
},
|
|
48
|
+
"gitHead": "c0ef8d269e33a795406bcbb240cac4b845c6c24c"
|
|
49
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BuildContext, FRONTEND_TARGET, BACKEND_TARGET, ConfigUtil, PathUtil } from '@celljs/cli-common';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
import { writeJSON, ensureDir } from 'fs-extra';
|
|
4
|
+
|
|
5
|
+
export default async (context: BuildContext) => {
|
|
6
|
+
const { cfg } = context;
|
|
7
|
+
let vercelConfig: any = {};
|
|
8
|
+
|
|
9
|
+
for (const target of [ BACKEND_TARGET, FRONTEND_TARGET ]) {
|
|
10
|
+
if (ConfigUtil.support(cfg, target)) {
|
|
11
|
+
const config = ConfigUtil.getCellConfig(cfg, target).vercel.config;
|
|
12
|
+
if (target === BACKEND_TARGET) {
|
|
13
|
+
vercelConfig = ConfigUtil.merge(config, vercelConfig);
|
|
14
|
+
} else {
|
|
15
|
+
vercelConfig = ConfigUtil.merge(vercelConfig, config);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!ConfigUtil.support(cfg, FRONTEND_TARGET)) {
|
|
21
|
+
vercelConfig.routes.push({
|
|
22
|
+
src: '/.*',
|
|
23
|
+
dest: 'dist/backend/index.js'
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
await ensureDir(PathUtil.getProjectHomePath());
|
|
27
|
+
const configPath = resolve(PathUtil.getProjectHomePath(), 'vercel.json');
|
|
28
|
+
await writeJSON(configPath, vercelConfig, { spaces: 2 });
|
|
29
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DeployContext, PathUtil } from '@celljs/cli-common';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
import { spawnSync } from 'child_process';
|
|
5
|
+
const commandExists = require('command-exists');
|
|
6
|
+
|
|
7
|
+
export default async (context: DeployContext) => {
|
|
8
|
+
const { pkg, prod} = context;
|
|
9
|
+
console.log(`Deploying ${chalk.bold.yellow(pkg.pkg.name)} to Vercel...`);
|
|
10
|
+
try {
|
|
11
|
+
await commandExists('vercel');
|
|
12
|
+
} catch (err) {
|
|
13
|
+
console.log(chalk`The vercel command does not exist, please install it first: {yellow.bold npm i -g vercel}`);
|
|
14
|
+
process.exit(-1);
|
|
15
|
+
}
|
|
16
|
+
const args = [];
|
|
17
|
+
if (prod) {
|
|
18
|
+
args.push('--prod');
|
|
19
|
+
}
|
|
20
|
+
args.push(...['--local-config', join(PathUtil.getProjectHomePath(), 'vercel.json')]);
|
|
21
|
+
spawnSync('vercel', { cwd: PathUtil.getProjectHomePath(), stdio: 'inherit' });
|
|
22
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { container } from '@celljs/core/lib/common/container/dynamic-container';
|
|
2
|
+
import { Dispatcher, Context } from '@celljs/web/lib/node';
|
|
3
|
+
import * as express from 'express';
|
|
4
|
+
import { DEFAULT_SERVER_OPTIONS } from './context';
|
|
5
|
+
import { ContainerProvider, Application, ConfigProvider } from '@celljs/core';
|
|
6
|
+
|
|
7
|
+
container.then(async c => {
|
|
8
|
+
ContainerProvider.set(c);
|
|
9
|
+
await c.get<Application>(Application).start();
|
|
10
|
+
const configProvider = c.get<ConfigProvider>(ConfigProvider);
|
|
11
|
+
const { port } = configProvider.get<any>('cell.server', DEFAULT_SERVER_OPTIONS);
|
|
12
|
+
|
|
13
|
+
const app = express();
|
|
14
|
+
app.all('*', async (req: any, res: any) => {
|
|
15
|
+
const dispatcher = c.get<Dispatcher<Context>>(Dispatcher);
|
|
16
|
+
const httpContext = new Context(req, res);
|
|
17
|
+
Context.run(() => dispatcher.dispatch(httpContext));
|
|
18
|
+
});
|
|
19
|
+
app.listen(port);
|
|
20
|
+
console.log(`serve ${port}`);
|
|
21
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './context';
|