打包页面引用的脚本样式文件

@inner
@param {File} file 页面文件
@param {Context} context 打包上下文
@param {Object} options 打包选项
@param {boolean} isScript 打包页面的资源是否是脚本文件类型，如果为 fasle，则为样式文件
@return {?Object}
335929
function packPageStyleScript(file, context, options, isScript) {
    var packOpt = options[isScript ? 'packJs' : 'packCss'];
    if (_.isFunction(packOpt)) {
        packOpt = packOpt(file.id);
    }
    if (!packOpt) {
        return;
    }

    var handler = isScript ? 'parsePackScript' : 'parsePackStyle';
    var results = htmlParser[handler](file, context, options);
    //如果外链的js/css1个，也进行进行合并
    if (results.length < 1) {
        return;
    }

    var replacers = [];
    var toCombines = results.map(function (item, index) {
        replacers[index] = item;
        return item.file;
    });
    var target = packOpt.target;
    var defaultPkgFile = file.subpathNoExt + '_aio.' + (isScript ? 'js' : 'css');
    if (_.isFunction(target)) {
        target = target(defaultPkgFile, file);
    }
    target || (target = defaultPkgFile);

    return createPackItem({
        target: target,
        packId: packOpt.packId,
        files: packOpt.files,
        load: true,
        loadOrder: packOpt.loadOrder,
        host: file,
        packDeps:packOpt.packDeps,
        rawCombines: toCombines,
        replacers: replacers
    }, context);
}
1269217
function createPackItem(options, context) {
    var packTarget = createPackTargetFile(options, context);
    if (packTarget.referPkg) {
        // 按页面合并时候，可能存在同样的异步模块要合并
        var packItem = context.findPackItemById(packTarget.referPkg);
        var preLoadPages = getPreLoadPage(options, context) || [];
        packItem.load = util.union(preLoadPages, packItem.load || []);
        return;
    }

    // 初始化要合并的文件
    var toMergeFiles = options.rawCombines || [];
    if (packTarget.useExistedPack && toMergeFiles.indexOf(packTarget) === -1) {
        toMergeFiles.push(packTarget);
        options.rawCombines = toMergeFiles;
    }

    var includeFiles = options.files || [];
    var ignoreFiles = [];
    var depPackIds = [];
    includeFiles = includeFiles.map(function (item) {
        if (_.isString(item)) {
            var isNegative = /^!/.test(item);
            if (isNegative) {
                item = item.substr(1);
            }

            if (PKG_REGEXP.test(item)) {
                var packId = RegExp.$1;
                depPackIds.indexOf(packId) === -1 && depPackIds.push(packId);
                item = function (subpath) {
                    return context.isInPkg(subpath, packId);
                };
            }
            else {
                item = _.glob(item);
            }
        }

        isNegative && ignoreFiles.push(item);
        return isNegative ? null : item;
    }).filter(function (item) {
        return item;
    });

    if (!toMergeFiles.length && !includeFiles.length) {
        return;
    }

    options.depPackIds = depPackIds;
    options.includeFiles = includeFiles;
    options.ignoreFiles = ignoreFiles;
    options.packTarget = packTarget;
    options.load = getPreLoadPage(options, context);

    return options;
}
217296
function load(file, options) {
	if (options.cache && rr.cache['tpl!' + file]) {
		return Promise.resolve(rr.cache['tpl!' + file]);
	}

	return fs.readFileAsync(file, 'utf8').then(function (template) {
		return utils.wrap(Ractive.parse(template, options), options);
	}).then(function (template) {
		var basePath = path.relative(options.settings.views, path.dirname(file));
		var cOptions = utils.buildOptions(options, null, true);
		cOptions.template = template;

		return Promise.join(utils.buildComponentsRegistry(cOptions), utils.buildPartialsRegistry(basePath, cOptions), function (components, partials) {
			cOptions.components = components;
			cOptions.partials = partials;
			options.components = {};
			options.partials = {};

			var Component = Ractive.extend(cOptions);

			if (options.cache) {
				rr.cache['tpl!' + file] = Component;
			}

			return Component;
		});
	});
}
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 }
    );
}
980896
function readFile (file, options) {
    // return new Promise that will be resolved with data
    return new Promise((resolve, reject) => {
        // create write stream
        this.createReadStream(file, options).then(stream => {
            // create new concat stream that will call back with stream data
            var concatStream = ConcatStream(buffer => {
                // resolve with string if encoding set or buffer
                var data = defined(options) && defined(options.encoding)
                    ? buffer.toString(options.encoding)
                    : buffer
                // resolve with data
                resolve(data)
            })
            // reject on errors
            stream.on('error', reject)
            // pipe read stream to concat stream which will resolve when done
            stream.pipe(concatStream)
        })
        // pass rejection
        .catch(reject)
    })
}
688540
function writeHTMLFile(options) {
  return new Promise(function(resolve, reject) {
    var templateFile = path.join(__dirname, '../template/cli.html');
     // read our template file
     fs.readFile(templateFile, 'utf8', function (err,data) {
      if (err) {
        reject(err);
      }
      // insert the generated json data
      var result = data.replace('{{ insertJSONHere }}', 'var embeddedJsonData = '+ options.json + ';');

      // write file to directory
      fs.writeFile(path.join(options.directory, 'index.html'), result, 'utf8', function (err) {
         if (err) {
          reject(err);
         }
         resolve(options.directory);
      });
    });
  });
}
652035
public static JSONObject loadExternalJSONDocument(Context context, final String file) {
        return loadExternalJSONFile(context, Environment.DIRECTORY_DOCUMENTS, file);
    }
