****************************************
移除文件夹
****************************************
4124
async function rmdir(dir) {
    let stats = await stat(dir);

    // 判断文件存在
    if (stats) {

        // 处理文件夹
        if (stats.isDirectory()) {
            let files = await local.readdir(dir);

            // 依次移除子文件
            await Promise.all(
                files.map(file => rmdir(path.resolve(dir, file)))
            );

            // 移除空目录
            return await local.rmdir(dir);
        }

        // 移除文件
        await local.unlink(dir);
    }
}
785673
function postStandard(file, context) {
  fis.emit('standard:restore:start', file);
  var content = file.getContent();

  if (typeof content !== 'string') {
    return;
  }

  fis.log.debug('postStandard start');

  var reg = map.reg;
  // 因为处理过程中可能新生成中间码，所以要拉个判断。
  while (reg.test(content)) {
    reg.lastIndex = 0; // 重置 regexp
    content = content.replace(reg, function(all, type, depth, value, extra) {
      var ret = '',
        info, id;
      try {
        switch (type) {
          case 'id':
            info = fis.project.lookup(value, file);
            ret = info.quote + info.id + info.quote;

            if (info.file && info.file.isFile()) {
              file.addLink(info.file.subpath);
            }
            break;
          case 'moduleId':
            info = fis.project.lookup(value, file);
            ret = info.quote + info.moduleId + info.quote;

            if (info.file && info.file.isFile()) {
              file.addLink(info.file.subpath);
            }
            break;
          case 'hash':
            info = fis.project.lookup(value, file);
            if (info.file && info.file.isFile()) {

              file.addLink(info.file.subpath);

              var locked = lockedCheck(file, info.file);
              if (!locked) {
                lock(file, info.file);
                exports(info.file, context);
                unlock(info.file);
                addDeps(file, info.file);
              }

              var md5 = info.file.getHash();
              ret = info.quote + md5 + info.quote;
            } else {
              ret = value;
              addMissingDeps(file, value);
            }
            break;
          case 'require':
          case 'jsRequire':
            info = fis.project.lookup(value, file);
            file.addRequire(info.id);

            if (type === 'jsRequire' && info.moduleId) {
              ret = info.quote + info.moduleId + info.quote;
            } else {
              ret = info.quote + info.id + info.quote;
            }

            if (info.file && info.file.isFile()) {
              file.addLink(info.file.subpath);
            }
            break;

          case 'async':
          case 'jsAsync':
            info = fis.project.lookup(value, file);
            file.addAsyncRequire(info.id);

            if (type === 'jsAsync' && info.moduleId) {
              ret = info.quote + info.moduleId + info.quote;
            } else {
              ret = info.quote + info.id + info.quote;
            }

            if (info.file && info.file.isFile()) {
              file.addLink(info.file.subpath);
            }
            break;
          case 'uri':
            info = fis.project.lookup(value, file);
            if (info.file && info.file.isFile()) {

              file.addLink(info.file.subpath);

              if (info.file.useHash) {
                var locked = lockedCheck(file, info.file);
                if (!locked) {
                  lock(file, info.file);
                  exports(info.file, context);
                  unlock(info.file);
                  addDeps(file, info.file);
                }
              }
              var query = (info.file.query && info.query) ? '&' + info.query.substring(1) : info.query;
              var url = info.file.getUrl();
              var hash = info.hash || info.file.hash;
              ret = info.quote + url + query + hash + info.quote;
            } else {
              ret = value;
              addMissingDeps(file, value);
            }
            break;
          case 'dep':
            if (file.cache) {
              info = fis.project.lookup(value, file);
              addDeps(file, info.file);
            } else {
              fis.log.warning('unable to add deps to file [' + path + ']');
              addMissingDeps(file, value);
            }
            break;
          case 'embed':
          case 'jsEmbed':
            info = fis.project.lookup(value, file);
            var f;
            if (info.file) {
              f = info.file;
            } else if (fis.util.isAbsolute(info.rest)) {
              f = fis.file(info.rest);
            }
            if (f && f.isFile()) {
              file.addLink(f.subpath);
              var locked = lockedCheck(file, info.file);
              if (!locked) {
                lock(file, f);
                f.isInline = true;
                exports(f, context);
                unlock(f);
                addDeps(file, f);
                copyInfo(f, file);

                if (f.isText()) {
                  ret = f.getContent();
                  if (type === 'jsEmbed' && !f.isJsLike && !f.isJsonLike) {
                    ret = JSON.stringify(ret);
                  }

                  extra && (ret = filterEmbed(ret, extra));
                } else {
                  ret = info.quote + f.getBase64() + info.quote;
                }
              } else {
                var msg = 'unable to embed file[' + file.realpath + '] into itself.';

                if (locked.splice) {
                  msg = 'circular embed `' + locked.join('` -> `') + '`.';
                }

                error(msg);
              }
            } else {
              fis.log.error('unable to embed non-existent file %s', value);
            }
            break;
          case 'xlang':
            ret = partial(value, file, extra);
            break;

          case 'inlineStyle':
            ret = partial('inline-style-placeholder {' + value + '}', file, {
              ext: 'css',
              xLang: ':inline-style'
            });
            ret = ret.replace(/inline-style-placeholder\s?\{([\s\S]*)\}/, '$1');
            break;

          case 'sourceMap':
            info = fis.project.lookup(value, file, true);
            if (info.file && info.file.isFile()) {

              file.addLink(info.file.subpath);

              if (info.file.useHash) {
                var locked = lockedCheck(file, info.file);
                if (!locked) {
                  lock(file, info.file);
                  exports(info.file, context);
                  unlock(info.file);
                  addDeps(file, info.file);
                }
              }
              var query = (info.file.query && info.query) ? '&' + info.query.substring(1) : info.query;
              var url = info.file.getUrl();
              var hash = info.hash || info.file.hash;
              ret = info.quote + url + query + hash + info.quote;

              file.extras = file.extras || {};
              file.extras.derived = file.extras.derived || [];
              file.extras.derived.push(info.file);
            } else {
              ret = value;
            }
            break;

            // 用来存信息的，内容会被移除。
          case 'info':
            ret = '';
            break;
          default:
            if (!map[type]) {
              fis.log.error('unsupported fis language tag [%s]', type);
            }
        }

        // trigger event.
        var message = {
          ret: ret,
          value: value,
          file: file,
          info: info,
          type: type
        };
        fis.emit('standard:restore', message);
        fis.emit('standard:restore:' + type, message);
        ret = message.ret;
      } catch (e) {
        lockedMap = {};
        e.message = e.message + ' in [' + file.subpath + ']';
        throw e;
      }
      return ret;
    });
  }
  file.setContent(content);
  fis.emit('standard:restore:end', file);
  fis.log.debug('postStandard end');
}
504873
function Context(ret) {
    this.ret = ret;

    // 初始化文件列表
    var fileMap = this.filePathMap = ret.src;

    // 初始化资源映射表
    var fileIdMap = this.fileIdMap = {};
    var fileUrlMap = this.fileUrlMap = {};
    var files = this.files = [];
    Object.keys(fileMap).forEach(function (subpath) {
        var file = fileMap[subpath];
        files.push(file);
        fileIdMap[file.id] = file;
        if (file.release) {
            fileUrlMap[file.getUrl()] = file;
        }
    });
    this.resIdMap = {};
    this.root = fis.project.getProjectPath();
    this.requireConfig = getAmdConfig();
    this.moduleConfig = amdHelper.initModuleConfig(this.requireConfig, this.root);
    this.toPackItems = [];
}
598789
public void copyFile(final RelativeResource src, final RelativeResource dest)
		throws IOException {
		if (src.equals(dest)) {
			return;
		}
		LOG.debug("复制文件从 {} 到 {}", src, dest);
		File srcFile = getResource(src).getFile();
		if (!srcFile.exists()) {
			throw new FileNotFoundException(srcFile.getAbsolutePath());
		}
		File destFile = getResource(dest).getFile();
		deleteOldFile(destFile);
		FileUtils.copyFile(srcFile, destFile);
	}
