1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { ModuleMode } from './module_mode'; 17import { ES2ABC, TS2ABC } from '../common/ark_define'; 18import { isEs2Abc, isTs2Abc } from '../../../ark_utils'; 19 20export class ModulePreviewMode extends ModuleMode { 21 constructor(rollupObject: any) { 22 super(rollupObject); 23 } 24 25 generateAbc(rollupObject: any) { 26 this.prepareForCompilation(rollupObject); 27 this.executeArkCompiler(); 28 } 29 30 executeArkCompiler() { 31 if (isEs2Abc(this.projectConfig)) { 32 this.generateEs2AbcCmd(); 33 this.addCacheFileArgs(); 34 this.generateMergedAbcOfEs2Abc(); 35 } else if (isTs2Abc(this.projectConfig)) { 36 this.filterModulesByHashJson(); 37 const splittedModules: any[] = this.getSplittedModulesByNumber(); 38 this.invokeTs2AbcWorkersToGenProto(splittedModules); 39 this.processTs2abcWorkersToGenAbc(); 40 } else { 41 this.throwArkTsCompilerError(`Invalid projectConfig.pandaMode for module preview, should be either 42 "${TS2ABC}" or "${ES2ABC}"`); 43 } 44 } 45} 46