@lcap/builder
Version:
lcap builder utils
61 lines (60 loc) • 3.02 kB
JavaScript
;
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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPreviewURL = exports.startPreview = void 0;
const portfinder_1 = __importDefault(require("portfinder"));
const project_1 = require("../utils/project");
const logger_1 = __importDefault(require("../utils/logger"));
const lcap_1 = require("../utils/lcap");
const exec_1 = require("../utils/exec");
let previewURL = '';
function startPreview(rootPath, https = false, options) {
return __awaiter(this, void 0, void 0, function* () {
const config = yield (0, project_1.getLcapConfig)();
const meta = yield (0, project_1.getExtensionProjectMeta)(rootPath);
const componentList = yield (0, lcap_1.getComponentMetaInfos)(rootPath, true);
const port = yield portfinder_1.default.getPortPromise({
port: 3000,
stopPort: 3333,
});
const protocol = https ? 'https' : 'http';
let platformURL = options.platform || config.platformURL || 'https://csforkf.lcap.codewave-test.163yun.com/';
platformURL = `${protocol}${platformURL.substring(platformURL.indexOf('://'))}`;
const version = options.version || '4.0.0';
const commands = [
'npx lcap-ide-server-proxy localserver',
`--PLATFORM_URL=${platformURL}`,
'--LIB_PATH=.',
`--IDE_VERSION=${version}`,
`--PORT=${port}`,
`--LIB_TYPE=${componentList[0].type === 'h5' ? 'h5' : 'pc'}`,
`--LIB_FRAMEWORK_KIND=${meta.framework}`,
// `--LIB_SERVICE=http://localhost:${port}/`,
];
try {
previewURL = `${protocol}://localhost:${port}/designer/uidev?appId=demo&MODE=localserver&LIB_SERVICE=${protocol}://localhost:${port}`;
logger_1.default.info(`ide 预览服务启动中...., 平台地址:${platformURL}`);
yield (0, exec_1.exec)(commands.join(' '));
}
catch (e) {
logger_1.default.error('ide 预览服务启动失败,platform');
}
return '';
});
}
exports.startPreview = startPreview;
function getPreviewURL() {
return previewURL;
}
exports.getPreviewURL = getPreviewURL;