-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdeploy.js
56 lines (43 loc) · 1.77 KB
/
deploy.js
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
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const root = path.resolve('.', process.env.AC_FAAS_ROOT);
const packageJSONPath = path.resolve('.', 'package.json');
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath));
const dependencies = packageJSON.dependencies;
delete dependencies['@aircodelabs/hydrogen'];
dependencies['aircode'] = 'latest';
const destPackageJSONPath = path.resolve(root, 'package.json');
fs.writeFileSync(destPackageJSONPath, JSON.stringify({dependencies}, null, 2));
const isTypeScript = fs.existsSync(path.resolve('.', 'tsconfig.json'));
const aircodeConfig = `{
"name": "${packageJSON.name}",
"runtime": "node/v16",
"timeout": 60,
"region": "US",
"envs": [],
"typescript": ${isTypeScript}
}`;
fs.writeFileSync(path.resolve(root, 'aircode.config.json'), aircodeConfig);
if(packageJSON.repository && packageJSON.repository.type === 'git') {
let repository = packageJSON.repository.url;
if(repository.startsWith('git+')) {
repository = repository.substring(4);
}
if(repository.startsWith('https://github.com/')) {
repository = repository.replace('https://github.com/', '');
}
const parts = repository.split('/');
const owner = parts[0];
const repo = parts[1].replace('.git', '');
const deployUrl = `https://aircode.io/dashboard?owner=${owner}&repo=${repo}&branch=main&path=${process.env.AC_FAAS_ROOT}&appname=${packageJSON.name}`;
const readmeTpl = `# ${packageJSON.name}
${packageJSON.name} github repo deploy to [AirCode](https://aircode.io).
## One-Click Deployment
[](${deployUrl})
`;
const readmePath = path.resolve(root, 'README.md');
if(!fs.existsSync(readmePath)) {
fs.writeFileSync(readmePath, readmeTpl);
}
}