-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdirectAssetsUploadStrategy.js
More file actions
69 lines (60 loc) · 2.16 KB
/
directAssetsUploadStrategy.js
File metadata and controls
69 lines (60 loc) · 2.16 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
import { performance } from 'perf_hooks';
import ora from 'ora';
import Gateway from '../proxy.js';
import { makeArchive } from '../archive.js';
import { deployAssets } from '../assets.js';
import duration from '../duration.js';
import files from '../files.js';
import { push } from '../push.js';
import logger from '../logger.js';
import report from '../logger/report.js';
import ServerError from '../ServerError.js';
const createArchive = (env) => makeArchive(env, { withoutAssets: true });
const uploadArchive = (env) => push(env);
const deployAndUploadAssets = async (authData) => {
const assetsToDeploy = await files.getAssets();
if (assetsToDeploy.length === 0) {
logger.Warn('There are no assets to deploy, skipping.');
return;
}
return deployAssets(new Gateway(authData));
};
const printAssetsReport = (response) => {
if (!response || !response.report) return;
const { upserted = 0, deleted = 0 } = response.report;
const parts = [];
if (upserted > 0) parts.push(`${upserted} upserted`);
if (deleted > 0) parts.push(`${deleted} deleted`);
if (parts.length > 0) {
logger.Success(`Assets: ${parts.join(', ')}`, { hideTimestamp: true });
}
};
const strategy = async ({ env, authData, _params }) => {
try {
process.env.FORCE_COLOR = true;
const url = env.MARKETPLACE_URL;
const msg = (url) => `Deploying to: ${url}`;
const numberOfFiles = await createArchive(env);
const spinner = ora({ text: msg(url), stream: process.stdout });
spinner.start();
const t0 = performance.now();
const assetsResult = await deployAndUploadAssets(authData);
printAssetsReport(assetsResult);
if (numberOfFiles > 0) {
await uploadArchive(env);
} else {
logger.Warn('There are no files in release file, skipping.');
}
spinner.succeed(`Deploy succeeded after ${duration(t0, performance.now())}`);
} catch (e) {
if (ServerError.isNetworkError(e)) {
await logger.Error('Deploy failed.', { exit: false });
await ServerError.handler(e);
process.exit(1);
} else {
await logger.Error(`Deploy failed. ${e}`);
}
report('[ERR] Deploy: Direct asset upload');
}
};
export default strategy;