distapp 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/cli.mjs +56 -9
  2. package/package.json +2 -2
package/cli.mjs CHANGED
@@ -20110,7 +20110,40 @@ var parse4 = (input) => {
20110
20110
 
20111
20111
  // utils/package-reader.ts
20112
20112
  var import_jszip = __toESM(require_lib3(), 1);
20113
- var readPackageFile = async (data) => {
20113
+
20114
+ // utils/utils.ts
20115
+ async function isZipFile(file) {
20116
+ const ZIP_SIGNATURE = [80, 75, 3, 4];
20117
+ let header;
20118
+ if (file instanceof File) {
20119
+ if (file.size < 4)
20120
+ return false;
20121
+ const buffer = await file.slice(0, 4).arrayBuffer();
20122
+ header = new Uint8Array(buffer);
20123
+ } else if (Buffer.isBuffer(file)) {
20124
+ if (file.length < 4)
20125
+ return false;
20126
+ header = new Uint8Array(file.slice(0, 4));
20127
+ } else {
20128
+ throw new TypeError("Unsupported file type");
20129
+ }
20130
+ return ZIP_SIGNATURE.every((byte, i2) => header[i2] === byte);
20131
+ }
20132
+
20133
+ // utils/package-reader.ts
20134
+ var readPackageFile = async (data, izZipPlatform) => {
20135
+ if (izZipPlatform) {
20136
+ const isActuallyZipFile = await isZipFile(data);
20137
+ if (!isActuallyZipFile) {
20138
+ throw "The file is not a zip file";
20139
+ }
20140
+ return {
20141
+ extension: "zip",
20142
+ versionCode: "",
20143
+ versionName: "",
20144
+ packageName: ""
20145
+ };
20146
+ }
20114
20147
  var fileZip = new import_jszip.default;
20115
20148
  await fileZip.loadAsync(data);
20116
20149
  var extension = "";
@@ -20225,7 +20258,7 @@ function normalizeError(error) {
20225
20258
  }
20226
20259
  }
20227
20260
  const message = error.response?._data?.message || error.response?.statusText || getFetchError()?.data?.message || getFetchError() || "Unexpected happen";
20228
- if (message.includes(`undefined (reading 'userId')`)) {
20261
+ if (typeof message === "string" && message.includes(`undefined (reading 'userId')`)) {
20229
20262
  return "Unauthorized. Try login again";
20230
20263
  }
20231
20264
  return message;
@@ -20258,11 +20291,21 @@ function getSizeFromFile(input) {
20258
20291
  }
20259
20292
  return sizeInBytes;
20260
20293
  }
20261
- async function uploadArtifact(file, filename, orgName, appName, releaseNotes, fileApk) {
20262
- const packageMetadata = await readPackageFile(file);
20294
+ async function uploadArtifact(file, filename, orgName, appName, releaseNotes, fileApk, versionMetadata) {
20295
+ const isZipPlatform = filename.endsWith(".zip") ? true : false;
20296
+ filename = filename.substring(0, filename.lastIndexOf("."));
20297
+ const packageMetadata = await readPackageFile(file, isZipPlatform);
20263
20298
  if (!packageMetadata) {
20264
20299
  throw "Cannot read package file";
20265
20300
  }
20301
+ if (!packageMetadata.packageName) {
20302
+ if (!versionMetadata?.versionName || !versionMetadata.versionCode) {
20303
+ throw "Version Name and Version Code are required.";
20304
+ }
20305
+ packageMetadata.packageName = appName;
20306
+ packageMetadata.versionCode = versionMetadata.versionCode;
20307
+ packageMetadata.versionName = versionMetadata.versionName;
20308
+ }
20266
20309
  const fileSize = getSizeFromFile(file);
20267
20310
  const fileSizeApk = getSizeFromFile(fileApk);
20268
20311
  const { url, fileKey, apkUrl, uploadId } = await myFetch("/api/artifacts/upload-artifact", {
@@ -20273,7 +20316,8 @@ async function uploadArtifact(file, filename, orgName, appName, releaseNotes, fi
20273
20316
  hasFileApk: fileApk && fileApk !== "generate_bundle" ? true : false,
20274
20317
  filename,
20275
20318
  fileSize,
20276
- fileSizeApk
20319
+ fileSizeApk,
20320
+ isZipPlatform
20277
20321
  },
20278
20322
  onResponseError(r) {
20279
20323
  console.error("Error ", normalizeError(r));
@@ -20661,7 +20705,7 @@ async function extractAabToApk(aabPath, bundleKeystoreFetcher) {
20661
20705
  }
20662
20706
 
20663
20707
  // cli/commands/distribute.ts
20664
- import { basename as basename2, extname as extname2 } from "path";
20708
+ import { basename as basename2 } from "path";
20665
20709
  function slugToOrgApp(slug) {
20666
20710
  const slugPath = slug.split("/");
20667
20711
  return {
@@ -20669,12 +20713,12 @@ function slugToOrgApp(slug) {
20669
20713
  appName: slugPath[1]
20670
20714
  };
20671
20715
  }
20672
- var distribute = new Command("distribute").requiredOption("--slug <string>", "Slug of you app").requiredOption("--file <string>", "File path to your app").requiredOption("--api-key <string>").option("--release-notes <string>").option("--url <url>").option("--group <string...>").action(async (options) => {
20716
+ var distribute = new Command("distribute").requiredOption("--slug <string>", "Slug of you app").requiredOption("--file <string>", "File path to your app").requiredOption("--api-key <string>").option("--release-notes <string>").option("--url <url>").option("--group <string...>").option("--version-name <string>", "Version name of your desktop app (e.g v1.0.0)").option("--version-code <string>", "Version code of your desktop app (e.g 1)").action(async (options) => {
20673
20717
  const optUrl = options.url || process.env.DISTAPP_CLI_URL || "https://distapp.lhf.my.id";
20674
20718
  updateMyFetch(options.apiKey, optUrl);
20675
20719
  const { orgName, appName } = slugToOrgApp(options.slug);
20676
20720
  const filePath = resolve(options.file);
20677
- const filename = basename2(filePath, extname2(filePath));
20721
+ const filename = basename2(filePath);
20678
20722
  const file = await promises3.readFile(filePath);
20679
20723
  console.log("Distributing", {
20680
20724
  filePath
@@ -20689,7 +20733,10 @@ var distribute = new Command("distribute").requiredOption("--slug <string>", "Sl
20689
20733
  disposeBundle = dispose;
20690
20734
  }
20691
20735
  const bundleApkFile = bundleApkPath ? await promises3.readFile(bundleApkPath) : undefined;
20692
- const { artifactId } = await uploadArtifact(file, filename, orgName, appName, options.releaseNotes ? options.releaseNotes : null, bundleApkFile);
20736
+ const { artifactId } = await uploadArtifact(file, filename, orgName, appName, options.releaseNotes ? options.releaseNotes : null, bundleApkFile, options.versionCode && options.versionName ? {
20737
+ versionCode: options.versionCode,
20738
+ versionName: options.versionName
20739
+ } : undefined);
20693
20740
  const groupNames = options.group;
20694
20741
  let updateToGroup = false;
20695
20742
  if (artifactId && groupNames && groupNames.length) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "distapp",
3
- "version": "1.0.4",
4
- "description": "Manage and distribute Android or iOS app",
3
+ "version": "1.0.5",
4
+ "description": "Manage and distribute Android, iOS and Desktop app",
5
5
  "main": "cli.mjs",
6
6
  "bin": {
7
7
  "distapp": "./cli.mjs"