初始化项目
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
/node_modules
|
||||
/oh_modules
|
||||
/.preview
|
||||
/build
|
||||
/.cxx
|
||||
/.test
|
||||
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"apiType": "stageMode",
|
||||
"buildOption": {
|
||||
"resOptions": {
|
||||
"copyCodeResource": {
|
||||
"enable": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"buildOptionSet": [
|
||||
{
|
||||
"name": "release",
|
||||
"arkOptions": {
|
||||
"obfuscation": {
|
||||
"ruleOptions": {
|
||||
"enable": false,
|
||||
"files": [
|
||||
"./obfuscation-rules.txt"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
],
|
||||
"targets": [
|
||||
{
|
||||
"name": "default"
|
||||
},
|
||||
{
|
||||
"name": "ohosTest",
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
|
||||
export default {
|
||||
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins: [] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
# Define project specific obfuscation rules here.
|
||||
# You can include the obfuscation configuration files in the current module's build-profile.json5.
|
||||
#
|
||||
# For more details, see
|
||||
# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/source-obfuscation
|
||||
|
||||
# Obfuscation options:
|
||||
# -disable-obfuscation: disable all obfuscations
|
||||
# -enable-property-obfuscation: obfuscate the property names
|
||||
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
|
||||
# -compact: remove unnecessary blank spaces and all line feeds
|
||||
# -remove-log: remove all console.* statements
|
||||
# -print-namecache: print the name cache that contains the mapping from the old names to new names
|
||||
# -apply-namecache: reuse the given cache file
|
||||
|
||||
# Keep options:
|
||||
# -keep-property-name: specifies property names that you want to keep
|
||||
# -keep-global-name: specifies names that you want to keep in the global scope
|
||||
|
||||
-enable-property-obfuscation
|
||||
-enable-toplevel-obfuscation
|
||||
-enable-filename-obfuscation
|
||||
-enable-export-obfuscation
|
||||
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"meta": {
|
||||
"stableOrder": true,
|
||||
"enableUnifiedLockfile": false
|
||||
},
|
||||
"lockfileVersion": 3,
|
||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||
"specifiers": {
|
||||
"@kuge/core@../core": "@kuge/core@../core",
|
||||
"@kuge/engine@../engine": "@kuge/engine@../engine",
|
||||
"@kuge/ui@../ui": "@kuge/ui@../ui"
|
||||
},
|
||||
"packages": {
|
||||
"@kuge/core@../core": {
|
||||
"name": "@kuge/core",
|
||||
"version": "1.0.0",
|
||||
"resolved": "../core",
|
||||
"registryType": "local"
|
||||
},
|
||||
"@kuge/engine@../engine": {
|
||||
"name": "@kuge/engine",
|
||||
"version": "1.0.0",
|
||||
"resolved": "../engine",
|
||||
"registryType": "local"
|
||||
},
|
||||
"@kuge/ui@../ui": {
|
||||
"name": "@kuge/ui",
|
||||
"version": "1.0.0",
|
||||
"resolved": "../ui",
|
||||
"registryType": "local"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "entry",
|
||||
"version": "1.0.0",
|
||||
"description": "Please describe the basic information.",
|
||||
"main": "",
|
||||
"author": "",
|
||||
"license": "",
|
||||
"dependencies": {
|
||||
"@kuge/core": "file:../core",
|
||||
"@kuge/engine": "file:../engine",
|
||||
"@kuge/ui": "file:../ui"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
|
||||
import { window } from '@kit.ArkUI';
|
||||
import { AppConfig, AppInfo, FileLogSink, Logger } from '@kuge/core';
|
||||
|
||||
const logger: Logger = Logger.create('EntryAbility');
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
private static logSink: FileLogSink | undefined = undefined;
|
||||
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
|
||||
try {
|
||||
this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
|
||||
} catch (err) {
|
||||
logger.error('Failed to set colorMode. Cause: {0}', JSON.stringify(err));
|
||||
}
|
||||
|
||||
// 配置与日志框架初始化:先读配置,再决定日志级别,最后挂文件落地。
|
||||
AppConfig.init(this.context);
|
||||
Logger.setMinLevel(AppConfig.getLogLevel());
|
||||
EntryAbility.logSink = new FileLogSink(this.context.filesDir + '/logs');
|
||||
Logger.setSink(EntryAbility.logSink);
|
||||
|
||||
logger.info('Ability onCreate, app={0}, version={1}, logLevel={2}, formFactors={3}',
|
||||
AppInfo.NAME, AppInfo.VERSION, AppConfig.levelName(AppConfig.getLogLevel()), AppInfo.FORM_FACTORS);
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
logger.info('Ability onDestroy');
|
||||
if (EntryAbility.logSink !== undefined) {
|
||||
EntryAbility.logSink.close();
|
||||
EntryAbility.logSink = undefined;
|
||||
Logger.setSink(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: window.WindowStage): void {
|
||||
// Main window is created, set main page for this ability
|
||||
logger.info('Ability onWindowStageCreate');
|
||||
|
||||
windowStage.loadContent('pages/Index', (err) => {
|
||||
if (err.code) {
|
||||
logger.error('Failed to load the content. Cause: {0}', JSON.stringify(err));
|
||||
return;
|
||||
}
|
||||
logger.info('Succeeded in loading the content.');
|
||||
});
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
// Main window is destroyed, release UI related resources
|
||||
logger.info('Ability onWindowStageDestroy');
|
||||
}
|
||||
|
||||
onForeground(): void {
|
||||
// Ability has brought to foreground
|
||||
logger.info('Ability onForeground');
|
||||
}
|
||||
|
||||
onBackground(): void {
|
||||
// Ability has back to background
|
||||
logger.info('Ability onBackground');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit';
|
||||
|
||||
const DOMAIN = 0x0000;
|
||||
|
||||
export default class EntryBackupAbility extends BackupExtensionAbility {
|
||||
async onBackup() {
|
||||
hilog.info(DOMAIN, 'testTag', 'onBackup ok');
|
||||
await Promise.resolve();
|
||||
}
|
||||
|
||||
async onRestore(bundleVersion: BundleVersion) {
|
||||
hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion));
|
||||
await Promise.resolve();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import { AppConfig, AppInfo, Logger, LogLevel } from '@kuge/core';
|
||||
import { ConnectionConfig, ConnectionManager, EngineKind, engineLabel, MockDriverFactory, stateLabel } from '@kuge/engine';
|
||||
import { AdaptiveScaffold } from '@kuge/ui';
|
||||
|
||||
const logger: Logger = Logger.create('Index');
|
||||
const manager: ConnectionManager = new ConnectionManager();
|
||||
manager.register(EngineKind.SQLITE, new MockDriverFactory(EngineKind.SQLITE));
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State message: string = AppInfo.NAME + '(' + AppInfo.ENGLISH_NAME + ')';
|
||||
@State hint: string = AppInfo.TAGLINE + '(' + AppInfo.FORM_FACTORS + ')';
|
||||
@State logLevel: string = AppConfig.levelName(AppConfig.getLogLevel());
|
||||
@State connState: string = '未自检';
|
||||
|
||||
aboutToAppear(): void {
|
||||
logger.info('page aboutToAppear, version={0}, logLevel={1}', AppInfo.VERSION, this.logLevel);
|
||||
}
|
||||
|
||||
async runSelfCheck(): Promise<void> {
|
||||
try {
|
||||
const cfg: ConnectionConfig = {
|
||||
id: 'mock-' + Date.now(),
|
||||
name: 'Mock SQLite',
|
||||
engine: EngineKind.SQLITE,
|
||||
host: 'local',
|
||||
port: 0,
|
||||
database: ':memory:',
|
||||
user: '',
|
||||
credentialRef: '',
|
||||
connectTimeoutMs: 2000
|
||||
};
|
||||
const conn = manager.create(cfg);
|
||||
await conn.connect();
|
||||
await conn.ping();
|
||||
this.connState = stateLabel(conn.getState());
|
||||
logger.info('self-check ok, engine={0}, state={1}', engineLabel(cfg.engine), this.connState);
|
||||
await conn.close();
|
||||
} catch (err) {
|
||||
const msg: string = err instanceof Error ? err.message : String(err);
|
||||
this.connState = '失败:' + msg;
|
||||
logger.error('self-check failed: {0}', msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Builder
|
||||
pageContent() {
|
||||
Column({ space: 16 }) {
|
||||
Text(this.message)
|
||||
.id('AppTitle')
|
||||
.fontSize(32)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
Text(this.hint)
|
||||
.id('AppHint')
|
||||
.fontSize(16)
|
||||
.fontColor($r('app.color.text_secondary'))
|
||||
Text('日志级别:' + this.logLevel)
|
||||
.id('LogLevel')
|
||||
.fontSize(14)
|
||||
.fontColor($r('app.color.text_secondary'))
|
||||
Text('连接状态:' + this.connState)
|
||||
.id('ConnState')
|
||||
.fontSize(14)
|
||||
.fontColor($r('app.color.text_secondary'))
|
||||
Button('写一条诊断日志')
|
||||
.id('LogButton')
|
||||
.onClick(() => {
|
||||
logger.info('user clicked, formFactors={0}', AppInfo.FORM_FACTORS);
|
||||
this.hint = '已写入 hilog(域 0xDB01)与文件日志(WARN 起)';
|
||||
})
|
||||
Button('切换日志级别')
|
||||
.id('LevelButton')
|
||||
.onClick(() => {
|
||||
const next: LogLevel = AppConfig.getLogLevel() === LogLevel.DEBUG ? LogLevel.INFO : LogLevel.DEBUG;
|
||||
AppConfig.setLogLevel(next);
|
||||
Logger.setMinLevel(next);
|
||||
this.logLevel = AppConfig.levelName(next);
|
||||
logger.info('log level switched to {0}', this.logLevel);
|
||||
})
|
||||
Button('连接自检(Mock 引擎)')
|
||||
.id('SelfCheckButton')
|
||||
.onClick(() => {
|
||||
this.runSelfCheck();
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.justifyContent(FlexAlign.Center)
|
||||
}
|
||||
|
||||
build() {
|
||||
AdaptiveScaffold({ content: this.pageContent })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"module": {
|
||||
"name": "entry",
|
||||
"type": "entry",
|
||||
"description": "$string:module_desc",
|
||||
"mainElement": "EntryAbility",
|
||||
"deviceTypes": [
|
||||
"tablet",
|
||||
"2in1"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages",
|
||||
"abilities": [
|
||||
{
|
||||
"name": "EntryAbility",
|
||||
"srcEntry": "./ets/entryability/EntryAbility.ets",
|
||||
"description": "$string:EntryAbility_desc",
|
||||
"icon": "$media:layered_image",
|
||||
"label": "$string:EntryAbility_label",
|
||||
"startWindowIcon": "$media:startIcon",
|
||||
"startWindowBackground": "$color:start_window_background",
|
||||
"exported": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"ohos.want.action.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"extensionAbilities": [
|
||||
{
|
||||
"name": "EntryBackupAbility",
|
||||
"srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets",
|
||||
"type": "backup",
|
||||
"exported": false,
|
||||
"metadata": [
|
||||
{
|
||||
"name": "ohos.extension.backup",
|
||||
"resource": "$profile:backup_config"
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#FFFFFF"
|
||||
},
|
||||
{
|
||||
"name": "text_secondary",
|
||||
"value": "#66000000"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"float": [
|
||||
{
|
||||
"name": "page_text_font_size",
|
||||
"value": "50fp"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "库阁主模块"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "库阁 · 跨库数据库工作台"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "库阁"
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 90 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"layered-image":
|
||||
{
|
||||
"background" : "$media:background",
|
||||
"foreground" : "$media:foreground"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"allowToBackupRestore": true
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/Index"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#000000"
|
||||
},
|
||||
{
|
||||
"name": "text_secondary",
|
||||
"value": "#99FFFFFF"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
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);
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import abilityTest from './Ability.test';
|
||||
|
||||
export default function testsuite() {
|
||||
abilityTest();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"module": {
|
||||
"name": "entry_test",
|
||||
"type": "feature",
|
||||
"deviceTypes": [
|
||||
"tablet",
|
||||
"2in1"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import localUnitTest from './LocalUnit.test';
|
||||
|
||||
export default function testsuite() {
|
||||
localUnitTest();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user