• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16const fs = require('fs');
17const path = require('path');
18
19const exists = function(src, dst, callback) {
20  if (src.match(/\/test$/)) {
21    return;
22  }
23  fs.exists(dst, function(exists) {
24    if (exists) {
25      callback(src, dst);
26    } else {
27      fs.mkdir(dst, function() {
28        callback(src, dst);
29      });
30    }
31  });
32};
33
34stat = fs.stat;
35const copy = function(src, dst) {
36  fs.readdir(src, function(err, paths) {
37    if (err) {
38      throw err;
39    }
40    paths.forEach(function(_path) {
41      const _src = src + '/' + _path;
42      const _dst = dst + '/' + _path;
43      let readable;
44      let writable;
45      stat(_src, function(err, st) {
46        if (err) {
47          throw err;
48        }
49        if (st.isFile()) {
50          const pathInfo = path.parse(_src);
51          if (pathInfo.name === 'gulpfile' || pathInfo.ext !== '.js') {
52            return;
53          }
54          readable = fs.createReadStream(_src);
55          writable = fs.createWriteStream(_dst);
56          readable.pipe(writable);
57        } else if (st.isDirectory()) {
58          exists(_src, _dst, copy);
59        }
60      });
61    });
62  });
63};
64
65function copyResource(src, dist) {
66  exists(path.resolve(__dirname, src), dist, copy);
67}
68
69const TARGET_POSITION = 2;
70copyResource(path.resolve(__dirname, './deps/weex-scripter'), process.argv[TARGET_POSITION] + '/scripter');
71copyResource(path.resolve(__dirname, './deps/weex-styler'), process.argv[TARGET_POSITION] + '/styler');
72