-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
64 lines (52 loc) · 2.38 KB
/
deploy.js
File metadata and controls
64 lines (52 loc) · 2.38 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
'use strict';
const {execSync} = require('child_process');
const fs = require("fs");
const {URL} = require('url');
const FormData = require('form-data');
const Path = require('path');
const axios = require("axios");
const configPath = Path.join(__dirname, "config", "buildConfig.json");
(async () => {
try {
console.log('-- build project --');
execSync('yarn run build', {stdio: "inherit"});
let config = JSON.parse(fs.readFileSync(configPath).toString());
if (config.publish === "local") {
console.log('-- pack project --');
execSync('npm pack', {stdio: "inherit"});
let version = process.env.npm_package_version;
let packageName = 'softvision-webpdf-wsclient-typescript-' + version + '.tgz';
let readStream = fs.createReadStream(packageName);
const formData = new FormData();
formData.append('file', readStream);
let url = new URL(config.api);
url.searchParams.set("repository", config.repository);
let response = await axios.post(url, formData, {
headers: {
Accept: 'application/json',
Authorization: 'Basic ' + Buffer.from(config.username + ":" + config.password).toString("base64")
}
});
if (response.status >= 300 || response.status < 200) {
let error = new Error(response.statusText);
error.code = response.status;
error.stack = await response.data;
throw error;
}
} else if (config.publish === "public") {
// public publish needs .npmrc file with: //registry.npmjs.org/:_authToken=<TOKEN>
let version = process.env.npm_package_version;
console.log('-- deploy project --');
execSync('yarn publish --access=public --always-auth=true --non-interactive --new-version ' + version, {stdio: "inherit"});
}
} catch (err) {
if (typeof err.stderr !== 'undefined' && err.stderr !== null && err.stderr.toString() !== '') {
console.error(err.stderr.toString());
} else if (typeof err.stdout !== 'undefined' && err.stdout !== null && err.stdout.toString() !== '') {
console.error(err.stdout.toString());
} else {
console.error(err);
}
process.exit(1);
}
})();