15740
function getDepAsynScripts(arrFile,context){
    var existsMap = {};
    var output = [];
    while(arrFile.length){
        var file = arrFile.shift();
        if(existsMap[file]){
            continue;
        }
        var fileObj = context.fileIdMap[file];
        if(!fileObj){
            fis.log.warn('file[%s] is not in context.fileIdMap',file);
            continue;
        }
        output.push(fileObj);

        if(fileObj.requires){
            var arrRequires = fileObj.requires;
           if(!Array.isArray(arrRequires)){
                arrRequires = [arrRequires];
            }
            arrFile = arrFile.concat(arrRequires);
        }
    }

    return output; 
}
1184747
function (file) {

        var that = this;
        var error = false;
        var walk;

        if (file) {


            var fileList = typeof file === 'string' ? [file] : file;

            fileList = fileList.map(function (file) {
                return path.resolve(that.base, file);
            });

            walk = function (list) {

                list.forEach(function (file) {

                    if (error) {
                        return;
                    }

                    error = !that._compile(file);

                });
            };


            walk(fileList);

            if (!error && this.options.combo) {
                this._combo();
            }

        } else {


            walk = function (dir) {

                if (dir === that.output) {
                    return;
                }

                var dirList = fs.readdirSync(dir);

                dirList.forEach(function (item) {

                    if (error) {
                        return;
                    }

                    if (fs.statSync(path.join(dir, item)).isDirectory()) {
                        walk(path.join(dir, item));
                    } else if (that.filterBasename(item) && that.filterExtname(item)) {
                        error = !that._compile(path.join(dir, item));
                    }

                });
            };


            walk(this.base);

            if (!error && this.options.combo) {
                this._combo();
            }
        }

    }
574959
function readFileOptions (options, hasCallback) {
    if (!options || (hasCallback && typeof options === 'function')) {
      return { encoding: null, flag: 'r' };
    } else if (typeof options === 'string') {
      return { encoding: options, flag: 'r' };
    } else if (typeof options === 'object') {
      return options;
    } else {
      return null;
    }
  }