949104
function combine(file) {
      if (!file) return;

      if (pathArr.indexOf(file.path) < 0) {
        pathArr.push(file.path);

        if (file.caculateContents) {
          cont = file.caculateContents
        } else {
          return;
        }

        contents.push(cont);

        size += cont.length;
      }

      if (file.children) {
        // 遍历依赖文件并且合并
        file.children.forEach(function(fc) {
          combine(denps[fc] || {path: fc});
        });
      }
    }
468403
async function rmdir(src) {
    let stats = await stat(src);

    // 判断是否存在文件夹
    if (stats) {
        if (stats.isDirectory()) {
            let files = await readdir(src);

            // 移除下级目录
            await Promise.all(
                files.map(file => rmdir(path.join(src, file)))
            );

            // 移除文件夹
            await removedir(src);
        } else {
            await unlink(src);
        }
    }
}
170205
function executeFile(src, { context, babelOptions } = {}) {
    let filename = resolvePath(context)(src);

    // 不存在文件
    if (!filename) {
        throw new Error(`Error: ENOENT: no such file, open '${src}'`);
    }

    // 解析【json】
    if (filename.endsWith('.json')) {
        return require(filename);
    }

    // 解析对象
    return execute(
        fs.readFileSync(filename, 'utf-8'), { filename, babelOptions }
    );
}
466101
function copyFile(src, dist, callback) {
    let rs = fs.createReadStream(src),
        ws = fs.createWriteStream(dist);

    // 监听事件
    rs.on('error', callback);
    ws.on('error', callback);
    ws.on('close', callback);

    // 传输文件
    rs.pipe(ws);
}
17649
function build(previousFileSizes) {
    let packText = userDevConfig ? '启动测试环境打包编译...' : '启动生产环境打包压缩...';
    let startTime = Date.now();
    let timer;
    let logProgress = function(stop) {
        var text = packText + '已耗时：' + ((Date.now() - startTime) / 1000).toFixed(3) + 's';

        if (stop) {
            clearTimeout(timer);
            spinner.succeed(chalk.green(text));
        } else {
            spinner.text = chalk.cyan(text);

            timer = setTimeout(logProgress, 100);
        }
    };

    clearConsole();
    logProgress();

    let compiler = webpack(config);

    return new Promise((resolve, reject) => {
        compiler.run((err, stats) => {
            let messages;

            logProgress(true); // 停止
            console.log();

            if (err) {
                if (!err.message) {
                    return reject(err);
                }

                messages = formatWebpackMessages({
                    errors: [err.message],
                    warnings: []
                });
            } else {
                messages = formatWebpackMessages(stats.toJson({ all: false, warnings: true, errors: true }));
            }

            if (messages.errors.length) {
                if (messages.errors.length > 1) {
                    messages.errors.length = 1;
                }

                return reject(new Error(messages.errors.join('\n\n')));
            }

            const resolveArgs = {
                stats,
                previousFileSizes,
                warnings: messages.warnings
            };

            return resolve(resolveArgs);
        });
    });
}
1272453
function getBaesVsersion(dir, callBack) {
        fs.readdir(`${dir}/`, (err, files) => {
            let dirList = [],
                baseVersion;
            if (err) {
                console.log('第一次部署中...');
                fs.mkdir(dir, () => {
                    callBack([1, 1, 1]);
                });
            } else {
                if (files.length == 0) {
                    files = ['1.1.1'];
                }
                console.log('部署目标已存在，正在更新中...');
                files.forEach((v)=> {
                    let intV = v.replace(/\./g, '');
                    if (!!parseInt(intV)) {
                        dirList.push(intV);
                    }
                });
                baseVersion = Math.max.apply(null, dirList).toString().split('');
                callBack(baseVersion);
            }
        });
    }
