Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Mar 9, 2021. It is now read-only.

Commit b6f3d27

Browse files
committed
refactor travis script
1 parent 607048e commit b6f3d27

File tree

1 file changed

+44
-17
lines changed

1 file changed

+44
-17
lines changed

scripts/now.js

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,19 @@ if (process.env.TRAVIS_PULL_REQUEST) {
3939
);
4040
}
4141

42-
function noop() {}
42+
function noop(err, res) {
43+
console.log(err, res);
44+
}
4345

4446
function getUrl(content) {
4547
const urls = content.match(urlRegex()) || [];
4648

4749
return urls.map(url => normalizeUrl(url.trim().replace(/\.+$/, '')))[0];
4850
}
4951

52+
const comment = ({ url, context }) =>
53+
`### New Δ Now ${context} deployment complete\n- ✅ **Build Passed**\n- 🚀 **URL** : ${url}\n---\nNote: **This is autogenerated through travis-ci build**`;
54+
5055
function deploy(context, sha) {
5156
ghRepo.status(
5257
sha,
@@ -67,7 +72,9 @@ function deploy(context, sha) {
6772
'-n',
6873
'coderplex-app',
6974
];
75+
7076
const alias = context === 'production' && process.env.NOW_ALIAS;
77+
7178
let stdout = '';
7279

7380
if (argv.p || argv.public) {
@@ -82,6 +89,7 @@ function deploy(context, sha) {
8289

8390
if (!alias) {
8491
child.stdout.on('data', data => {
92+
console.log(data);
8593
stdout += data;
8694
});
8795
}
@@ -99,20 +107,19 @@ function deploy(context, sha) {
99107
);
100108
axios
101109
.post(discordHook, {
102-
content: `Δ Now ${context} deployment failed. See Travis logs for details.`,
110+
content: `Δ Now ${context} deployment failed. See Travis logs for details. Reason: \n \`\`\`${err}\`\`\``,
103111
username: 'coderplex-bot',
104112
})
105113
.then(() => {
106-
console.log(`SUCCESS posted to discord`);
114+
console.log(`Error posted to discord`);
107115
})
108116
.catch(console.log);
109117
});
110118

111119
child.on('close', () => {
112120
const target_url = getUrl(stdout);
113-
const comment = url =>
114-
`### New Δ Now ${context} deployment complete\n- ✅ **Build Passed**\n- 🚀 **URL** : ${url}\n---\nNote: **This is autogenerated through travis-ci build**`;
115121
if (alias) {
122+
console.log(`Alising ${target_url} to ${alias}`);
116123
const args = [
117124
'alias',
118125
'--token',
@@ -123,22 +130,42 @@ function deploy(context, sha) {
123130
target_url,
124131
alias,
125132
];
126-
spawn(nowCli, args);
127-
axios
128-
.post(discordHook, {
129-
content: comment(`${alias} and https://coderplex.org`),
130-
username: 'coderplex-bot',
131-
})
132-
.then(() => {
133-
console.log(`SUCCESS posted to discord`);
134-
})
135-
.catch(console.log);
133+
const subChild = spawn(nowCli, args);
134+
subChild.stdout.on('data', data => {
135+
console.log(data);
136+
});
137+
subChild.on('error', err => {
138+
console.log(err);
139+
axios
140+
.post(discordHook, {
141+
content: `Aliasing ${target_url} to ${alias} failed. Reason: \n \`\`\`${err}\`\`\``,
142+
username: 'coderplex-bot',
143+
})
144+
.then(() => {
145+
console.log(`Error posted to discord`);
146+
})
147+
.catch(console.log);
148+
});
149+
subChild.on('close', () => {
150+
axios
151+
.post(discordHook, {
152+
content: comment({
153+
url: `${alias} and https://coderplex.org`,
154+
context,
155+
}),
156+
username: 'coderplex-bot',
157+
})
158+
.then(() => {
159+
console.log(`SUCCESS posted to discord`);
160+
})
161+
.catch(console.log);
162+
});
136163
}
137164
if (ghPR) {
138-
console.log(comment(target_url));
165+
console.log(comment({ url: target_url, context }));
139166
ghPR.createComment(
140167
{
141-
body: comment(target_url),
168+
body: comment({ url: target_url, context }),
142169
},
143170
(err, res) => {
144171
console.log(err, res);

0 commit comments

Comments
 (0)