From 03d41693cd5f61b4c4c0c7818296d13ef184c33a Mon Sep 17 00:00:00 2001 From: wangyue Date: Tue, 11 Feb 2025 14:31:47 +0800 Subject: [PATCH] chore: update example project Signed-off-by: wangyue --- .gitignore | 5 +- example/harmony/build-profile.template.json5 | 6 +- example/harmony/entry/oh-package.json5 | 4 +- .../resources/base/profile/main_pages.json | 5 + example/harmony/fs/.gitignore | 6 - example/harmony/fs/build-profile.json5 | 12 - example/harmony/fs/hvigorfile.ts | 6 - example/harmony/fs/index.ets | 7 - example/harmony/fs/oh-package.json5 | 10 - .../harmony/fs/src/main/cpp/CMakeLists.txt | 14 - example/harmony/fs/src/main/cpp/RNFSPackage.h | 18 - .../RNOH/generated/BaseReactNativeFsPackage.h | 65 -- .../generated/turbo_modules/ReactNativeFs.cpp | 35 -- .../generated/turbo_modules/ReactNativeFs.h | 16 - example/harmony/fs/src/main/ets/FsPackage.ts | 30 - .../harmony/fs/src/main/ets/FsTurboModule.ts | 571 ------------------ .../src/main/ets/generated/components/ts.ts | 5 - .../fs/src/main/ets/generated/index.ets | 5 - .../harmony/fs/src/main/ets/generated/ts.ts | 6 - .../generated/turboModules/ReactNativeFs.ts | 58 -- .../src/main/ets/generated/turboModules/ts.ts | 5 - example/harmony/fs/src/main/module.json5 | 12 - .../main/resources/base/element/color.json | 8 - .../main/resources/base/element/string.json | 16 - .../main/resources/en_US/element/string.json | 16 - .../main/resources/zh_CN/element/string.json | 16 - .../fs/src/ohosTest/ets/test/Ability.test.ets | 41 -- .../fs/src/ohosTest/ets/test/List.test.ets | 11 - .../ohosTest/ets/testability/TestAbility.ets | 56 -- .../ohosTest/ets/testability/pages/Index.ets | 23 - .../ets/testrunner/OpenHarmonyTestRunner.ets | 98 --- example/harmony/fs/src/ohosTest/module.json5 | 38 -- .../resources/base/element/color.json | 8 - .../resources/base/element/string.json | 16 - example/harmony/fs/src/test/List.test.ets | 11 - .../harmony/fs/src/test/LocalUnit.test.ets | 39 -- example/harmony/fs/ts.ts | 7 - example/package.json | 5 +- 38 files changed, 16 insertions(+), 1294 deletions(-) create mode 100644 example/harmony/entry/src/main/resources/base/profile/main_pages.json delete mode 100644 example/harmony/fs/.gitignore delete mode 100644 example/harmony/fs/build-profile.json5 delete mode 100644 example/harmony/fs/hvigorfile.ts delete mode 100644 example/harmony/fs/index.ets delete mode 100644 example/harmony/fs/oh-package.json5 delete mode 100644 example/harmony/fs/src/main/cpp/CMakeLists.txt delete mode 100644 example/harmony/fs/src/main/cpp/RNFSPackage.h delete mode 100644 example/harmony/fs/src/main/cpp/generated/RNOH/generated/BaseReactNativeFsPackage.h delete mode 100644 example/harmony/fs/src/main/cpp/generated/RNOH/generated/turbo_modules/ReactNativeFs.cpp delete mode 100644 example/harmony/fs/src/main/cpp/generated/RNOH/generated/turbo_modules/ReactNativeFs.h delete mode 100644 example/harmony/fs/src/main/ets/FsPackage.ts delete mode 100644 example/harmony/fs/src/main/ets/FsTurboModule.ts delete mode 100644 example/harmony/fs/src/main/ets/generated/components/ts.ts delete mode 100644 example/harmony/fs/src/main/ets/generated/index.ets delete mode 100644 example/harmony/fs/src/main/ets/generated/ts.ts delete mode 100644 example/harmony/fs/src/main/ets/generated/turboModules/ReactNativeFs.ts delete mode 100644 example/harmony/fs/src/main/ets/generated/turboModules/ts.ts delete mode 100644 example/harmony/fs/src/main/module.json5 delete mode 100644 example/harmony/fs/src/main/resources/base/element/color.json delete mode 100644 example/harmony/fs/src/main/resources/base/element/string.json delete mode 100644 example/harmony/fs/src/main/resources/en_US/element/string.json delete mode 100644 example/harmony/fs/src/main/resources/zh_CN/element/string.json delete mode 100644 example/harmony/fs/src/ohosTest/ets/test/Ability.test.ets delete mode 100644 example/harmony/fs/src/ohosTest/ets/test/List.test.ets delete mode 100644 example/harmony/fs/src/ohosTest/ets/testability/TestAbility.ets delete mode 100644 example/harmony/fs/src/ohosTest/ets/testability/pages/Index.ets delete mode 100644 example/harmony/fs/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets delete mode 100644 example/harmony/fs/src/ohosTest/module.json5 delete mode 100644 example/harmony/fs/src/ohosTest/resources/base/element/color.json delete mode 100644 example/harmony/fs/src/ohosTest/resources/base/element/string.json delete mode 100644 example/harmony/fs/src/test/List.test.ets delete mode 100644 example/harmony/fs/src/test/LocalUnit.test.ets delete mode 100644 example/harmony/fs/ts.ts diff --git a/.gitignore b/.gitignore index 97227df..1e21228 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,6 @@ build/ *.xcworkspace !default.xcworkspace xcuserdata -profile *.moved-aside DerivedData .idea/ @@ -24,4 +23,6 @@ Pods update-test.sh .vscode/ Session.vim -*.tgz \ No newline at end of file +*.tgz +package-lock.json +harmony/fs/oh-package-lock.json5 diff --git a/example/harmony/build-profile.template.json5 b/example/harmony/build-profile.template.json5 index 2614419..883483e 100644 --- a/example/harmony/build-profile.template.json5 +++ b/example/harmony/build-profile.template.json5 @@ -4,8 +4,8 @@ { "name": 'default', "signingConfig": 'default', - "compileSdkVersion": '5.0.0(12)', - "compatibleSdkVersion": '5.0.0(12)', + "compileSdkVersion": '5.0.1(13)', + "compatibleSdkVersion": '5.0.1(13)', "runtimeOS": 'HarmonyOS' }, ], @@ -34,7 +34,7 @@ }, { "name": "fs", - "srcPath": './fs' + "srcPath": '../../harmony/fs' } ], } \ No newline at end of file diff --git a/example/harmony/entry/oh-package.json5 b/example/harmony/entry/oh-package.json5 index 4e2abcf..85667bd 100644 --- a/example/harmony/entry/oh-package.json5 +++ b/example/harmony/entry/oh-package.json5 @@ -6,7 +6,7 @@ "version": "1.0.0", "dependencies": { "@rnoh/react-native-openharmony": "0.72.38", - "@react-native-ohos/react-native-fs": "file:../fs" -// "@react-native-ohos/react-native-fs": "file:../../node_modules/@react-native-ohos/react-native-fs/harmony/fs.har", +// "@react-native-ohos/react-native-fs": "file:../fs" + "@react-native-ohos/react-native-fs": "file:../../node_modules/@react-native-ohos/react-native-fs/harmony/fs.har", } } \ No newline at end of file diff --git a/example/harmony/entry/src/main/resources/base/profile/main_pages.json b/example/harmony/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000..1898d94 --- /dev/null +++ b/example/harmony/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/example/harmony/fs/.gitignore b/example/harmony/fs/.gitignore deleted file mode 100644 index e2713a2..0000000 --- a/example/harmony/fs/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/example/harmony/fs/build-profile.json5 b/example/harmony/fs/build-profile.json5 deleted file mode 100644 index 9c5ce9b..0000000 --- a/example/harmony/fs/build-profile.json5 +++ /dev/null @@ -1,12 +0,0 @@ -{ - "apiType": "stageMode", - - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] -} \ No newline at end of file diff --git a/example/harmony/fs/hvigorfile.ts b/example/harmony/fs/hvigorfile.ts deleted file mode 100644 index c4045ef..0000000 --- a/example/harmony/fs/hvigorfile.ts +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved - * Use of this source code is governed by a MIT license that can be - * found in the LICENSE file. - */ -export { harTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file diff --git a/example/harmony/fs/index.ets b/example/harmony/fs/index.ets deleted file mode 100644 index d6579ae..0000000 --- a/example/harmony/fs/index.ets +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved - * Use of this source code is governed by a MIT license that can be - * found in the LICENSE file. - */ - -export * from './ts' \ No newline at end of file diff --git a/example/harmony/fs/oh-package.json5 b/example/harmony/fs/oh-package.json5 deleted file mode 100644 index c7c2dad..0000000 --- a/example/harmony/fs/oh-package.json5 +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "@react-native-ohos/react-native-fs", - "version": "2.20.1-rc.2", - "description": "Please describe the basic information.", - "main": "index.ets", - "types": "module", - "dependencies": { - "@rnoh/react-native-openharmony": "0.72.38" - } -} \ No newline at end of file diff --git a/example/harmony/fs/src/main/cpp/CMakeLists.txt b/example/harmony/fs/src/main/cpp/CMakeLists.txt deleted file mode 100644 index 607ba12..0000000 --- a/example/harmony/fs/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.13) -set(CMAKE_VERBOSE_MAKEFILE on) -set(rnoh_fs_generated_dir "${CMAKE_CURRENT_SOURCE_DIR}/generated") - -file(GLOB rnoh_fs_SRC CONFIGURE_DEPENDS *.cpp) -file(GLOB_RECURSE rnoh_fs_generated_SRC "${rnoh_fs_generated_dir}/**/*.cpp") - -add_library(rnoh_fs SHARED ${rnoh_fs_SRC} ${rnoh_fs_generated_SRC}) -target_include_directories(rnoh_fs PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} - ${rnoh_fs_generated_dir} -) - -target_link_libraries(rnoh_fs PUBLIC rnoh) \ No newline at end of file diff --git a/example/harmony/fs/src/main/cpp/RNFSPackage.h b/example/harmony/fs/src/main/cpp/RNFSPackage.h deleted file mode 100644 index dab1595..0000000 --- a/example/harmony/fs/src/main/cpp/RNFSPackage.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved - * Use of this source code is governed by a MIT license that can be - * found in the LICENSE file. - */ -#pragma once - -#include "RNOH/generated/BaseReactNativeFsPackage.h" - -namespace rnoh { - -class RNFSPackage : public BaseReactNativeFsPackage { - using Super = BaseReactNativeFsPackage; - -public: - RNFSPackage(Package::Context ctx) : Super(ctx) {} -}; -} // namespace rnoh \ No newline at end of file diff --git a/example/harmony/fs/src/main/cpp/generated/RNOH/generated/BaseReactNativeFsPackage.h b/example/harmony/fs/src/main/cpp/generated/RNOH/generated/BaseReactNativeFsPackage.h deleted file mode 100644 index 56c68b9..0000000 --- a/example/harmony/fs/src/main/cpp/generated/RNOH/generated/BaseReactNativeFsPackage.h +++ /dev/null @@ -1,65 +0,0 @@ -/** - * This code was generated by "react-native codegen-lib-harmony" - */ - -#pragma once - -#include "RNOH/Package.h" -#include "RNOH/ArkTSTurboModule.h" -#include "RNOH/generated/turbo_modules/ReactNativeFs.h" - -namespace rnoh { - -class BaseReactNativeFsPackageTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate { - public: - SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override { - if (name == "ReactNativeFs") { - return std::make_shared(ctx, name); - } - return nullptr; - }; -}; - -class BaseReactNativeFsPackageEventEmitRequestHandler : public EventEmitRequestHandler { - public: - void handleEvent(Context const &ctx) override { - auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter(ctx.tag); - if (eventEmitter == nullptr) { - return; - } - - std::vector supportedEventNames = { - }; - if (std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) { - eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload)); - } - } -}; - - -class BaseReactNativeFsPackage : public Package { - public: - BaseReactNativeFsPackage(Package::Context ctx) : Package(ctx){}; - - std::unique_ptr createTurboModuleFactoryDelegate() override { - return std::make_unique(); - } - - std::vector createComponentDescriptorProviders() override { - return { - }; - } - - ComponentJSIBinderByString createComponentJSIBinderByName() override { - return { - }; - }; - - EventEmitRequestHandlers createEventEmitRequestHandlers() override { - return { - std::make_shared(), - }; - } -}; - -} // namespace rnoh diff --git a/example/harmony/fs/src/main/cpp/generated/RNOH/generated/turbo_modules/ReactNativeFs.cpp b/example/harmony/fs/src/main/cpp/generated/RNOH/generated/turbo_modules/ReactNativeFs.cpp deleted file mode 100644 index 84c80e0..0000000 --- a/example/harmony/fs/src/main/cpp/generated/RNOH/generated/turbo_modules/ReactNativeFs.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/** - * This code was generated by "react-native codegen-lib-harmony" - */ - -#include "ReactNativeFs.h" - -namespace rnoh { -using namespace facebook; - -ReactNativeFs::ReactNativeFs(const ArkTSTurboModule::Context ctx, const std::string name) : ArkTSTurboModule(ctx, name) { - methodMap_ = { - ARK_METHOD_METADATA(getConstants, 0), - ARK_ASYNC_METHOD_METADATA(readFile, 1), - ARK_ASYNC_METHOD_METADATA(exists, 1), - ARK_ASYNC_METHOD_METADATA(mkdir, 2), - ARK_ASYNC_METHOD_METADATA(appendFile, 3), - ARK_ASYNC_METHOD_METADATA(writeFile, 3), - ARK_ASYNC_METHOD_METADATA(readFileAssets, 1), - ARK_ASYNC_METHOD_METADATA(copyFile, 2), - ARK_ASYNC_METHOD_METADATA(unlink, 1), - ARK_ASYNC_METHOD_METADATA(hash, 2), - ARK_ASYNC_METHOD_METADATA(moveFile, 2), - ARK_ASYNC_METHOD_METADATA(read, 3), - ARK_ASYNC_METHOD_METADATA(write, 3), - ARK_ASYNC_METHOD_METADATA(stat, 1), - ARK_ASYNC_METHOD_METADATA(touch, 3), - ARK_ASYNC_METHOD_METADATA(downloadFile, 1), - ARK_ASYNC_METHOD_METADATA(readDir, 1), - ARK_ASYNC_METHOD_METADATA(existsAssets, 1), - ARK_METHOD_METADATA(addListener, 1), - ARK_METHOD_METADATA(removeListeners, 1), - }; -} - -} // namespace rnoh diff --git a/example/harmony/fs/src/main/cpp/generated/RNOH/generated/turbo_modules/ReactNativeFs.h b/example/harmony/fs/src/main/cpp/generated/RNOH/generated/turbo_modules/ReactNativeFs.h deleted file mode 100644 index fd1b48a..0000000 --- a/example/harmony/fs/src/main/cpp/generated/RNOH/generated/turbo_modules/ReactNativeFs.h +++ /dev/null @@ -1,16 +0,0 @@ -/** - * This code was generated by "react-native codegen-lib-harmony" - */ - -#pragma once - -#include "RNOH/ArkTSTurboModule.h" - -namespace rnoh { - -class JSI_EXPORT ReactNativeFs : public ArkTSTurboModule { - public: - ReactNativeFs(const ArkTSTurboModule::Context ctx, const std::string name); -}; - -} // namespace rnoh diff --git a/example/harmony/fs/src/main/ets/FsPackage.ts b/example/harmony/fs/src/main/ets/FsPackage.ts deleted file mode 100644 index a58cb55..0000000 --- a/example/harmony/fs/src/main/ets/FsPackage.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved - * Use of this source code is governed by a MIT license that can be - * found in the LICENSE file. - */ - -import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts'; -import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts'; -import { FsTurboModule } from './FsTurboModule'; - -class FsTurboModulesFactory extends TurboModulesFactory { - createTurboModule(name: string): TurboModule | null { - if (name === 'ReactNativeFs') { - // 上下文对象 - globalThis.uiAbilityContext = this.ctx.uiAbilityContext; - return new FsTurboModule(this.ctx); - } - return null; - } - - hasTurboModule(name: string): boolean { - return name === 'ReactNativeFs'; - } -} - -export class FsPackage extends RNPackage { - createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory { - return new FsTurboModulesFactory(ctx); - } -} diff --git a/example/harmony/fs/src/main/ets/FsTurboModule.ts b/example/harmony/fs/src/main/ets/FsTurboModule.ts deleted file mode 100644 index d29d7cb..0000000 --- a/example/harmony/fs/src/main/ets/FsTurboModule.ts +++ /dev/null @@ -1,571 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved - * Use of this source code is governed by a MIT license that can be - * found in the LICENSE file. - */ - -import { TurboModule, RNOHError, TurboModuleContext } from '@rnoh/react-native-openharmony/ts'; -import { TM } from "./generated/ts" -import fs, { ListFileOptions, ReadOptions, ReadTextOptions, WriteOptions } from '@ohos.file.fs'; -import hash from '@ohos.file.hash'; -import { BusinessError } from '@ohos.base'; -import resourceManager from '@ohos.resourceManager' -import util from '@ohos.util'; -import loadRequest from '@ohos.request'; -import buffer from '@ohos.buffer'; -import HashMap from '@ohos.util.HashMap'; -import { Context } from '@ohos.abilityAccessCtrl'; -import common from '@ohos.app.ability.common'; - -const TAG: string = "[RNOH] Fs" - -interface StatResult { - ctime: number, // The creation date of the file - mtime: number, // The last modified date of the file - size: number, // Size in bytes - mode: number, // UNIX file mode - originalFilepath: string, // ANDROID: In case of content uri this is the pointed file path, otherwise is the same as path - type: number // Is the file just a file? Is the file a directory? -} - -type Headers = { [name: string]: string } -type Fields = { [name: string]: string } - -type DownloadFileOptions = { - jobId: number - fromUrl: string // URL to download file from - toFile: string // Local filesystem path to save the file to - headers?: Headers // An object of headers to be passed to the server - background?: boolean // Continue the download in the background after the app terminates (iOS only) - progressInterval?: number - progressDivider?: number - readTimeout?: number - hasBeginCallback?: (res: DownloadBeginCallbackResult) => void - hasProgressCallback?: (res: DownloadProgressCallbackResult) => void - hasResumableCallback?: () => void // only supported on iOS yet - connectionTimeout?: number // only supported on Android yet - backgroundTimeout?: number // Maximum time (in milliseconds) to download an entire resource (iOS only, useful for timing out background downloads) -} - -type DownloadBeginCallbackResult = { - jobId: number // The download job ID, required if one wishes to cancel the download. See `stopDownload`. - statusCode: number // The HTTP status code - contentLength: number // The total size in bytes of the download resource - headers: Headers // The HTTP response headers from the server -} - -type DownloadProgressCallbackResult = { - jobId: number // The download job ID, required if one wishes to cancel the download. See `stopDownload`. - contentLength: number // The total size in bytes of the download resource - bytesWritten: number // The number of bytes written to the file so far -} - -type DownloadResult = { - jobId: number // The download job ID, required if one wishes to cancel the download. See `stopDownload`. - statusCode: number // The HTTP status code - bytesWritten: number // The number of bytes written to the file -} - -type ReadDirItem = { - ctime?: number; - mtime?: number; - name: string; - path: string; - size: number; - type: number; -}; - -enum LOADTASK_STATUS { - PROGRESS = 'progress', - COMPLETE = 'complete', - PAUSE = 'pause', - REMOVE = 'remove', - FAIL = 'fail' -} - -export class FsTurboModule extends TurboModule implements TM.ReactNativeFs.Spec { - private context: Context; // ApplicationContext - private resourceManager: resourceManager.ResourceManager; - private FOUR_ZERO_NINE_SIX: number = 4096 - private ZERO: number = 0 - private ONE: number = 1 - private ONE_Three_Nine_ZERO_ZERO_ZERO_ONE_FIVE: number = 13900015 - private UTF8: buffer.BufferEncoding = 'utf8' - private MD5: string = 'md5' - private SHA1: string = 'sha1' - private SHA256: string = 'sha256' - private UTF_8: buffer.BufferEncoding = 'utf-8' - private BASE64: buffer.BufferEncoding = 'base64' - private logger = this.ctx.logger.clone("ReactNativeFsLogger") - - - constructor(ctx: TurboModuleContext) { - super(ctx) - this.context = this.ctx.uiAbilityContext; - this.resourceManager = this.context.resourceManager; - } - - existsAssets(filepath: string): Promise { - this.logger.info('existsAssets') - return new Promise((resolve, reject) => { - try { - this.resourceManager.getRawFileList(filepath, (error: BusinessError, value: Array) => { - if (error != null) { - resolve(false); - } else { - resolve(true); - } - }); - } catch (error) { - this.logger.error(`existsAssets error: ${error?.message}`) - resolve(false); - } - }); - } - - readDir(dirpath: string): Promise { - this.logger.info('readDir') - return new Promise((resolve, reject) => { - let listFileOption: ListFileOptions = { - recursion: false, - listNum: this.ZERO - }; - if (!dirpath.endsWith('/')) { - dirpath += '/'; - } - fs.listFile(dirpath, listFileOption, (err: BusinessError, filenames: Array) => { - if (err) { - reject("list file failed with error message: " + err.message + ", error code: " + err.code); - } else { - try { - let readDirResult: ReadDirItem[] = []; - for (let i = this.ZERO; i < filenames.length; i++) { - let filename = filenames[i]; - let filePath = dirpath + filename; - let file = fs.statSync(filePath); - readDirResult.push({ - ctime: file.ctime, - mtime: file.mtime, - name: filename, - path: filePath, - size: file.size, - type: file.isDirectory() ? this.ONE : this.ZERO, - }); - } - resolve(readDirResult); - } catch (e) { - this.logger.error(`readDir error: ${e?.message}`) - reject(e) - } - } - }); - }); - } - - downloadFile(options: Object): Promise { - this.logger.info('downloadFile') - return new Promise((resolve, reject) => { - let downloadFileOptions: DownloadFileOptions = options as DownloadFileOptions; - - try { - let res = fs.accessSync(downloadFileOptions.toFile); - if (res) { - fs.unlinkSync(downloadFileOptions.toFile); - } - } catch (error) { - reject(error); - } - let downloadConfig: loadRequest.DownloadConfig = { - url: downloadFileOptions.fromUrl, - header: downloadFileOptions.headers, - enableMetered: true, - enableRoaming: true, - description: "", - filePath: downloadFileOptions.toFile, - title: '', - background: false - }; - - loadRequest.downloadFile((this.context as common.BaseContext), downloadConfig) - .then((downloadTask: loadRequest.DownloadTask) => { - if (downloadTask) { - let loadTask: loadRequest.DownloadTask | null = downloadTask; - - if (downloadFileOptions.hasBeginCallback) { - let downloadBeginCallbackResult: DownloadBeginCallbackResult = { - jobId: downloadFileOptions.jobId, - statusCode: this.ZERO, - contentLength: this.ZERO, - headers: downloadFileOptions.headers - } - this.ctx.rnInstance.emitDeviceEvent('DownloadBegin', downloadBeginCallbackResult) - } - if (downloadFileOptions.hasProgressCallback) { - loadTask.on('progress', (receivedSize, totalSize) => { - if (totalSize > this.ZERO) { - let downloadProgressCallbackResult: DownloadProgressCallbackResult = { - jobId: downloadFileOptions.jobId, - contentLength: totalSize, - bytesWritten: receivedSize - } - this.ctx.rnInstance.emitDeviceEvent('DownloadProgress', downloadProgressCallbackResult) - } - }); - } - - loadTask.on('complete', () => { - let downloadResult: DownloadResult = { - jobId: downloadFileOptions.jobId, - statusCode: 200, - bytesWritten: this.ZERO - } - resolve(downloadResult); - }) - loadTask.on('pause', () => { - }) - - loadTask.on('remove', () => { - }) - loadTask.on('fail', (err) => { - reject(err); - }) - } else { - reject("downloadTask dismiss"); - } - }).catch((err: BusinessError) => { - this.logger.error(`downloadFile error: ${err?.message}`) - reject(err); - }) - }); - } - - // 常量 - getConstants(): Object { - let applicationContext = this.context.getApplicationContext(); - let result = { - // 沙箱路径 - FileSandBoxPath: this.context.filesDir, - // 缓存路径 - FileCachePath: this.context.cacheDir, - MainBundlePath: applicationContext.bundleCodeDir, - TemporaryDirectoryPath: applicationContext.tempDir, - LibraryDirectoryPath: applicationContext.preferencesDir, - // 文件 - RNFSFileTypeRegular: this.ZERO, - // 文件夹 - RNFSFileTypeDirectory: this.ONE, - } - - return result; - }; - - // 读取文件内容 - readFile(path: string): Promise { - this.logger.info('readFile') - return new Promise((resolve, reject) => { - try { - let file = fs.openSync(path); - let bufSize = this.FOUR_ZERO_NINE_SIX; - let readSize = this.ZERO; - let buf = new ArrayBuffer(bufSize); - let readOptions: ReadOptions = { - offset: readSize, - length: bufSize - }; - let buffers: buffer.Buffer[] = []; - let readLen = fs.readSync(file.fd, buf, readOptions); - while (readLen > this.ZERO) { - readSize += readLen; - readOptions.offset = readSize; - buffers.push(buffer.from(buf.slice(this.ZERO, readLen))) - readLen = fs.readSync(file.fd, buf, readOptions); - } - fs.closeSync(file); - let finalBuf: ArrayBuffer = buffer.concat(buffers).buffer; - let base64Helper = new util.Base64Helper; - let result = base64Helper.encodeToStringSync(new Uint8Array(finalBuf)); - resolve(result); - } catch (e) { - this.logger.error(`readFile error: ${e?.message}`) - reject(e); - } - }) - }; - - // 判断文件是否存在 - exists(path: string): Promise { - return new Promise((resolve, reject) => { - fs.access(path, (err: BusinessError, result: boolean) => { - if (err) { - reject('File does not exist'); - } else { - resolve(result); - } - }); - }) - }; - - // 创建文件 - mkdir(path: string): Promise { - this.logger.info('mkdir') - return new Promise(async (resolve, reject) => { - fs.mkdir(path, true, (err: BusinessError) => { - if (err) { - if (err.code == this.ONE_Three_Nine_ZERO_ZERO_ZERO_ONE_FIVE) { - // 文件夹存在 - resolve(); - } else { - reject(`Directory could not be created ${err.message} ${err.code}`); - } - } else { - resolve(); - } - }) - }) - } - - - // 写入文件内容 - writeFile(path: string, contentStr: string): Promise { - return new Promise((resolve, reject) => { - // base64 decode 解码 - let result = buffer.from(contentStr, this.BASE64); - // 读写创建 文件不存在则创建文件 - let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE | fs.OpenMode.TRUNC); - fs.write(file.fd, result.buffer, (err: BusinessError, writeLen: number) => { - if (err) { - reject('Directory could not be created'); - } else { - resolve(); - } - fs.closeSync(file); - }); - }) - }; - - // 文件内容追加 - appendFile(path: string, contentStr: string): Promise { - return new Promise((resolve, reject) => { - // base64 decode 解码 - let result = buffer.from(contentStr, this.BASE64).toString(this.UTF8); - // 读写创建 文件内容追加到末尾 - let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.APPEND); - fs.write(file.fd, result, (err: BusinessError, writeLen: number) => { - if (err) { - reject('Directory could not be created'); - } else { - resolve(); - } - fs.closeSync(file); - }); - }) - }; - - // 资源文件内容读取 - readFileAssets(path: string): Promise { - return new Promise((resolve, reject) => { - this.resourceManager.getRawFileContent(path, (err: BusinessError, value: Uint8Array) => { - if (err) { - this.logger.error(`readFileAssets error: ${err?.message}`) - reject(err.message); - } else { - resolve(this.parsingRawFile(value)); - } - }); - }) - } - - private parsingRawFile(rawFile: Uint8Array): string { - let base64 = new util.Base64Helper(); - let result = base64.encodeToStringSync(rawFile); - return result; - } - - // 将位于from的文件复制到into。 - copyFile(from: string, into: string): Promise { - return new Promise((resolve, reject) => { - let fromResult: string[] = from.split('/'); - let intoResult: string[] = into.split('/'); - if (fromResult[fromResult.length-this.ONE] === intoResult[intoResult.length-1]) { - reject(new Error('The file already exists.')); - return; - } - fs.copyFile(from, into, (err: BusinessError) => { - if (err) { - reject(err.message); - } else { - resolve(); - } - }) - }) - }; - - // 删除文件 - unlink(path: string): Promise { - return new Promise((resolve, reject) => { - fs.rmdir(path, (err: BusinessError) => { - if (err) { - reject('FilePath does not exist'); - } else { - resolve(); - } - }); - }) - } - - // 文件hash - hash(path: string, algorithm: string): Promise { - return new Promise((resolve, reject) => { - let algorithms: HashMap = new HashMap(); - algorithms.set(this.MD5, this.MD5); - algorithms.set(this.SHA1, this.SHA1); - algorithms.set(this.SHA256, this.SHA256); - // algorithm不存在 - if (!algorithms.hasKey(algorithm)) { - reject('Invalid hash algorithm'); - return; - } - // 判断是否是文件夹 - let isDirectory = fs.statSync(path).isDirectory(); - if (isDirectory) { - reject('file IsDirectory'); - return; - } - // 判断文件是否在 - let res = fs.accessSync(path); - if (!res) { - reject('file not exists'); - return; - } - hash.hash(path, algorithm, (err: BusinessError, result: string) => { - if (err) { - reject("calculate file hash failed with error message: " + err.message + ", error code: " + err.code); - } else { - resolve(result.toLocaleLowerCase()); - } - }) - }) - } - - // 移动文件 - moveFile(filepath: string, destPath: string): Promise { - return new Promise((resolve, reject) => { - fs.moveFile(filepath, destPath, this.ZERO, (err: BusinessError) => { - if (err) { - reject('move file failed with error message: ' + err.message + ', error code: ' + err.code); - } else { - resolve(); - } - }) - }) - } - - // 文件内容部分读 - read(path: string, length: number, position: number): Promise { - return new Promise((resolve, reject) => { - let readTextOption: ReadTextOptions = { - offset: position, - length: length, - encoding: this.UTF_8 - }; - fs.readText(path, readTextOption, (err: BusinessError, str: string) => { - if (err) { - reject('readText failed with error message: ' + err.message + ', error code: ' + err.code); - } else { - let result = buffer.from(str, this.UTF8).toString(this.BASE64); - resolve(result); - } - }); - }) - } - - // 文件内容从某位置写 - write(filepath: string, contents: string, position: number): Promise { - return new Promise((resolve, reject) => { - let result = buffer.from(contents, this.BASE64).toString(this.UTF8); - let file = fs.openSync(filepath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); - let writeOption: WriteOptions = { - offset: fs.statSync(filepath).size - }; - fs.write(file.fd, result, writeOption, (err: BusinessError, writeLen: number) => { - if (err) { - reject('write data to file failed with error message:' + err.message + ', error code: ' + err.code); - } else { - resolve(); - } - fs.closeSync(file); - }); - }) - } - - touch(filePath: string, mtime?: number, ctime?: number): Promise { - return new Promise((resolve, reject) => { - // 判断是否是文件夹 - let isDirectory = fs.statSync(filePath).isDirectory(); - if (isDirectory) { - reject('file IsDirectory'); - return; - } - // 判断文件是否在 - let res = fs.accessSync(filePath); - if (!res) { - reject('No such file or directory'); - return; - } - if (mtime) { - try { - fs.utimes(filePath, mtime); - resolve(true) - } catch (err) { - resolve(err.message) - } - } else { - resolve(false) - } - }) - } - - // 获取文件详细属性信息 - stat(filepath: string): Promise { - return new Promise((resolve, reject) => { - let statResult: StatResult = { - ctime: -this.ONE, - mtime: -this.ONE, - size: -this.ONE, - mode: -this.ONE, - originalFilepath: '', - type: -this.ONE - }; - // 判断文件是否在 - let res = fs.accessSync(filepath); - if (!res) { - reject('file not exists'); - return; - } - fs.stat(filepath, (err: BusinessError, stat: fs.Stat) => { - if (err) { - this.logger.error(TAG, `error message: ` + err.message + ', error code: ' + err.code); - } else { - statResult.ctime = stat.ctime; - statResult.mtime = stat.mtime; - statResult.size = stat.size; - statResult.mode = stat.mode; - statResult.originalFilepath = filepath; - statResult.type = stat.isDirectory() ? this.ONE : this.ZERO; - this.logger.info(TAG, 'file statResult: ' + JSON.stringify(statResult)); - resolve(statResult); - } - }); - }) - } - - // 处理异常警告 没有实际业务 - addListener(eventName: string): void { - - } - - // 处理异常警告 没有实际业务 - removeListeners(count: number): void { - - } -} \ No newline at end of file diff --git a/example/harmony/fs/src/main/ets/generated/components/ts.ts b/example/harmony/fs/src/main/ets/generated/components/ts.ts deleted file mode 100644 index d1dae56..0000000 --- a/example/harmony/fs/src/main/ets/generated/components/ts.ts +++ /dev/null @@ -1,5 +0,0 @@ - -/** - */ - -export {} diff --git a/example/harmony/fs/src/main/ets/generated/index.ets b/example/harmony/fs/src/main/ets/generated/index.ets deleted file mode 100644 index 041b7ed..0000000 --- a/example/harmony/fs/src/main/ets/generated/index.ets +++ /dev/null @@ -1,5 +0,0 @@ -/** - * This code was generated by "react-native codegen-lib-harmony" - */ - -export * from "./ts" diff --git a/example/harmony/fs/src/main/ets/generated/ts.ts b/example/harmony/fs/src/main/ets/generated/ts.ts deleted file mode 100644 index 4c568a8..0000000 --- a/example/harmony/fs/src/main/ets/generated/ts.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * This code was generated by "react-native codegen-lib-harmony" - */ - -export * as RNC from "./components/ts" -export * as TM from "./turboModules/ts" diff --git a/example/harmony/fs/src/main/ets/generated/turboModules/ReactNativeFs.ts b/example/harmony/fs/src/main/ets/generated/turboModules/ReactNativeFs.ts deleted file mode 100644 index 580f748..0000000 --- a/example/harmony/fs/src/main/ets/generated/turboModules/ReactNativeFs.ts +++ /dev/null @@ -1,58 +0,0 @@ -/** - * This code was generated by "react-native codegen-lib-harmony" - */ - -import { Tag } from "@rnoh/react-native-openharmony/ts" - -export namespace ReactNativeFs { - export const NAME = 'ReactNativeFs' as const - - export type MkdirOptionsT = {NSURLIsExcludedFromBackupKey?: boolean} - - export type StatResult = {ctime: number, mtime: number, size: number, mode: number, originalFilepath: string, type: number} - - export type DownloadResult = {jobId: number, statusCode: number, bytesWritten: number} - - export interface Spec { - getConstants(): Object; - - readFile(path: string): Promise; - - exists(path: string): Promise; - - mkdir(path: string, options: MkdirOptionsT): Promise; - - appendFile(path: string, contents: string, encoding: string): Promise; - - writeFile(path: string, contents: string, encoding: string): Promise; - - readFileAssets(path: string): Promise; - - copyFile(from: string, into: string): Promise; - - unlink(filepath: string): Promise; - - hash(filepath: string, algorithm: string): Promise; - - moveFile(filepath: string, destPath: string): Promise; - - read(path: string, length: number, position: number): Promise; - - write(filepath: string, contents: string, position: number): Promise; - - stat(filepath: string): Promise; - - touch(filepath: string, mtime: number, ctime: number): Promise; - - downloadFile(bridgeOptions: Object): Promise; - - readDir(dirpath: string): Promise; - - existsAssets(filepath: string): Promise; - - addListener(eventName: string): void; - - removeListeners(count: number): void; - - } -} diff --git a/example/harmony/fs/src/main/ets/generated/turboModules/ts.ts b/example/harmony/fs/src/main/ets/generated/turboModules/ts.ts deleted file mode 100644 index 6281d12..0000000 --- a/example/harmony/fs/src/main/ets/generated/turboModules/ts.ts +++ /dev/null @@ -1,5 +0,0 @@ -/** - * This code was generated by "react-native codegen-lib-harmony" - */ - -export * from "./ReactNativeFs" diff --git a/example/harmony/fs/src/main/module.json5 b/example/harmony/fs/src/main/module.json5 deleted file mode 100644 index 8aaa1c4..0000000 --- a/example/harmony/fs/src/main/module.json5 +++ /dev/null @@ -1,12 +0,0 @@ -{ - "module": { - "name": "fs", - "type": "har", - "description": "$string:module_desc", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ] - } -} \ No newline at end of file diff --git a/example/harmony/fs/src/main/resources/base/element/color.json b/example/harmony/fs/src/main/resources/base/element/color.json deleted file mode 100644 index 3c71296..0000000 --- a/example/harmony/fs/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/example/harmony/fs/src/main/resources/base/element/string.json b/example/harmony/fs/src/main/resources/base/element/string.json deleted file mode 100644 index 97ba7bb..0000000 --- a/example/harmony/fs/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "FsAbility_desc", - "value": "description" - }, - { - "name": "FsAbility_label", - "value": "label" - } - ] -} \ No newline at end of file diff --git a/example/harmony/fs/src/main/resources/en_US/element/string.json b/example/harmony/fs/src/main/resources/en_US/element/string.json deleted file mode 100644 index 97ba7bb..0000000 --- a/example/harmony/fs/src/main/resources/en_US/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "FsAbility_desc", - "value": "description" - }, - { - "name": "FsAbility_label", - "value": "label" - } - ] -} \ No newline at end of file diff --git a/example/harmony/fs/src/main/resources/zh_CN/element/string.json b/example/harmony/fs/src/main/resources/zh_CN/element/string.json deleted file mode 100644 index bd36d39..0000000 --- a/example/harmony/fs/src/main/resources/zh_CN/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "模块描述" - }, - { - "name": "FsAbility_desc", - "value": "description" - }, - { - "name": "FsAbility_label", - "value": "label" - } - ] -} \ No newline at end of file diff --git a/example/harmony/fs/src/ohosTest/ets/test/Ability.test.ets b/example/harmony/fs/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100644 index ca1b2db..0000000 --- a/example/harmony/fs/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved - * Use of this source code is governed by a MIT license that can be - * found in the LICENSE file. - */ - -import hilog from '@ohos.hilog'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; - -export default function abilityTest() { - describe('ActsAbilityTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }) - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }) - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }) - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }) - it('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); - let a = 'abc'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); - }) - }) -} \ No newline at end of file diff --git a/example/harmony/fs/src/ohosTest/ets/test/List.test.ets b/example/harmony/fs/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index f6c27e3..0000000 --- a/example/harmony/fs/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved - * Use of this source code is governed by a MIT license that can be - * found in the LICENSE file. - */ - -import abilityTest from './Ability.test'; - -export default function testsuite() { - abilityTest(); -} \ No newline at end of file diff --git a/example/harmony/fs/src/ohosTest/ets/testability/TestAbility.ets b/example/harmony/fs/src/ohosTest/ets/testability/TestAbility.ets deleted file mode 100644 index 1dcec5f..0000000 --- a/example/harmony/fs/src/ohosTest/ets/testability/TestAbility.ets +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved - * Use of this source code is governed by a MIT license that can be - * found in the LICENSE file. - */ - -import UIAbility from '@ohos.app.ability.UIAbility'; -import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -import hilog from '@ohos.hilog'; -import { Hypium } from '@ohos/hypium'; -import testsuite from '../test/List.test'; -import window from '@ohos.window'; -import Want from '@ohos.app.ability.Want'; -import AbilityConstant from '@ohos.app.ability.AbilityConstant'; - -export default class TestAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); - hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); - hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); - let abilityDelegator: AbilityDelegatorRegistry.AbilityDelegator; - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - let abilityDelegatorArguments: AbilityDelegatorRegistry.AbilityDelegatorArgs; - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); - hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); - } - - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); - windowStage.loadContent('testability/pages/Index', (err, data) => { - if (err.code) { - hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', - JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); - } - - onForeground() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); - } - - onBackground() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); - } -} \ No newline at end of file diff --git a/example/harmony/fs/src/ohosTest/ets/testability/pages/Index.ets b/example/harmony/fs/src/ohosTest/ets/testability/pages/Index.ets deleted file mode 100644 index 783cd7a..0000000 --- a/example/harmony/fs/src/ohosTest/ets/testability/pages/Index.ets +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved - * Use of this source code is governed by a MIT license that can be - * found in the LICENSE file. - */ - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - } - .height('100%') - } -} \ No newline at end of file diff --git a/example/harmony/fs/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets b/example/harmony/fs/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets deleted file mode 100644 index 05f743b..0000000 --- a/example/harmony/fs/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved - * Use of this source code is governed by a MIT license that can be - * found in the LICENSE file. - */ - -import hilog from '@ohos.hilog'; -import { BusinessError } from '@ohos.base'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import TestRunner from '@ohos.application.testRunner'; -import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -import Want from '@ohos.app.ability.Want'; -import resourceManager from '@ohos.resourceManager'; -import util from '@ohos.util'; - -let abilityDelegator: AbilityDelegatorRegistry.AbilityDelegator; -let abilityDelegatorArguments: AbilityDelegatorRegistry.AbilityDelegatorArgs; -let jsonPath: string = 'mock/mock-config.json'; -let tag: string = 'testTag'; - -async function onAbilityCreateCallback(data: UIAbility) { - hilog.info(0x0000, 'testTag', 'onAbilityCreateCallback, data: ${}', JSON.stringify(data)); -} - -async function addAbilityMonitorCallback(err: BusinessError) { - hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); -} - -export default class OpenHarmonyTestRunner implements TestRunner { - constructor() { - } - - onPrepare() { - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare'); - } - - async onRun() { - let tag = 'testTag'; - hilog.info(0x0000, tag, '%{public}s', 'OpenHarmonyTestRunner onRun run'); - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - let moduleName = abilityDelegatorArguments.parameters['-m']; - let context = abilityDelegator.getAppContext().getApplicationContext().createModuleContext(moduleName); - let mResourceManager = context.resourceManager; - await checkMock(abilityDelegator, mResourceManager); - const bundleName = abilityDelegatorArguments.bundleName; - const testAbilityName: string = 'TestAbility'; - let lMonitor: AbilityDelegatorRegistry.AbilityMonitor = { - abilityName: testAbilityName, - onAbilityCreate: onAbilityCreateCallback, - moduleName: moduleName - }; - abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) - const want: Want = { - bundleName: bundleName, - abilityName: testAbilityName, - moduleName: moduleName - }; - abilityDelegator.startAbility(want, (err: BusinessError, data: void) => { - hilog.info(0x0000, tag, 'startAbility : err : %{public}s', JSON.stringify(err) ?? ''); - hilog.info(0x0000, tag, 'startAbility : data : %{public}s', JSON.stringify(data) ?? ''); - }) - hilog.info(0x0000, tag, '%{public}s', 'OpenHarmonyTestRunner onRun end'); - } -} - -async function checkMock(abilityDelegator: AbilityDelegatorRegistry.AbilityDelegator, resourceManager: resourceManager.ResourceManager) { - let rawFile: Uint8Array; - try { - rawFile = resourceManager.getRawFileContentSync(jsonPath); - hilog.info(0x0000, tag, 'MockList file exists'); - let mockStr: string = util.TextDecoder.create("utf-8", { ignoreBOM: true }).decodeWithStream(rawFile); - let mockMap: Record = getMockList(mockStr); - try { - abilityDelegator.setMockList(mockMap) - } catch (error) { - let code = (error as BusinessError).code; - let message = (error as BusinessError).message; - hilog.error(0x0000, tag, `abilityDelegator.setMockList failed, error code: ${code}, message: ${message}.`); - } - } catch (error) { - let code = (error as BusinessError).code; - let message = (error as BusinessError).message; - hilog.error(0x0000, tag, `ResourceManager:callback getRawFileContent failed, error code: ${code}, message: ${message}.`); - } -} - -function getMockList(jsonStr: string) { - let jsonObj: Record = JSON.parse(jsonStr); - let map: Map = new Map(Object.entries(jsonObj)); - let mockList: Record = {}; - map.forEach((value: object, key: string) => { - let realValue: string = value['source'].toString(); - mockList[key] = realValue; - }); - hilog.info(0x0000, tag, '%{public}s', 'mock-json value:' + JSON.stringify(mockList) ?? ''); - return mockList; -} \ No newline at end of file diff --git a/example/harmony/fs/src/ohosTest/module.json5 b/example/harmony/fs/src/ohosTest/module.json5 deleted file mode 100644 index 6cc4de6..0000000 --- a/example/harmony/fs/src/ohosTest/module.json5 +++ /dev/null @@ -1,38 +0,0 @@ -{ - "module": { - "name": "fs_test", - "type": "feature", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} diff --git a/example/harmony/fs/src/ohosTest/resources/base/element/color.json b/example/harmony/fs/src/ohosTest/resources/base/element/color.json deleted file mode 100644 index 3c71296..0000000 --- a/example/harmony/fs/src/ohosTest/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/example/harmony/fs/src/ohosTest/resources/base/element/string.json b/example/harmony/fs/src/ohosTest/resources/base/element/string.json deleted file mode 100644 index 65d8fa5..0000000 --- a/example/harmony/fs/src/ohosTest/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_test_desc", - "value": "test ability description" - }, - { - "name": "TestAbility_desc", - "value": "the test ability" - }, - { - "name": "TestAbility_label", - "value": "test label" - } - ] -} \ No newline at end of file diff --git a/example/harmony/fs/src/test/List.test.ets b/example/harmony/fs/src/test/List.test.ets deleted file mode 100644 index 45ccbcc..0000000 --- a/example/harmony/fs/src/test/List.test.ets +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved - * Use of this source code is governed by a MIT license that can be - * found in the LICENSE file. - */ - -import localUnitTest from './LocalUnit.test'; - -export default function testsuite() { - localUnitTest(); -} \ No newline at end of file diff --git a/example/harmony/fs/src/test/LocalUnit.test.ets b/example/harmony/fs/src/test/LocalUnit.test.ets deleted file mode 100644 index 4a395d8..0000000 --- a/example/harmony/fs/src/test/LocalUnit.test.ets +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved - * Use of this source code is governed by a MIT license that can be - * found in the LICENSE file. - */ - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; - -export default function localUnitTest() { - describe('localUnitTest',() => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }); - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }); - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }); - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }); - it('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - let a = 'abc'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); - }); - }); -} \ No newline at end of file diff --git a/example/harmony/fs/ts.ts b/example/harmony/fs/ts.ts deleted file mode 100644 index e48256b..0000000 --- a/example/harmony/fs/ts.ts +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved - * Use of this source code is governed by a MIT license that can be - * found in the LICENSE file. - */ - -export * from "./src/main/ets/FsPackage" diff --git a/example/package.json b/example/package.json index 8bb47de..99c575e 100644 --- a/example/package.json +++ b/example/package.json @@ -11,12 +11,13 @@ "install:pkg": "npm uninstall @react-native-ohos/react-native-fs && npm run pack:pkg && npm i @react-native-ohos/react-native-fs@file:../react-native-ohos-react-native-fs-2.20.1-rc.2.tgz", "dev": "npm run codegen && react-native bundle-harmony --dev --minify=false", "prod": "npm run codegen && react-native bundle-harmony --dev=false --minify=true", - "postinstall": "node ./scripts/create-build-profile" + "postinstall": "node ./scripts/create-build-profile", + "fast:pkg": "cd ../ && npm i --legacy-peer-deps && npm pack && cd ./example && npm i && npm run dev" }, "dependencies": { "@gorhom/portal": "^1.0.14", "@react-native-ohos/react-native-fs": "file:../react-native-ohos-react-native-fs-2.20.1-rc.2.tgz", - "@rnoh/testerino": "npm:@react-native-oh/rnoh-testerino@0.0.9", + "@rnoh/testerino": "npm:@react-native-oh-tpl/testerino@0.0.9", "react": "18.2.0", "react-native": "0.72.5", "react-native-harmony": "npm:@react-native-oh/react-native-harmony@^0.72.32" -- Gitee