605732
function setZip(context, config, _stream, pathname) {
  const ext = path.extname(pathname).toLowerCase()
  if (ZIPFILE.indexOf(ext) === -1) {
    return _stream
  }
  const acceptEncoding = context.acceptEncoding
  // 如果acceptEncoding不为数组，就返回值
  if (!Array.isArray(acceptEncoding)) {
    return _stream
  }
  let zip = config.zip
  // 获取客户端支持的encoding
  let encoding = getEncoding(zip, acceptEncoding)
  // 设置压缩格式，并返回压缩后的响应正文
  switch (encoding) {
    case 'gzip':
      context.set({
        'Content-Encoding': 'gzip',
        'Transfer-Encoding': 'chunked'
      })
      return _stream.pipe(zlib.createGzip())
      break
    case 'deflate':
      context.set({
        'Content-Encoding': 'deflate',
        'Transfer-Encoding': 'chunked'
      })
      return _stream.pipe(zlib.createDeflate())
      break
    default:
      return _stream
      break
  }
  /**
   * 获取客户端和服务器支持的压缩格式
   * 并选择一种压缩格式
   * @param  {Mixed} _zip             config zip配置
   * @param  {Array} _acceptEncoding  客户端支持的压缩格式
   * @return {String}
   */
  function getEncoding(_zip, _acceptEncoding) {
    if (!_zip) {
      return false
    }
    if (_zip == true) {
      _zip = ENCODING
    }
    if ('string' === typeof _zip) {
      _zip = [_zip]
    }
    if (!Array.isArray(_zip)) {
      return false
    }
    for (let i = 0, length = _acceptEncoding.length; i < length; i++) {
      for (let j = 0; j < _zip.length; j++) {
        if (_zip[j] === _acceptEncoding[i]) {
          return _acceptEncoding[i].toLocaleLowerCase()
        }
      }
    }
  }
}
1176470
function getAsyncList(file, added, depScaned) {
        var asyncList = [];
        added = added || {};
        depScaned = depScaned || {};
        //对同步依赖进行异步依赖检查
        file.requires.forEach(function (depId) {
            if (depScaned[depId]) {
                return false;
            }
            depScaned[depId] = true;
            var dep = ret.ids[depId];
            if (!dep) {
                var isNotice = true;
                if (settings.notice && settings.notice.exclude) {
                    isNotice = fis.util.filter(file.subpath, null, settings.notice.exclude);
                }
                if (isNotice) {
                    fis.log.notice('can\'t find dep resource [' + depId + ']');
                }
                return false;
            }
            asyncList = asyncList.concat(getAsyncList(dep, added, depScaned));
        });
        file.extras && file.extras.async && file.extras.async.forEach(function (asyncId) {
            if (added[asyncId]) {
                return false;
            }
            added[asyncId] = true;
            var async = ret.ids[asyncId];
            if (!async) {
                fis.log.notice('can\'t find async resource [' + asyncId + ']');
                return false;
            }
            asyncList = asyncList.concat(getAsyncList(async, added, depScaned));
            //异步资源依赖需要递归添加所有同步依赖
            asyncList = asyncList.concat(getDepList(async, added));
            asyncList.push(async);
        });
        return asyncList;
    }
