UNPKG

3.56 kBJavaScriptView Raw
1"use strict";
2const packager_1 = require("./packager");
3const gitHubPublisher_1 = require("./gitHubPublisher");
4const promise_1 = require("./promise");
5const awaiter_1 = require("./awaiter");
6const repositoryInfo_1 = require("./repositoryInfo");
7const util_1 = require("./util");
8const __awaiter = awaiter_1.tsAwaiter;
9Array.isArray(__awaiter);
10function createPublisher(packager, options, repoSlug, isPublishOptionGuessed = false) {
11 return __awaiter(this, void 0, void 0, function* () {
12 const info = yield repoSlug.getInfo(packager);
13 if (info == null) {
14 if (isPublishOptionGuessed) {
15 return null;
16 }
17 util_1.log("Cannot detect repository by .git/config");
18 throw new Error("Please specify 'repository' in the dev package.json ('" + packager.devPackageFile + "')");
19 }
20 else {
21 return new gitHubPublisher_1.GitHubPublisher(info.user, info.project, packager.metadata.version, options.githubToken, options.publish !== "onTagOrDraft");
22 }
23 });
24}
25exports.createPublisher = createPublisher;
26function build(options = {}) {
27 if (options.cscLink == null) {
28 options.cscLink = process.env.CSC_LINK;
29 }
30 if (options.cscKeyPassword == null) {
31 options.cscKeyPassword = process.env.CSC_KEY_PASSWORD;
32 }
33 if (options.githubToken == null) {
34 options.githubToken = process.env.GH_TOKEN || process.env.GH_TEST_TOKEN;
35 }
36 const lifecycleEvent = process.env.npm_lifecycle_event;
37 if (options.dist === undefined) {
38 options.dist = lifecycleEvent === "dist" || lifecycleEvent === "build";
39 }
40 if (options.publish) {
41 options.dist = true;
42 }
43 let isPublishOptionGuessed = false;
44 if (options.publish === undefined) {
45 if (lifecycleEvent === "release") {
46 options.publish = "always";
47 }
48 else {
49 const tag = process.env.TRAVIS_TAG || process.env.APPVEYOR_REPO_TAG_NAME || process.env.CIRCLE_TAG;
50 if (tag != null && tag.length !== 0) {
51 util_1.log("Tag %s is defined, so artifacts will be published", tag);
52 options.publish = "onTag";
53 isPublishOptionGuessed = true;
54 }
55 else if ((process.env.TRAVIS || process.env.APPVEYOR || process.env.CIRCLECI || "").toLowerCase() === "true") {
56 util_1.log("CI detected, so artifacts will be published if draft release exists");
57 options.publish = "onTagOrDraft";
58 isPublishOptionGuessed = true;
59 }
60 }
61 }
62 const publishTasks = [];
63 const repositoryInfo = new repositoryInfo_1.InfoRetriever();
64 const packager = new packager_1.Packager(options, repositoryInfo);
65 if (options.publish != null && options.publish !== "never") {
66 let publisher = null;
67 packager.artifactCreated(path => {
68 if (publisher == null) {
69 publisher = createPublisher(packager, options, repositoryInfo, isPublishOptionGuessed);
70 }
71 if (publisher != null) {
72 publisher.then(it => publishTasks.push(it.upload(path)));
73 }
74 });
75 }
76 return promise_1.executeFinally(packager.build(), error => {
77 if (error == null) {
78 return Promise.all(publishTasks);
79 }
80 else {
81 for (let task of publishTasks) {
82 task.cancel();
83 }
84 return null;
85 }
86 });
87}
88exports.build = build;
89//# sourceMappingURL=builder.js.map
\No newline at end of file