chore: cleanup

This commit is contained in:
Nathan Walker
2025-07-14 17:40:50 -07:00
parent b2cfc8045b
commit 7bc57216c0
10 changed files with 69 additions and 150 deletions

View File

@ -73,7 +73,7 @@ export class FileSystemEntity {
/** /**
* Contains Android-specific the file system helpers. * Contains Android-specific the file system helpers.
*/ */
class Android { declare class Android {
createFile(options: { relativePath?: string; name: string; mime: string; directory: AndroidDirectory }): File; createFile(options: { relativePath?: string; name: string; mime: string; directory: AndroidDirectory }): File;
} }
@ -81,7 +81,7 @@ class Android {
* Contains iOS-specific the file system helpers. * Contains iOS-specific the file system helpers.
*/ */
class iOS {} declare class iOS {}
/** /**
* Represents a File entity on the file system. * Represents a File entity on the file system.

View File

@ -1,3 +1,7 @@
import { HttpRequestOptions, HttpResponse, Headers } from '../http-interfaces'; import { HttpRequestOptions, HttpResponse, Headers } from '../http-interfaces';
/**
* Makes a generic http request using the provided options and returns a HttpResponse Object.
* @param options An object that specifies various request options.
*/
export const request: (options: HttpRequestOptions) => Promise<HttpResponse>; export const request: (options: HttpRequestOptions) => Promise<HttpResponse>;
export function addHeader(headers: Headers, key: string, value: string): void; export function addHeader(headers: Headers, key: string, value: string): void;

View File

@ -1,4 +1,7 @@
import type { ImageSource } from '../image-source'; import type { File } from '../file-system';
import type { ImageSource } from '../image-source';
import type { HttpResponse, HttpRequestOptions } from './http-interfaces';
export { request } from './http-request';
export * from './http-interfaces'; export * from './http-interfaces';
/** /**
@ -42,7 +45,7 @@ export function getImage(options: HttpRequestOptions): Promise<ImageSource>;
* @param url The URL to request from. * @param url The URL to request from.
* @param destinationFilePath Optional. The downloaded file path. * @param destinationFilePath Optional. The downloaded file path.
*/ */
export function getFile(url: string, destinationFilePath?: string): Promise<File>; export function getFile(url: string, destinationFilePath?: string): Promise<any>;
/** /**
* Downloads the content from the specified URL and attempts to save it as file. * Downloads the content from the specified URL and attempts to save it as file.
@ -62,105 +65,3 @@ export function getBinary(url: string): Promise<ArrayBuffer>;
* @param options An object that specifies various request options. * @param options An object that specifies various request options.
*/ */
export function getBinary(options: HttpRequestOptions): Promise<ArrayBuffer>; export function getBinary(options: HttpRequestOptions): Promise<ArrayBuffer>;
/**
* Makes a generic http request using the provided options and returns a HttpResponse Object.
* @param options An object that specifies various request options.
*/
export function request(options: HttpRequestOptions): Promise<HttpResponse>;
/**
* Provides options for the http requests.
*/
export interface HttpRequestOptions {
/**
* Gets or sets the request url.
*/
url: string;
/**
* Gets or sets the request method.
*/
method: string;
/**
* Gets or sets the request headers in JSON format.
*/
headers?: any;
/**
* Gets or sets the request body.
*/
content?: string | FormData | ArrayBuffer;
/**
* Gets or sets the request timeout in milliseconds.
*/
timeout?: number;
/**
* Gets or sets wether to *not* follow server's redirection responses.
*/
dontFollowRedirects?: boolean;
}
/**
* Encapsulates HTTP-response information from an HTTP-request.
*/
export interface HttpResponse {
/**
* Gets the response status code.
*/
statusCode: number;
/**
* Gets the response headers.
*/
headers: Headers;
/**
* Gets the response content.
*/
content?: HttpContent;
}
export type Headers = { [key: string]: string | string[] };
export enum HttpResponseEncoding {
UTF8,
GBK,
}
/**
* Encapsulates the content of an HttpResponse.
*/
export interface HttpContent {
/**
* Gets the response body as raw data.
*/
raw: any;
/**
* Gets the response body as ArrayBuffer
*/
toArrayBuffer: () => ArrayBuffer;
/**
* Gets the response body as string.
*/
toString: (encoding?: HttpResponseEncoding) => string;
/**
* Gets the response body as JSON object.
*/
toJSON: (encoding?: HttpResponseEncoding) => any;
/**
* Gets the response body as ImageSource.
*/
toImage: () => Promise<ImageSource>;
/**
* Gets the response body as file.
*/
toFile: (destinationFilePath?: string) => any /* File */;
}

View File

@ -1,6 +1,6 @@
import { setGetImageRequest, type ImageSourceLike } from './http-shared'; import { setGetImageRequest, type ImageSourceLike } from './http-shared';
import { request } from './http-request'; import { request } from './http-request';
export * from './http-request'; export { request } from './http-request';
export * from './http-interfaces'; export * from './http-interfaces';
export function getString(arg: any): Promise<string> { export function getString(arg: any): Promise<string> {

View File

@ -11,12 +11,11 @@ export * from './application';
export { androidRegisterBroadcastReceiver, androidUnregisterBroadcastReceiver, androidRegisteredReceivers, iosAddNotificationObserver, iosRemoveNotificationObserver, iosNotificationObservers } from './application/helpers'; export { androidRegisterBroadcastReceiver, androidUnregisterBroadcastReceiver, androidRegisteredReceivers, iosAddNotificationObserver, iosRemoveNotificationObserver, iosNotificationObservers } from './application/helpers';
export { getNativeApp, setNativeApp } from './application/helpers-common'; export { getNativeApp, setNativeApp } from './application/helpers-common';
export * as ApplicationSettings from './application-settings'; export * as ApplicationSettings from './application-settings';
import * as Accessibility from './accessibility';
export namespace AccessibilityEvents { export namespace AccessibilityEvents {
export const accessibilityBlurEvent = Accessibility.accessibilityBlurEvent; export const accessibilityBlurEvent: 'accessibilityBlur';
export const accessibilityFocusEvent = Accessibility.accessibilityFocusEvent; export const accessibilityFocusEvent: 'accessibilityFocus';
export const accessibilityFocusChangedEvent = Accessibility.accessibilityFocusChangedEvent; export const accessibilityFocusChangedEvent: 'accessibilityFocusChanged';
export const accessibilityPerformEscapeEvent = Accessibility.accessibilityPerformEscapeEvent; export const accessibilityPerformEscapeEvent: 'accessibilityPerformEscape';
} }
export { AccessibilityLiveRegion, AccessibilityRole, AccessibilityState, AccessibilityTrait, FontScaleCategory } from './accessibility'; export { AccessibilityLiveRegion, AccessibilityRole, AccessibilityState, AccessibilityTrait, FontScaleCategory } from './accessibility';
export { Color } from './color'; export { Color } from './color';
@ -37,7 +36,8 @@ export type { PropertyChangeData, EventData, EventDataValue } from './data/obser
export { VirtualArray } from './data/virtual-array'; export { VirtualArray } from './data/virtual-array';
export type { ItemsLoading } from './data/virtual-array'; export type { ItemsLoading } from './data/virtual-array';
export { File, FileSystemEntity, Folder, knownFolders, path, getFileAccess, AndroidDirectory } from './file-system'; export { File, FileSystemEntity, Folder, knownFolders, path, getFileAccess, AndroidDirectory } from './file-system';
export type { HttpRequestOptions, HttpResponse, Headers, HttpResponseEncoding, HttpContent } from './http'; export type { HttpRequestOptions, HttpResponse, Headers, HttpContent } from './http/http-interfaces';
export { HttpResponseEncoding } from './http/http-interfaces';
export * as Http from './http'; export * as Http from './http';
export { ImageAsset } from './image-asset'; export { ImageAsset } from './image-asset';
export type { ImageAssetOptions } from './image-asset'; export type { ImageAssetOptions } from './image-asset';

View File

@ -26,7 +26,8 @@ export type { PropertyChangeData, EventData } from './data/observable';
export { VirtualArray } from './data/virtual-array'; export { VirtualArray } from './data/virtual-array';
export type { ItemsLoading } from './data/virtual-array'; export type { ItemsLoading } from './data/virtual-array';
export { File, FileSystemEntity, Folder, knownFolders, path, getFileAccess, AndroidDirectory } from './file-system'; export { File, FileSystemEntity, Folder, knownFolders, path, getFileAccess, AndroidDirectory } from './file-system';
export type { HttpRequestOptions, HttpResponse, Headers, HttpResponseEncoding, HttpContent } from './http'; export type { HttpRequestOptions, HttpResponse, Headers, HttpContent } from './http/http-interfaces';
export { HttpResponseEncoding } from './http/http-interfaces';
export * as Http from './http'; export * as Http from './http';
export { ImageAsset } from './image-asset'; export { ImageAsset } from './image-asset';
export type { ImageAssetOptions } from './image-asset'; export type { ImageAssetOptions } from './image-asset';

View File

@ -4,9 +4,17 @@
"sourceRoot": "packages/core", "sourceRoot": "packages/core",
"projectType": "library", "projectType": "library",
"generators": {}, "generators": {},
"namedInputs": { "default": ["{projectRoot}/**/*"], "production": ["!{projectRoot}/**/*.spec.ts"] }, "namedInputs": {
"default": ["{projectRoot}/**/*"],
"production": ["!{projectRoot}/**/*.spec.ts"]
},
"targets": { "targets": {
"lint": { "executor": "@nx/eslint:lint", "options": { "lintFilePatterns": ["packages/core/**/*.ts", "packages/core/references.d.ts", "packages/core/**/*.spec.ts", "packages/core/**/*.spec.tsx", "packages/core/**/*.spec.js", "packages/core/**/*.spec.jsx", "packages/core/**/*.d.ts"] } }, "lint": {
"executor": "@nx/eslint:lint",
"options": {
"lintFilePatterns": ["packages/core/**/*.ts", "packages/core/references.d.ts", "packages/core/**/*.spec.ts", "packages/core/**/*.spec.tsx", "packages/core/**/*.spec.js", "packages/core/**/*.spec.jsx", "packages/core/**/*.d.ts"]
}
},
"build": { "build": {
"executor": "@nx/js:tsc", "executor": "@nx/js:tsc",
"inputs": ["default", "^production"], "inputs": ["default", "^production"],
@ -16,11 +24,41 @@
"outputPath": "{workspaceRoot}/dist/packages/core", "outputPath": "{workspaceRoot}/dist/packages/core",
"rootDir": "{projectRoot}", "rootDir": "{projectRoot}",
"main": "{projectRoot}/index.ts", "main": "{projectRoot}/index.ts",
"assets": ["{workspaceRoot}/LICENSE", "{projectRoot}/README.md", "{projectRoot}/global-types.d.ts", "{projectRoot}/fetch/LICENSE", { "glob": "**/*", "input": "{projectRoot}/js-libs/", "output": "./js-libs/" }, { "glob": "**/*", "input": "{projectRoot}/cli-hooks/", "output": "./cli-hooks/" }, { "glob": "**/*", "input": "{projectRoot}/platforms/", "output": "./platforms/" }, { "glob": "**/*.d.ts", "input": "{projectRoot}/", "output": "./" }] "assets": [
"{workspaceRoot}/LICENSE",
"{projectRoot}/README.md",
"{projectRoot}/global-types.d.ts",
"{projectRoot}/fetch/LICENSE",
{
"glob": "**/*",
"input": "{projectRoot}/js-libs/",
"output": "./js-libs/"
},
{
"glob": "**/*",
"input": "{projectRoot}/cli-hooks/",
"output": "./cli-hooks/"
},
{
"glob": "**/*",
"input": "{projectRoot}/platforms/",
"output": "./platforms/"
},
{
"glob": "**/*.d.ts",
"input": "{projectRoot}/",
"output": "./"
}
]
}, },
"dependsOn": ["^build"] "dependsOn": ["^build"]
}, },
"build.npm": { "executor": "nx:run-commands", "options": { "commands": ["node tools/scripts/build-finish.ts core"], "parallel": false }, "outputs": ["{workspaceRoot}/dist/packages/core"], "dependsOn": [{ "target": "build" }] }, "test": {
"test": { "executor": "@nx/vite:test", "outputs": ["{options.reportsDirectory}"], "options": { "reportsDirectory": "../../coverage/packages/core" } } "executor": "@nx/vite:test",
"outputs": ["{options.reportsDirectory}"],
"options": {
"reportsDirectory": "../../coverage/packages/core"
}
}
} }
} }