712370
private static void constructNGram(Path file){
        try(BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file.toFile()),"utf-8"));){
            String line;
            while( (line = reader.readLine()) != null ){
                LINES_COUNT.incrementAndGet();
                //去除首尾空白字符
                line = line.trim();
                //忽略空行
                if(!"".equals(line)){
                    //词和词之间以空格隔开
                    String[] words = line.split("\\s+");
                    if(words == null){
                        //忽略不符合规范的行
                        continue;
                    }
                    List<String> list = new ArrayList<>();
                    StringBuilder phrase = new StringBuilder();
                    int phraseCount=0;
                    boolean find=false;
                    for(String word : words){
                        String[] attr = word.split("/");
                        if(attr == null || attr.length < 1){
                            //忽略不符合规范的词
                            continue;
                        }
                        if(attr[0].trim().startsWith("[")){
                            find = true;
                        }                        
                        //去掉[和]
                        String item = attr[0].replace("[", "").replace("]", "").trim();
                        list.add(item);
                        //不重复词
                        addWord(item);
                        //词数目
                        WORD_COUNT.incrementAndGet();
                        //字符数目
                        CHAR_COUNT.addAndGet(item.length());
                        if(find){
                            phrase.append(item).append(" ");
                            phraseCount++;
                        }
                        //短语标注错误
                        if(phraseCount > 10){
                            find = false;
                            phraseCount = 0;
                            phrase.setLength(0);
                        }
                        if(find && attr.length > 1 && attr[1].trim().endsWith("]")){
                            find = false;
                            PHRASES.add(phrase.toString());
                            phrase.setLength(0);
                        }
                    }
                    //计算bigram模型
                    int len = list.size();
                    if(len < 2){
                        continue;
                    }
                    for(int i=0; i<len-1; i++){
                        String first = list.get(i);
                        if(!Utils.isChineseCharAndLengthAtLeastOne(first)){
                            continue;
                        }
                        String second = list.get(i+1);
                        if(!Utils.isChineseCharAndLengthAtLeastOne(second)){
                            //跳过一个词
                            i++;
                            continue;
                        }
                        //忽略长度均为1的模型
                        if(first.length() < 2 && second.length() < 2){
                            continue;
                        }
                        String key = first+":"+second;
                        Integer value = BIGRAM.get(key);
                        if(value == null){
                            value = 1;
                        }else{
                            value++;
                        }
                        BIGRAM.put(key, value);
                    }
                    if(len < 3){
                        continue;
                    }
                    //计算trigram模型
                    for(int i=0; i<len-2; i++){
                        String first = list.get(i);
                        if(!Utils.isChineseCharAndLengthAtLeastOne(first)){
                            continue;
                        }
                        String second = list.get(i+1);
                        if(!Utils.isChineseCharAndLengthAtLeastOne(second)){
                            //跳过一个词
                            i++;
                            continue;
                        }
                        String third = list.get(i+2);
                        if(!Utils.isChineseCharAndLengthAtLeastOne(third)){
                            //跳过二个词
                            i += 2;
                            continue;
                        }
                        //忽略长度均为1的模型
                        if(first.length() < 2 && second.length() < 2 && third.length() < 2){
                            continue;
                        }
                        String key = first+":"+second+":"+third;
                        Integer value = TRIGRAM.get(key);
                        if(value == null){
                            value = 1;
                        }else{
                            value++;
                        }
                        TRIGRAM.put(key, value);
                    }                    
                }
            }
        }catch(Exception e){
            LOGGER.info("分析语料库 "+file+" 失败：", e);
        }        
    }
