diff --git a/PackageStructureKit/hvigorfile.ts b/PackageStructureKit/hvigorfile.ts index f3cb9f1a87a81687554a76283af8df27d8bda775..e1edb358a8bed335f6f381a3aae3077223c9538d 100644 --- a/PackageStructureKit/hvigorfile.ts +++ b/PackageStructureKit/hvigorfile.ts @@ -1,6 +1,50 @@ -import { appTasks } from '@ohos/hvigor-ohos-plugin'; +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// [Start hvigorfile] +import { hapTasks, OhosPluginId } from '@ohos/hvigor-ohos-plugin'; +import { hapPlugin } from '@hadss/hmrouter-plugin'; +import { hvigor } from '@ohos/hivgor'; +import fs from 'fs'; +import path from 'path'; + +// Callback function after node evaluation +hvigor.afterNodeEvaluate((hvigorNode) => { + // Ensure this directory exists + const resourcesDir = path.join(__dirname, 'src/main/resources/rawfile'); + if (!fs.existsSync(resourcesDir)) { + fs.mkdirSync(resourcesDir, { recursive: true }); + } + + // Write the build time into the JSON file + const now = new Date(); + const buildTime = now.getFullYear() + '-' + + String(now.getMonth() + 1).padStart(2, '0') + '-' + + String(now.getDate()).padStart(2, '0') + '' + + String(now.getHours()).padStart(2, '0') + ':' + + String(now.getMinutes()).padStart(2, '0') + ':' + + String(now.getSeconds()).padStart(2, '0'); + const buildInfo = { 'buildTime': buildTime }; + fs.writeFileSync( + path.join(resourceDir, 'build_info.json'), + JSON.stringify(buildInfo, null, 2) + ); +}) export default { - system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ - plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [hapPlugin()] /* Custom plugin to extend the functionality of Hvigor. */ } +// [End hvigorfile] \ No newline at end of file