"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const FS = __importStar(require("fs"));
const Path = __importStar(require("path"));
const Urlencode = __importStar(require("urlencode"));
const Utils = __importStar(require("../../../util/src"));
const Model = __importStar(require("../model"));
function build(path) {
    return __awaiter(this, void 0, void 0, function* () {
        if (!FS.existsSync(Path.join(path, 'dist/compress/mQAppId.zip'))) {
            return Promise.reject(Error(`未找到可提取的cube编译产物`));
        }
        const cases = new Array();
        Utils.Console.info(`提取应用配置 [${Path.join(path, 'dist/app.manifest')}]`);
        const manifest = FS.existsSync(Path.join(path, 'dist/app.manifest')) ? JSON.parse(FS.readFileSync(Path.join(path, 'dist/app.manifest')).toString()) : {};
        const pkg = JSON.parse(FS.readFileSync(Path.join(path, 'package.json')).toString());
        //  TODO: check case version
        const srcUrl = yield Utils.Basement.upload(Path.join(path, 'dist/app.manifest'), `${pkg.name}_${pkg.version}`);
        let index = 1;
        for (const page of manifest.pages) {
            Utils.Console.info(`构建用例配置 [${page}] [${index}/${manifest.pages.length}]`);
            const acase = Model.Case.defaultCase();
            acase.poles = Model.Case.Pole.Snapshot;
            acase.type = Model.Case.Type.Tiny;
            acase.subtype = Model.Case.Subtype.OnlyPaintCheck;
            acase.version = pkg.version;
            acase.scheme = `rubik:/launch?type=vue&dist=${Urlencode.encode(srcUrl)}&path=${page}`;
            cases.push(acase);
            index++;
        }
        return Promise.resolve(cases);
    });
}
exports.build = build;
//# sourceMappingURL=vue.js.map