1146185
function () {

        var that = this;
        var base = this.base;
        var $ = this.$;
        var files = [];


        $('link[rel=stylesheet]').each(function () {

            var $this = $(this);
            var cssFile;
            var href = $this.attr('href');

            cssFile = utils.resolve(base, href);
            cssFile = getUrl(cssFile);

            // 注意：为空也得放进去，保持与 link 标签一一对应
            files.push(cssFile);
        });


        // 转换 file 地址
        // 执行顺序：ignore > map > normalize
        function getUrl (file) {

            if (!that.ignore(file)) {
                file = that.map(file);
                file = utils.normalize(file);
                return file;
            }
        }


        if (this.options.debug) {
            console.log('');
            console.log('[DEBUG]', 'HtmlParser#getCssFiles', this.file);
            console.log(files);
        }


        return files;
    }
1125687
function copyExamp(path,pathLength){
	fs.readdir(path,function(err, files){
		if(err){
			console.log('examples read dir err:' + path);
		}else{
			// 遍历目录下所有子项
			files.forEach(function(item){
				var tmpPath = path + '/' + item;
				fs.stat(tmpPath,function(err, stat){
					if(stat.isFile()){
						// 判断文件类型,如果是.html则转化
						var htmlIndex = item.indexOf('.html');
						var jsIndex = item.indexOf('.js');
						var cssIndex = item.indexOf('.css');
						if(htmlIndex < 0 && (jsIndex > -1 || cssIndex > -1)){
							// 创建读取流
		                    readable = fs.createReadStream( tmpPath );
		                    // 创建写入流
		                    writable = fs.createWriteStream( 'examples/' + tmpPath.substring(pathLength) );
		                    // 通过管道来传输流
		                    readable.pipe(writable);
						}
						if(htmlIndex > -1){
							fs.readFile(tmpPath,function(err,data){
								var htmlStr = '';
								if(err){
									console.log('read html err:' + tmpPath)
								}else{
									htmlStr = data.toString();
								}
								var ctx = 'http://design.yonyoucloud.com/static/'
								var tpl = [
							        '<!DOCTYPE html>',
							        '<html lang="en">',
							        '<head>',
							        '<meta charset="UTF-8">',
							        '<meta name="viewport" content="width=device-width, initial-scale=1">',
							       	'<title>Title</title>',
									'<link rel="stylesheet" href="'+ ctx +'/font-awesome/css/font-awesome.css">',
							       	'<link rel="stylesheet" type="text/css" href="'+ ctx +'/uui/latest/css/u.css">',
							       	'<link rel="stylesheet" type="text/css" href="'+ ctx +'/uui/latest/css/u-extend.css">',
								    '<link rel="stylesheet" type="text/css" href="'+ ctx +'/uui/latest/css/tree.css">',
							        '<link rel="stylesheet" type="text/css" href="'+ ctx +'/uui/latest/css/grid.css">',
							        '<link rel="stylesheet" type="text/css" href="widget.css">',
							        '</head>',
							        '<body>',
							        htmlStr,
							        '<script src="'+ ctx +'/jquery/jquery-1.11.2.js"></script>',
							    	'<script src="'+ ctx +'/knockout/knockout-3.2.0.debug.js"></script>',
							        '<script src="'+ ctx +'/uui/latest/js/u-polyfill.js"></script>',
							        '<script src="'+ ctx +'/uui/latest/js/u.js"></script>',
							        '<script src="'+ ctx +'/uui/latest/js/u-tree.js"></script>',
							        '<script src="'+ ctx +'/uui/latest/js/u-grid.js"></script>',
									'<script src="'+ ctx +'/requirejs/require.debug.js"></script>',
									'<script src="widget.js"></script>',
							        '</body>',
							        '</html>'
						        ]
					        	var tplStr = tpl.join('\r\n');
					        	fs.writeFile('examples/' + tmpPath.substring(pathLength),tplStr,function(err){
						        	if(err){
						        		console.log('write err:' + 'examples/' + item + '.html');
						        	}
						        })
					        })
						}
					}
					// 子项为目录创建目录
					if(stat.isDirectory()){
						var dirPath = 'examples/' + tmpPath.substring(pathLength);
						fs.exists(dirPath, function(exist) {
							if(!exist){
								fs.mkdirSync(dirPath);
							}
						});
						copyExamp(tmpPath,pathLength);
					}
				})
			})
		}
	})
}
998532
async function mapdir(src, callback) {
    let stats = await stat(src),
        result = [];

    // 判断是否存在文件夹
    if (stats) {
        let fullpath = path.cwd(src),
            data = assign(stats, { path: fullpath });


        // 执行回调
        result.push(callback ? callback(data) : data);

        // 处理文件夹
        if (stats.isDirectory() && !fullpath.endsWith('node_modules')) {
            let files = await readdir(src);

            // 遍历下级文件
            for (let file of files) {
                result = result.concat(await mapdir(path.join(src, file), callback));
            }
        }
    }

    // 返回结果
    return result;
}
41304
public function resolveFileMenu()
    {
        $file_index = [];
        $files = $this->files;
        foreach ($files as $key => $file) {
            // 单页文件不做索引
            if (in_array($file['page_uuid'], $this->single_pages)) {
                continue;
            }
            // 标题索引处理
            $content = $this->fileSys->getContent($file['file_path']);
            $token = array_filter(explode("\n", $content['content']), function ($d){
                if (empty($d)) {
                    return false;
                }
                if (strpos($d, "\n#") === false && strpos($d, '#') !== 0 ) {
                    return false;
                }
                return true;
            });
            if (count($token)>0) {
                foreach ($token as &$value) {
                    $value = preg_replace_callback("|(#{1,6} )|", function($m){
                                return '';
                            }, $value);
                    $value = [
                        'title' => $value,
                        'href'  => '#'.$value,
                    ];
                }
            }
            $index = [
                'title' => $file['title'],
                'href'  => $file['href'],
                'uuid'  => $file['page_uuid'],
                'child' => $token
            ];
            $file_index[$file['page_uuid']] = $index;
        }
        $this->file_index = $file_index;
        // dd($file_index);
    }