View File

@ -2,6 +2,7 @@
import { defineConfig } from 'vite'; import { defineConfig } from 'vite';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
import { fileURLToPath, URL } from 'node:url';
export default defineConfig({ export default defineConfig({
root: __dirname, root: __dirname,
@ -13,6 +14,10 @@ export default defineConfig({
// }, // },
resolve: { resolve: {
extensions: ['.ts', '.ios.ts'], extensions: ['.ts', '.ios.ts'],
alias: {
// ~ at import root → /absolute/path/to/src
'~': fileURLToPath(new URL('./', import.meta.url)),
},
}, },
test: { test: {
watch: false, watch: false,

View File

@ -1,4 +1,4 @@
import type { HttpRequestOptions, HttpResponse } from '../http'; import type { HttpRequestOptions, HttpResponse } from '../http/http-interfaces';
import { request } from '../http'; import { request } from '../http';
import { isString, isFunction } from '../utils/types'; import { isString, isFunction } from '../utils/types';
import { Trace } from '../trace'; import { Trace } from '../trace';

View File

@ -1,30 +0,0 @@
const path = require('path');
const fs = require('fs-extra');
const { serializeJson, parseJson } = require('@nx/devkit');
const rootDir = path.resolve(path.join(__dirname, '..', '..'));
const cmdArgs = process.argv.slice(2);
const packageName = cmdArgs[0];
const publish = cmdArgs[1] === 'publish';
const packagePath = path.join('packages', packageName, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packagePath));
const npmPackageName = packageJson.name;
console.log(`Building ${npmPackageName}...${publish ? 'and publishing.' : ''}`);
// function cleanPackage() {
// // helps remove unwanted properties which may be added by other tooling
// const packageJsonPath = path.resolve(rootDir, 'dist', 'packages', packageName, 'package.json');
// let packageJson = fs.readFileSync(packageJsonPath, { encoding: 'utf-8' });
// if (packageJson) {
// packageJson = parseJson(packageJson);
// // we don't need module or type properties at the moment
// delete packageJson['module'];
// delete packageJson['type'];
// fs.writeFileSync(packageJsonPath, serializeJson(packageJson));
// }
// }
// cleanPackage();
console.log(`${npmPackageName} ready to publish.`);