• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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
16"use strict";
17const path = require("path");
18const fs = require("fs");
19const spawn = require('child_process').spawn;
20
21let isWin = !1;
22let isMac = !1;
23
24const arkDir = path.resolve(__dirname);
25
26if (fs.existsSync(path.join(arkDir, 'build-win'))) {
27    isWin = !0;
28} else if (fs.existsSync(path.join(arkDir, 'build-mac'))) {
29    isMac = !0;
30} else if (!fs.existsSync(path.join(arkDir, 'build'))) {
31    throw Error('find build fail').message;
32}
33
34let js2abc;
35if (isWin) {
36    js2abc = path.join(arkDir, 'build-win', 'bin', 'js2abc.exe');
37} else if (isMac) {
38    js2abc = path.join(arkDir, 'build-mac', 'bin', 'js2abc');
39} else {
40    js2abc = path.join(arkDir, 'build', 'bin', 'js2abc');
41}
42
43function callJs2abc(args) {
44    let proc = spawn(`${js2abc}`, args);
45
46    proc.stderr.on('data', (data) => {
47        throw Error(`${data}`).message;
48    });
49
50    proc.stdout.on('data', (data) => {
51        process.stdout.write(`${data}`);
52    });
53}
54
55let args = process.argv.splice(2);
56// keep bc-version to be compatible with old IDE versions
57if (args.length == 1 && args[0] == "--bc-version") {
58    callJs2abc(args);
59    return;
60}
61
62// hard-coded for now, will be modified later
63if (args[0] == "--target-api-version") {
64    if (args[1] == "8") {
65        process.stdout.write("0.0.0.2");
66    } else if (args[1] == "9") {
67        process.stdout.write("9.0.0.0");
68    } else if (args[1] == "10") {
69        process.stdout.write("9.0.0.0");
70    } else {
71        args = ["--bc-version"];
72        callJs2abc(args);
73    }
74}
75