easc 0.0.1

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.
@@ -0,0 +1,164 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { IAppJson } from "./runtime";
4
+ import { Platform, PlatformType } from "../enums/platform";
5
+
6
+ export interface IMetadata {
7
+ fileMetadata?: {
8
+ [Platform.iOS]?: {
9
+ assets: Array<{ path: string }>;
10
+ };
11
+ [Platform.Android]?: {
12
+ assets: Array<{ path: string }>;
13
+ };
14
+ };
15
+ }
16
+
17
+ /**
18
+ * Read and parse app.json file
19
+ */
20
+ export function readAppJson(appDir: string = process.cwd()): IAppJson {
21
+ const appJsonPath = path.join(appDir, "app.json");
22
+
23
+ if (!fs.existsSync(appJsonPath)) {
24
+ throw new Error(`app.json not found in ${appDir}`);
25
+ }
26
+
27
+ try {
28
+ const content = fs.readFileSync(appJsonPath, "utf-8");
29
+ return JSON.parse(content);
30
+ } catch (error) {
31
+ throw new Error(`Failed to parse app.json: ${error}`);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Read and parse metadata.json from the export directory
37
+ */
38
+ export function readMetadata(exportDir: string): IMetadata {
39
+ const metadataPath = path.join(exportDir, "metadata.json");
40
+
41
+ if (!fs.existsSync(metadataPath)) {
42
+ throw new Error(
43
+ `metadata.json not found in ${exportDir}. Did you run 'expo export'?`
44
+ );
45
+ }
46
+
47
+ try {
48
+ const content = fs.readFileSync(metadataPath, "utf-8");
49
+ return JSON.parse(content);
50
+ } catch (error) {
51
+ throw new Error(`Failed to parse metadata.json: ${error}`);
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Find the bundle file for a platform
57
+ */
58
+ export function findBundleFile(
59
+ exportDir: string,
60
+ platform: PlatformType
61
+ ): string {
62
+ const bundlePath = path.join(exportDir, `_expo/static/js/${platform}`);
63
+
64
+ if (!fs.existsSync(bundlePath)) {
65
+ throw new Error(`Bundle directory not found: ${bundlePath}`);
66
+ }
67
+
68
+ const bundleFiles = fs
69
+ .readdirSync(bundlePath)
70
+ .filter((f) => f.startsWith("entry-") && f.endsWith(".hbc"));
71
+
72
+ if (bundleFiles.length === 0) {
73
+ throw new Error(`No bundle found for ${platform}`);
74
+ }
75
+
76
+ return path.join(bundlePath, bundleFiles[0]);
77
+ }
78
+
79
+ /**
80
+ * Get asset files for a platform
81
+ */
82
+ export function getAssetFiles(
83
+ exportDir: string,
84
+ metadata: IMetadata,
85
+ platform: PlatformType
86
+ ): string[] {
87
+ const assetsPath = path.join(exportDir, "assets");
88
+
89
+ if (!fs.existsSync(assetsPath)) {
90
+ return [];
91
+ }
92
+
93
+ const platformMetadata =
94
+ platform === Platform.iOS
95
+ ? metadata.fileMetadata?.[Platform.iOS]
96
+ : metadata.fileMetadata?.[Platform.Android];
97
+ const platformAssets = platformMetadata?.assets || [];
98
+
99
+ if (platformAssets.length === 0) {
100
+ return [];
101
+ }
102
+
103
+ const platformAssetFiles = new Set(
104
+ platformAssets.map((asset) => path.basename(asset.path))
105
+ );
106
+
107
+ const assetFiles = fs.readdirSync(assetsPath);
108
+ const validAssets: string[] = [];
109
+
110
+ assetFiles.forEach((assetFile) => {
111
+ const assetPath = path.join(assetsPath, assetFile);
112
+ if (fs.statSync(assetPath).isFile() && platformAssetFiles.has(assetFile)) {
113
+ validAssets.push(assetPath);
114
+ }
115
+ });
116
+
117
+ return validAssets;
118
+ }
119
+
120
+ /**
121
+ * Check if the export directory exists and has been built
122
+ * Supports custom export directories (EAS-compatible)
123
+ */
124
+ export function checkExportDirectory(
125
+ exportDir: string,
126
+ appDir: string = process.cwd()
127
+ ): string {
128
+ // If exportDir is relative, resolve it from appDir
129
+ const resolvedExportDir = path.isAbsolute(exportDir)
130
+ ? exportDir
131
+ : path.join(appDir, exportDir);
132
+
133
+ if (!fs.existsSync(resolvedExportDir)) {
134
+ throw new Error(
135
+ `Export directory not found: ${resolvedExportDir}\n` +
136
+ `Run 'npx expo export' or use --export-dir to specify a different directory.`
137
+ );
138
+ }
139
+
140
+ // Check for expected structure
141
+ const expectedPaths = [
142
+ path.join(resolvedExportDir, "metadata.json"),
143
+ path.join(resolvedExportDir, "_expo"),
144
+ ];
145
+
146
+ for (const expectedPath of expectedPaths) {
147
+ if (!fs.existsSync(expectedPath)) {
148
+ throw new Error(
149
+ `Invalid export directory structure in: ${resolvedExportDir}\n` +
150
+ `Run 'npx expo export' to generate a valid export.`
151
+ );
152
+ }
153
+ }
154
+
155
+ return resolvedExportDir;
156
+ }
157
+
158
+ /**
159
+ * Legacy wrapper for backwards compatibility
160
+ * @deprecated Use checkExportDirectory instead
161
+ */
162
+ export function checkDistDirectory(appDir: string = process.cwd()): string {
163
+ return checkExportDirectory("dist", appDir);
164
+ }
@@ -0,0 +1,112 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { execSync } from "child_process";
3
+ import { getCommitHash, getShortCommitHash, isGitClean, getCurrentBranch } from "./git";
4
+
5
+ vi.mock("child_process", () => ({
6
+ execSync: vi.fn(),
7
+ }));
8
+
9
+ describe("Git utilities", () => {
10
+ beforeEach(() => {
11
+ vi.clearAllMocks();
12
+ });
13
+
14
+ describe("getCommitHash", () => {
15
+ it("should return the commit hash when in a git repo", () => {
16
+ const mockHash = "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0";
17
+ vi.mocked(execSync).mockReturnValue(mockHash + "\n");
18
+
19
+ expect(getCommitHash()).toBe(mockHash);
20
+ expect(execSync).toHaveBeenCalledWith("git rev-parse HEAD", {
21
+ cwd: process.cwd(),
22
+ encoding: "utf-8",
23
+ stdio: ["ignore", "pipe", "ignore"],
24
+ });
25
+ });
26
+
27
+ it("should return undefined when not in a git repo", () => {
28
+ vi.mocked(execSync).mockImplementation(() => {
29
+ throw new Error("Not a git repository");
30
+ });
31
+
32
+ expect(getCommitHash()).toBeUndefined();
33
+ });
34
+
35
+ it("should use custom working directory", () => {
36
+ const mockHash = "abcdef123456";
37
+ vi.mocked(execSync).mockReturnValue(mockHash);
38
+
39
+ getCommitHash("/custom/path");
40
+ expect(execSync).toHaveBeenCalledWith("git rev-parse HEAD", {
41
+ cwd: "/custom/path",
42
+ encoding: "utf-8",
43
+ stdio: ["ignore", "pipe", "ignore"],
44
+ });
45
+ });
46
+ });
47
+
48
+ describe("getShortCommitHash", () => {
49
+ it("should return the first 7 characters of the commit hash", () => {
50
+ const mockHash = "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0";
51
+ vi.mocked(execSync).mockReturnValue(mockHash);
52
+
53
+ expect(getShortCommitHash()).toBe("a1b2c3d");
54
+ });
55
+
56
+ it("should return undefined when not in a git repo", () => {
57
+ vi.mocked(execSync).mockImplementation(() => {
58
+ throw new Error("Not a git repository");
59
+ });
60
+
61
+ expect(getShortCommitHash()).toBeUndefined();
62
+ });
63
+ });
64
+
65
+ describe("isGitClean", () => {
66
+ it("should return true when working directory is clean", () => {
67
+ vi.mocked(execSync).mockReturnValue("");
68
+
69
+ expect(isGitClean()).toBe(true);
70
+ expect(execSync).toHaveBeenCalledWith("git status --porcelain", {
71
+ cwd: process.cwd(),
72
+ encoding: "utf-8",
73
+ stdio: ["ignore", "pipe", "ignore"],
74
+ });
75
+ });
76
+
77
+ it("should return false when there are uncommitted changes", () => {
78
+ vi.mocked(execSync).mockReturnValue("M file.txt\n");
79
+
80
+ expect(isGitClean()).toBe(false);
81
+ });
82
+
83
+ it("should return false when not in a git repo", () => {
84
+ vi.mocked(execSync).mockImplementation(() => {
85
+ throw new Error("Not a git repository");
86
+ });
87
+
88
+ expect(isGitClean()).toBe(false);
89
+ });
90
+ });
91
+
92
+ describe("getCurrentBranch", () => {
93
+ it("should return the current branch name", () => {
94
+ vi.mocked(execSync).mockReturnValue("main\n");
95
+
96
+ expect(getCurrentBranch()).toBe("main");
97
+ expect(execSync).toHaveBeenCalledWith("git rev-parse --abbrev-ref HEAD", {
98
+ cwd: process.cwd(),
99
+ encoding: "utf-8",
100
+ stdio: ["ignore", "pipe", "ignore"],
101
+ });
102
+ });
103
+
104
+ it("should return undefined when not in a git repo", () => {
105
+ vi.mocked(execSync).mockImplementation(() => {
106
+ throw new Error("Not a git repository");
107
+ });
108
+
109
+ expect(getCurrentBranch()).toBeUndefined();
110
+ });
111
+ });
112
+ });
@@ -0,0 +1,73 @@
1
+ import { execSync } from "child_process";
2
+
3
+ /**
4
+ * Get the current git commit hash
5
+ *
6
+ * @param cwd - Working directory (defaults to process.cwd())
7
+ * @returns The commit hash or undefined if not in a git repo
8
+ */
9
+ export function getCommitHash(cwd: string = process.cwd()): string | undefined {
10
+ try {
11
+ const hash = execSync("git rev-parse HEAD", {
12
+ cwd,
13
+ encoding: "utf-8",
14
+ stdio: ["ignore", "pipe", "ignore"],
15
+ }).trim();
16
+ return hash;
17
+ } catch {
18
+ return undefined;
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Get the short version of the commit hash (7 characters)
24
+ *
25
+ * @param cwd - Working directory (defaults to process.cwd())
26
+ * @returns The short commit hash or undefined if not in a git repo
27
+ */
28
+ export function getShortCommitHash(
29
+ cwd: string = process.cwd()
30
+ ): string | undefined {
31
+ const hash = getCommitHash(cwd);
32
+ return hash ? hash.substring(0, 7) : undefined;
33
+ }
34
+
35
+ /**
36
+ * Check if the git working directory is clean
37
+ *
38
+ * @param cwd - Working directory (defaults to process.cwd())
39
+ * @returns True if clean, false if there are uncommitted changes
40
+ */
41
+ export function isGitClean(cwd: string = process.cwd()): boolean {
42
+ try {
43
+ const status = execSync("git status --porcelain", {
44
+ cwd,
45
+ encoding: "utf-8",
46
+ stdio: ["ignore", "pipe", "ignore"],
47
+ }).trim();
48
+ return status === "";
49
+ } catch {
50
+ return false;
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Get the current git branch name
56
+ *
57
+ * @param cwd - Working directory (defaults to process.cwd())
58
+ * @returns The branch name or undefined if not in a git repo
59
+ */
60
+ export function getCurrentBranch(
61
+ cwd: string = process.cwd()
62
+ ): string | undefined {
63
+ try {
64
+ const branch = execSync("git rev-parse --abbrev-ref HEAD", {
65
+ cwd,
66
+ encoding: "utf-8",
67
+ stdio: ["ignore", "pipe", "ignore"],
68
+ }).trim();
69
+ return branch;
70
+ } catch {
71
+ return undefined;
72
+ }
73
+ }
@@ -0,0 +1,121 @@
1
+ import chalk from "chalk";
2
+ import ora, { Ora } from "ora";
3
+
4
+ export class Logger {
5
+ private spinner: Ora | null = null;
6
+
7
+ constructor() {}
8
+
9
+ /**
10
+ * Log an informational message
11
+ */
12
+ info(message: string): void {
13
+ console.log(chalk.blue("ℹ"), message);
14
+ }
15
+
16
+ /**
17
+ * Log a success message
18
+ */
19
+ success(message: string): void {
20
+ console.log(chalk.green("✓"), message);
21
+ }
22
+
23
+ /**
24
+ * Log an error message
25
+ */
26
+ error(message: string): void {
27
+ console.error(chalk.red("✗"), message);
28
+ }
29
+
30
+ /**
31
+ * Log a warning message
32
+ */
33
+ warn(message: string): void {
34
+ console.warn(chalk.yellow("⚠"), message);
35
+ }
36
+
37
+ /**
38
+ * Start a spinner with a message
39
+ */
40
+ startSpinner(message: string): void {
41
+ this.spinner = ora(message).start();
42
+ }
43
+
44
+ /**
45
+ * Update spinner text
46
+ */
47
+ updateSpinner(message: string): void {
48
+ if (this.spinner) {
49
+ this.spinner.text = message;
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Stop spinner with success
55
+ */
56
+ succeedSpinner(message?: string): void {
57
+ if (this.spinner) {
58
+ this.spinner.succeed(message);
59
+ this.spinner = null;
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Stop spinner with failure
65
+ */
66
+ failSpinner(message?: string): void {
67
+ if (this.spinner) {
68
+ this.spinner.fail(message);
69
+ this.spinner = null;
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Stop spinner without status
75
+ */
76
+ stopSpinner(): void {
77
+ if (this.spinner) {
78
+ this.spinner.stop();
79
+ this.spinner = null;
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Log a section header
85
+ */
86
+ section(title: string): void {
87
+ console.log(`\n${chalk.bold(title)}`);
88
+ }
89
+
90
+ /**
91
+ * Display a simple two-column table
92
+ */
93
+ table(rows: Array<[string, string | number | undefined]>): void {
94
+ const maxKeyLength = Math.max(...rows.map(([key]) => key.length));
95
+
96
+ rows.forEach(([key, value]) => {
97
+ const paddedKey = key.padEnd(maxKeyLength);
98
+ console.log(` ${chalk.gray(paddedKey + ":")} ${value}`);
99
+ });
100
+ }
101
+
102
+ /**
103
+ * Create a box around text
104
+ */
105
+ box(text: string): void {
106
+ const lines = text.split("\n");
107
+ const maxLength = Math.max(...lines.map((l) => l.length));
108
+ const top = "┌" + "─".repeat(maxLength + 2) + "┐";
109
+ const bottom = "└" + "─".repeat(maxLength + 2) + "┘";
110
+
111
+ console.log(chalk.gray(top));
112
+ lines.forEach((line) => {
113
+ const padding = " ".repeat(maxLength - line.length);
114
+ console.log(chalk.gray("│ ") + line + padding + chalk.gray(" │"));
115
+ });
116
+ console.log(chalk.gray(bottom));
117
+ }
118
+ }
119
+
120
+ // Export singleton instance
121
+ export let logger = new Logger();
@@ -0,0 +1,99 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { resolveRuntimeVersion, getPlatforms, type IAppJson } from "./runtime";
3
+
4
+ describe("resolveRuntimeVersion", () => {
5
+ it("should return string runtime version directly", () => {
6
+ const appJson: IAppJson = {
7
+ expo: {
8
+ runtimeVersion: "1.0.0",
9
+ },
10
+ };
11
+ expect(resolveRuntimeVersion(appJson)).toBe("1.0.0");
12
+ });
13
+
14
+ it("should resolve appVersion policy", () => {
15
+ const appJson: IAppJson = {
16
+ expo: {
17
+ runtimeVersion: { policy: "appVersion" },
18
+ version: "2.1.0",
19
+ },
20
+ };
21
+ expect(resolveRuntimeVersion(appJson)).toBe("2.1.0");
22
+ });
23
+
24
+ it("should throw error when appVersion policy is used but version is missing", () => {
25
+ const appJson: IAppJson = {
26
+ expo: {
27
+ runtimeVersion: { policy: "appVersion" },
28
+ },
29
+ };
30
+ expect(() => resolveRuntimeVersion(appJson)).toThrow(
31
+ 'runtimeVersion policy is "appVersion" but no version field found in app.json'
32
+ );
33
+ });
34
+
35
+ it("should throw error for invalid runtime version configuration", () => {
36
+ const appJson: IAppJson = {
37
+ expo: {},
38
+ };
39
+ expect(() => resolveRuntimeVersion(appJson)).toThrow(
40
+ "Invalid runtimeVersion configuration"
41
+ );
42
+ });
43
+
44
+ it("should throw error for unsupported policy", () => {
45
+ const appJson: IAppJson = {
46
+ expo: {
47
+ runtimeVersion: { policy: "unsupported" } as any,
48
+ },
49
+ };
50
+ expect(() => resolveRuntimeVersion(appJson)).toThrow(
51
+ "Invalid runtimeVersion configuration"
52
+ );
53
+ });
54
+ });
55
+
56
+ describe("getPlatforms", () => {
57
+ it("should return specified platforms", () => {
58
+ const appJson: IAppJson = {
59
+ expo: {
60
+ platforms: ["ios", "android"],
61
+ },
62
+ };
63
+ expect(getPlatforms(appJson)).toEqual(["ios", "android"]);
64
+ });
65
+
66
+ it("should default to both platforms when not specified", () => {
67
+ const appJson: IAppJson = {
68
+ expo: {},
69
+ };
70
+ expect(getPlatforms(appJson)).toEqual(["ios", "android"]);
71
+ });
72
+
73
+ it("should filter out invalid platforms", () => {
74
+ const appJson: IAppJson = {
75
+ expo: {
76
+ platforms: ["ios", "web", "android"],
77
+ },
78
+ };
79
+ expect(getPlatforms(appJson)).toEqual(["ios", "android"]);
80
+ });
81
+
82
+ it("should handle iOS-only", () => {
83
+ const appJson: IAppJson = {
84
+ expo: {
85
+ platforms: ["ios"],
86
+ },
87
+ };
88
+ expect(getPlatforms(appJson)).toEqual(["ios"]);
89
+ });
90
+
91
+ it("should handle Android-only", () => {
92
+ const appJson: IAppJson = {
93
+ expo: {
94
+ platforms: ["android"],
95
+ },
96
+ };
97
+ expect(getPlatforms(appJson)).toEqual(["android"]);
98
+ });
99
+ });
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Utilities for handling Expo runtime versions
3
+ */
4
+
5
+ import { PlatformType } from "../enums/platform";
6
+
7
+ export interface IAppJson {
8
+ expo: {
9
+ runtimeVersion?: string | { policy: string };
10
+ version?: string;
11
+ platforms?: string[];
12
+ };
13
+ }
14
+
15
+ /**
16
+ * Resolve the runtime version from app.json
17
+ * Supports both string values and policy objects
18
+ */
19
+ export function resolveRuntimeVersion(appJson: IAppJson): string {
20
+ const runtimeVersionConfig = appJson.expo.runtimeVersion;
21
+
22
+ // If it's a string, use it directly
23
+ if (typeof runtimeVersionConfig === "string") {
24
+ return runtimeVersionConfig;
25
+ }
26
+
27
+ // If it's an object with policy: appVersion
28
+ if (
29
+ typeof runtimeVersionConfig === "object" &&
30
+ runtimeVersionConfig?.policy === "appVersion"
31
+ ) {
32
+ const version = appJson.expo.version;
33
+ if (!version) {
34
+ throw new Error(
35
+ 'runtimeVersion policy is "appVersion" but no version field found in app.json'
36
+ );
37
+ }
38
+ return version;
39
+ }
40
+
41
+ throw new Error(
42
+ "Invalid runtimeVersion configuration in app.json. Must be either:\n" +
43
+ ' - A string: "runtimeVersion": "1.0.0"\n' +
44
+ ' - Policy object: "runtimeVersion": { "policy": "appVersion" }'
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Get platforms from app.json, defaulting to both iOS and Android
50
+ */
51
+ export function getPlatforms(appJson: IAppJson): PlatformType[] {
52
+ const platforms = appJson.expo.platforms || ["ios", "android"];
53
+ return platforms.filter(p => p === "ios" || p === "android") as PlatformType[];
54
+ }