16a23e08bSopenharmony_ci/*
26a23e08bSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
36a23e08bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
46a23e08bSopenharmony_ci * you may not use this file except in compliance with the License.
56a23e08bSopenharmony_ci * You may obtain a copy of the License at
66a23e08bSopenharmony_ci *
76a23e08bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
86a23e08bSopenharmony_ci *
96a23e08bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
106a23e08bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
116a23e08bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
126a23e08bSopenharmony_ci * See the License for the specific language governing permissions and
136a23e08bSopenharmony_ci * limitations under the License.
146a23e08bSopenharmony_ci */
156a23e08bSopenharmony_ci
166a23e08bSopenharmony_ci"use strict";
176a23e08bSopenharmony_civar path = require("path");
186a23e08bSopenharmony_civar fs = require("fs");
196a23e08bSopenharmony_cilet exec = require('child_process').exec;
206a23e08bSopenharmony_ci
216a23e08bSopenharmony_ciconst arkDir = path.resolve(__dirname, 'bin', "ark");
226a23e08bSopenharmony_ciif (!fs.existsSync(arkDir)) {
236a23e08bSopenharmony_ci  return;
246a23e08bSopenharmony_ci}
256a23e08bSopenharmony_ci
266a23e08bSopenharmony_civar isWin = !1;
276a23e08bSopenharmony_civar isMac = !1;
286a23e08bSopenharmony_ci
296a23e08bSopenharmony_ciif (fs.existsSync(path.join(arkDir, "build-win"))) {
306a23e08bSopenharmony_ci    isWin = !0;
316a23e08bSopenharmony_ci} else if (fs.existsSync(path.join(arkDir, "build-mac"))) {
326a23e08bSopenharmony_ci    isMac = !0;
336a23e08bSopenharmony_ci} else if (!fs.existsSync(path.join(arkDir, "build"))) {
346a23e08bSopenharmony_ci    throw Error("Error: find build fail").message;
356a23e08bSopenharmony_ci}
366a23e08bSopenharmony_ci
376a23e08bSopenharmony_cilet cwd;
386a23e08bSopenharmony_ciif (isWin) {
396a23e08bSopenharmony_ci    cwd = path.join(arkDir, "build-win");
406a23e08bSopenharmony_ci} else if (isMac) {
416a23e08bSopenharmony_ci    cwd = path.join(arkDir, "build-mac");
426a23e08bSopenharmony_ci} else {
436a23e08bSopenharmony_ci    cwd = path.join(arkDir, "build");
446a23e08bSopenharmony_ci}
456a23e08bSopenharmony_ci
466a23e08bSopenharmony_cicwd = path.join(cwd, "legacy_api8");
476a23e08bSopenharmony_ci
486a23e08bSopenharmony_ciexec("npm install", { cwd: cwd }, function (err, stdout, stderr) {
496a23e08bSopenharmony_ci    console.log("[31m", stdout, "[39m");
506a23e08bSopenharmony_ci    if (err != null) {
516a23e08bSopenharmony_ci        throw Error(`npm install filed: ${err}`).message;
526a23e08bSopenharmony_ci    }
536a23e08bSopenharmony_ci});
54