3
'use strict';
4
5
const {exec} = require('child-process-promise');
6
-const {existsSync, readdirSync} = require('fs');
7
-const {readJsonSync} = require('fs-extra');
6
+const {existsSync} = require('fs');
7
const {join} = require('path');
8
const {getArtifactsList, logPromise} = require('../utils');
9
const theme = require('../theme');
10
12
-const run = async ({build, cwd}) => {
11
+const run = async ({build, cwd, releaseChannel}) => {
12
const artifacts = await getArtifactsList(build);
14
- const nodeModulesArtifact = artifacts.find(entry =>
15
- entry.path.endsWith('node_modules.tgz')
13
+ const buildArtifacts = artifacts.find(entry =>
14
+ entry.path.endsWith('build2.tgz')
15
);
16
18
- if (!nodeModulesArtifact) {
17
+ if (!buildArtifacts) {
18
console.log(
19
theme`{error The specified build (${build}) does not contain any build artifacts.}`
20
);
21
process.exit(1);
22
}
23
25
- const nodeModulesURL = nodeModulesArtifact.url;
24
+ // Download and extract artifact
25
+ await exec(`rm -rf ./build2`, {cwd});
26
+ await exec(
27
+ `curl -L $(fwdproxy-config curl) ${buildArtifacts.url} | tar -xvz`,
28
+ {
29
+ cwd,
30
+ }
31
+ );
32
33
+ // Copy to staging directory
34
+ // TODO: Consider staging the release in a different directory from the CI
35
+ // build artifacts: `./build/node_modules` -> `./staged-releases`
36
if (!existsSync(join(cwd, 'build'))) {
37
await exec(`mkdir ./build`, {cwd});
38
+ } else {
39
+ await exec(`rm -rf ./build/node_modules`, {cwd});
40
}
30
-
31
- // Download and extract artifact
32
- await exec(`rm -rf ./build/node_modules*`, {cwd});
33
- await exec(`curl -L ${nodeModulesURL} --output ./build/node_modules.tgz`, {
34
- cwd,
35
- });
36
- await exec(`mkdir ./build/node_modules`, {cwd});
37
- await exec(`tar zxvf ./build/node_modules.tgz -C ./build/node_modules/`, {
38
- cwd,
39
- });
40
-
41
- // Unpack packages and prepare to publish
42
- const compressedPackages = readdirSync(join(cwd, 'build/node_modules/'));
43
- for (let i = 0; i < compressedPackages.length; i++) {
44
- await exec(
45
- `tar zxvf ./build/node_modules/${compressedPackages[i]} -C ./build/node_modules/`,
46
- {cwd}
47
- );
48
- const packageJSON = readJsonSync(
49
- join(cwd, `/build/node_modules/package/package.json`)
50
- );
51
- await exec(
52
- `mv ./build/node_modules/package ./build/node_modules/${packageJSON.name}`,
53
- {cwd}
54
- );
41
+ let sourceDir;
42
+ if (releaseChannel === 'stable') {
43
+ sourceDir = 'oss-stable';
44
+ } else if (releaseChannel === 'experimental') {
45
+ sourceDir = 'oss-experimental';
46
+ } else {
47
+ console.error('Internal error: Invalid release channel: ' + releaseChannel);
48
+ process.exit(releaseChannel);
49
}
56
-
57
- // Cleanup
58
- await exec(`rm ./build/node_modules.tgz`, {cwd});
59
- await exec(`rm ./build/node_modules/*.tgz`, {cwd});
50
+ await exec(`cp -r ./build2/${sourceDir} ./build/node_modules`, {cwd});
51
};
52
62
-module.exports = async ({build, cwd}) => {
53
+module.exports = async ({build, cwd, releaseChannel}) => {
54
return logPromise(
64
- run({build, cwd}),
55
+ run({build, cwd, releaseChannel}),
56
theme`Downloading artifacts from Circle CI for build {build ${build}}`
57
);
58
};