-
Notifications
You must be signed in to change notification settings - Fork 15
/
upload-monaco-editor.js
64 lines (56 loc) · 1.85 KB
/
upload-monaco-editor.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
57
58
59
60
61
62
63
64
/* eslint-disable @typescript-eslint/no-var-requires */
// Have a look at README.md (the Monaco Editor section)
// to understand why we need this GitHub Action.
const { spawn } = require('child_process');
const packageJson = require('./package.json');
const { default: appConfig } = require('./server/config');
const monacoVersion = packageJson.dependencies['monaco-editor'];
const monacoS3Path = `${appConfig.AWS.s3}/lib/monaco-editor/${monacoVersion}`;
// https://docs.aws.amazon.com/cli/latest/reference/s3/index.html
const verifyAlreadyUploaded = () => {
// The `aws s3 ls` command will not output anything
// if the URI doesn't exist. This is what we use to check
// that something has been uploaded on `monacoS3Path`
return new Promise((resolve) => {
const ls = spawn('aws', [
's3',
'ls',
'--region',
'eu-west-1',
monacoS3Path,
]);
ls.stdout.on('data', (data) => {
resolve(true);
console.log('[verifyAlreadyUploaded.stdout]', data.toString());
});
ls.stderr.on('data', (data) => {
resolve(false);
console.log('[verifyAlreadyUploaded.stderr]', data.toString());
});
ls.on('close', () => {
// If neither of the above listeners have been called,
// it means that the command didn't output anything,
// thus this version hasn't been uploaded.
// We don't have to worry about concurrency,
// as a Promise can only be resolved once
resolve(false);
});
});
};
verifyAlreadyUploaded().then((isAlreadyUploaded) => {
if (isAlreadyUploaded) {
console.log(`Monaco version ${monacoVersion} has already been uploaded. Exiting.`);
return;
}
spawn('aws', [
's3',
'cp',
'--region',
'eu-west-1',
'--acl',
'public-read',
'node_modules/monaco-editor/min/',
monacoS3Path,
'--recursive',
], { stdio: 'inherit' });
});