1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.filterCFBundleIdentifier = exports.AppInfo = exports.smarten = void 0;
|
4 | const builder_util_1 = require("builder-util");
|
5 | const semver_1 = require("semver");
|
6 | const macroExpander_1 = require("./util/macroExpander");
|
7 | const filename_1 = require("./util/filename");
|
8 |
|
9 |
|
10 | function smarten(s) {
|
11 |
|
12 | s = s.replace(/(^|[-\u2014\s(["])'/g, "$1\u2018");
|
13 |
|
14 | s = s.replace(/'/g, "\u2019");
|
15 |
|
16 | s = s.replace(/(^|[-\u2014/[(\u2018\s])"/g, "$1\u201c");
|
17 |
|
18 | s = s.replace(/"/g, "\u201d");
|
19 | return s;
|
20 | }
|
21 | exports.smarten = smarten;
|
22 | class AppInfo {
|
23 | constructor(info, buildVersion, platformSpecificOptions = null) {
|
24 | this.info = info;
|
25 | this.platformSpecificOptions = platformSpecificOptions;
|
26 | this.description = smarten(this.info.metadata.description || "");
|
27 | this.version = info.metadata.version;
|
28 | if (buildVersion == null) {
|
29 | buildVersion = info.config.buildVersion;
|
30 | }
|
31 | this.buildNumber =
|
32 | process.env.BUILD_NUMBER ||
|
33 | process.env.TRAVIS_BUILD_NUMBER ||
|
34 | process.env.APPVEYOR_BUILD_NUMBER ||
|
35 | process.env.CIRCLE_BUILD_NUM ||
|
36 | process.env.BUILD_BUILDNUMBER ||
|
37 | process.env.CI_PIPELINE_IID;
|
38 | if (buildVersion == null) {
|
39 | buildVersion = this.version;
|
40 | if (!builder_util_1.isEmptyOrSpaces(this.buildNumber)) {
|
41 | buildVersion += `.${this.buildNumber}`;
|
42 | }
|
43 | }
|
44 | this.buildVersion = buildVersion;
|
45 | if (info.metadata.shortVersion) {
|
46 | this.shortVersion = info.metadata.shortVersion;
|
47 | }
|
48 | if (info.metadata.shortVersionWindows) {
|
49 | this.shortVersionWindows = info.metadata.shortVersionWindows;
|
50 | }
|
51 | this.productName = info.config.productName || info.metadata.productName || info.metadata.name;
|
52 | this.sanitizedProductName = filename_1.sanitizeFileName(this.productName);
|
53 | this.productFilename = (platformSpecificOptions === null || platformSpecificOptions === void 0 ? void 0 : platformSpecificOptions.executableName) != null ? filename_1.sanitizeFileName(platformSpecificOptions.executableName) : this.sanitizedProductName;
|
54 | }
|
55 | get channel() {
|
56 | const prereleaseInfo = semver_1.prerelease(this.version);
|
57 | if (prereleaseInfo != null && prereleaseInfo.length > 0) {
|
58 | return prereleaseInfo[0];
|
59 | }
|
60 | return null;
|
61 | }
|
62 | getVersionInWeirdWindowsForm(isSetBuildNumber = true) {
|
63 | const parsedVersion = new semver_1.SemVer(this.version);
|
64 |
|
65 | let buildNumber = isSetBuildNumber ? this.buildNumber : null;
|
66 | if (buildNumber == null || !/^\d+$/.test(buildNumber)) {
|
67 | buildNumber = "0";
|
68 | }
|
69 | return `${parsedVersion.major}.${parsedVersion.minor}.${parsedVersion.patch}.${buildNumber}`;
|
70 | }
|
71 | get notNullDevMetadata() {
|
72 | return this.info.devMetadata || {};
|
73 | }
|
74 | get companyName() {
|
75 | const author = this.info.metadata.author || this.notNullDevMetadata.author;
|
76 | return author == null ? null : author.name;
|
77 | }
|
78 | get id() {
|
79 | let appId = null;
|
80 | for (const options of [this.platformSpecificOptions, this.info.config]) {
|
81 | if (options != null && appId == null) {
|
82 | appId = options.appId;
|
83 | }
|
84 | }
|
85 | const generateDefaultAppId = () => {
|
86 | const info = this.info;
|
87 | return `${info.framework.defaultAppIdPrefix}${info.metadata.name.toLowerCase()}`;
|
88 | };
|
89 | if (appId != null && (appId === "your.id" || builder_util_1.isEmptyOrSpaces(appId))) {
|
90 | const incorrectAppId = appId;
|
91 | appId = generateDefaultAppId();
|
92 | builder_util_1.log.warn(`do not use "${incorrectAppId}" as appId, "${appId}" will be used instead`);
|
93 | }
|
94 | return appId == null ? generateDefaultAppId() : appId;
|
95 | }
|
96 | get macBundleIdentifier() {
|
97 | return filterCFBundleIdentifier(this.id);
|
98 | }
|
99 | get name() {
|
100 | return this.info.metadata.name;
|
101 | }
|
102 | get linuxPackageName() {
|
103 | const name = this.name;
|
104 |
|
105 | return name.startsWith("@") ? this.sanitizedProductName : name;
|
106 | }
|
107 | get sanitizedName() {
|
108 | return filename_1.sanitizeFileName(this.name);
|
109 | }
|
110 | get updaterCacheDirName() {
|
111 | return this.sanitizedName.toLowerCase() + "-updater";
|
112 | }
|
113 | get copyright() {
|
114 | const copyright = this.info.config.copyright;
|
115 | if (copyright != null) {
|
116 | return macroExpander_1.expandMacro(copyright, null, this);
|
117 | }
|
118 | return `Copyright © ${new Date().getFullYear()} ${this.companyName || this.productName}`;
|
119 | }
|
120 | async computePackageUrl() {
|
121 | const url = this.info.metadata.homepage || this.notNullDevMetadata.homepage;
|
122 | if (url != null) {
|
123 | return url;
|
124 | }
|
125 | const info = await this.info.repositoryInfo;
|
126 | return info == null || info.type !== "github" ? null : `https://${info.domain}/${info.user}/${info.project}`;
|
127 | }
|
128 | }
|
129 | exports.AppInfo = AppInfo;
|
130 |
|
131 | function filterCFBundleIdentifier(identifier) {
|
132 |
|
133 |
|
134 | return identifier.replace(/ /g, "-").replace(/[^a-zA-Z0-9.-]/g, "");
|
135 | }
|
136 | exports.filterCFBundleIdentifier = filterCFBundleIdentifier;
|
137 |
|
\ | No newline at end of file |