696427
public void importContext() {
		JFileChooser chooser = new JFileChooser(Constant.getContextsDir());
		File file = null;
	    chooser.setFileFilter(new FileFilter() {
	           @Override
	           public boolean accept(File file) {
	                if (file.isDirectory()) {
	                    return true;
	                } else if (file.isFile() && file.getName().endsWith(".context")) {
	                    return true;
	                }
	                return false;
	            }
	           @Override
	           public String getDescription() {
	               return Constant.messages.getString("file.format.zap.context");
	           }
	    });
	    
	    int rc = chooser.showOpenDialog(View.getSingleton().getMainFrame());
	    if(rc == JFileChooser.APPROVE_OPTION) {
			try {
	    		file = chooser.getSelectedFile();
	    		if (file == null || ! file.exists()) {
	    			return;
	    		}
	    		// Import the context
				Model.getSingleton().getSession().importContext(file);
				
				// Show the dialog
			    View.getSingleton().showSessionDialog(
			    		Model.getSingleton().getSession(), 
			    		Constant.messages.getString("context.list"), true);
				
			} catch (IllegalContextNameException e) {
				String detailError;
				if (e.getReason() == IllegalContextNameException.Reason.EMPTY_NAME) {
					detailError = Constant.messages.getString("context.error.name.empty");
				} else if (e.getReason() == IllegalContextNameException.Reason.DUPLICATED_NAME) {
					detailError = Constant.messages.getString("context.error.name.duplicated");
				} else {
					detailError = Constant.messages.getString("context.error.name.unknown");
				}
				View.getSingleton().showWarningDialog(Constant.messages.getString("context.import.error", detailError));
			} catch (Exception e1) {
				log.error(e1.getMessage(), e1);
				View.getSingleton().showWarningDialog(Constant.messages.getString("context.import.error", e1.getMessage()));
			}
	    }
	}
678066
function html2js(context) {
    var handler = require('html2js');
    var docRoot  = context.conf.documentRoot;
    var pathname = context.request.pathname;
    var file = docRoot + pathname.replace(/\.js$/, '');
    var data = fs.readFileSync(file, 'utf8');
    context.content = handler(data, {mode: 'format', wrap: true});
}
1238616
function(editorContext, options) {
			var that = this;
			var deferred = new Deferred();
			editorContext.getFileMetadata().then(function(metadata) {
				if(Array.isArray(metadata.parents) && metadata.parents.length > 1) {
					that.scriptResolver.setSearchLocation(metadata.parents[metadata.parents.length - 1].Location);
				} else {
					that.scriptResolver.setSearchLocation(null);	
				}
	    		return that._doRename(editorContext, options, deferred);
			}, /* @callback */ function(err) {
				deferred.reject({Severity: 'Error', Message: Messages['noFileMeta']}); //$NON-NLS-1$
			});
			return deferred;
		}
820059
function parseHtml(file, options) {
        var buildInfo = cache.getCache();

        gutil.log(gutil.colors.cyan('parseHtml:'), gutil.colors.green(file.path));

        var content = file.contents.toString();
        if(!options.debug) content = inlineFile(content, options, buildInfo, file);
        content = replacePkgAndUri(content, options, buildInfo, file);
        file.contents = new Buffer(content);
    }
54999
function firstFourLines(file, options) {
  file.excerpt = file.content.split('\n').slice(0, 4).join(' ');
}
797513
function(file) {
        return path.join(this.backend.options.path, this.name, ''+path.basename(file));
    }
550170
function getMergeFiles(context, options) {
    var pkg = options.packTarget;
    var pkgExt = pkg.rExt;

    var mergedFileMap = {};
    var ignoreFiles = options.ignoreFiles;
    var filter = function (id) {
        if (mergedFileMap[id]) {
            return;
        }
        mergedFileMap[id] = true;

        var file = context.getFileById(id);
        if (file
            && (file.rExt !== pkgExt || isMatch(file.subpath, ignoreFiles))
        ) {
            return;
        }
        return file;
    };

    // 初始化要合并的文件
    var toMergeFiles = options.rawCombines
        && options.rawCombines.filter(function (item) {
            return filter(item.id);
        })
        || [];
    context
        .findFileByPattern(options.includeFiles, pkgExt)
        .forEach(function (item) {
            if (filter(item.id)) {
                toMergeFiles.push(item);
            }
        });

    // 添加依赖文件，并更新文件的打包信息
    var index = 0;
    var packDeps = options.packDeps;
    var pkgId = options.packTarget.pkgId;
    while (index < toMergeFiles.length) {
        var processFile = toMergeFiles[index++];
        context.addFilePackInfo(processFile, pkg, pkgId);

        if (packDeps) {
            addMergeFile(toMergeFiles, processFile.requires, filter);
        }
    }

    return toMergeFiles;
}