@lspriv/plugin-taro
Version:
小程序日历组件Taro插件
103 lines • 4.51 kB
JavaScript
;
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCompJson = exports.TPL_COMP_WXML = exports.TPL_COMP_CONTENT = exports.removeComments = exports.getDefaultPmInstaller = exports.PKG_INSTALLER = exports.formatJson = exports.createCli = exports.getPkgConfig = exports.getPrjConfig = exports.PKG_LATEST_VERSION = exports.WX_CALENDAR_PKG_NAME = exports.isWin = exports.isMac = void 0;
const os_1 = require("os");
const fs_extra_1 = require("fs-extra");
const path_1 = require("path");
const child_process_1 = require("child_process");
const _platform = (0, os_1.platform)();
exports.isMac = _platform === 'darwin';
exports.isWin = _platform === 'win32';
exports.WX_CALENDAR_PKG_NAME = '@lspriv/wx-calendar';
exports.PKG_LATEST_VERSION = 'latest';
/**
* 如果小程序开发工具不是默认安装位置,请设置cli路径
* CLI_PATH 未设置时将会在以下几个位置尝试寻找:
* Mac:/Applications/wechatwebdevtools.app/Contents/MacOS/cli
* Win:C:/Program Files (x86)/Tencent/微信web开发者工具/cli.bat
*/
const CLI_PATH = exports.isMac
? '/Applications/wechatwebdevtools.app/Contents/MacOS/cli'
: exports.isWin
? 'C:/Program Files (x86)/Tencent/微信web开发者工具/cli.bat'
: '';
const getPrjConfig = () => {
return (0, fs_extra_1.readJsonSync)((0, path_1.resolve)(process.cwd(), 'project.config.json'), 'utf8');
};
exports.getPrjConfig = getPrjConfig;
const getPkgConfig = () => {
return (0, fs_extra_1.readJsonSync)((0, path_1.resolve)(process.cwd(), 'package.json'), 'utf8');
};
exports.getPkgConfig = getPkgConfig;
const PRJ_PATH = (0, path_1.resolve)(process.cwd(), ((_a = (0, exports.getPrjConfig)()) === null || _a === void 0 ? void 0 : _a.miniprogramRoot) || 'dist');
const createCli = (prjPath) => (command, options) => {
let _a = options || {}, { cli, withPrj } = _a, rest = __rest(_a, ["cli", "withPrj"]);
const opts = Object.assign(Object.assign({}, rest), { encoding: 'utf-8' });
const cliPath = cli || CLI_PATH;
const result = (0, child_process_1.execSync)(`${cliPath} ${command}${withPrj ? ` --project ${prjPath || PRJ_PATH}` : ''}`, opts);
return typeof result === 'string' ? JSON.parse(result) : result;
};
exports.createCli = createCli;
const formatJson = (json) => {
return JSON.stringify(json, null, 2);
};
exports.formatJson = formatJson;
const mergeCommand = (command, pkg, args) => {
return [command, pkg, ...(args || [])].filter(item => !!item).join(' ');
};
const pnpmInstall = (path, pkg, args) => {
(0, child_process_1.execSync)(mergeCommand('pnpm install', pkg, args), { cwd: path, stdio: 'ignore' });
};
const npmInstall = (path, pkg, args) => {
(0, child_process_1.execSync)(mergeCommand('npm install', pkg, args), { cwd: path, stdio: 'ignore' });
};
const cnpmInstall = (path, pkg, args) => {
(0, child_process_1.execSync)(mergeCommand('cnpm install', pkg, args), { cwd: path, stdio: 'ignore' });
};
exports.PKG_INSTALLER = {
cnpm: cnpmInstall,
pnpm: pnpmInstall,
npm: npmInstall
};
const getDefaultPmInstaller = () => {
try {
(0, child_process_1.execSync)('cnpm --version', { stdio: 'ignore' });
return cnpmInstall;
}
catch (e) { }
try {
(0, child_process_1.execSync)('pnpm --version', { stdio: 'ignore' });
return pnpmInstall;
}
catch (e) { }
try {
(0, child_process_1.execSync)('npm --version', { stdio: 'ignore' });
return npmInstall;
}
catch (e) { }
throw new Error('No package manager found');
};
exports.getDefaultPmInstaller = getDefaultPmInstaller;
const removeComments = (content) => {
return content.replace(/\/\/.*|\/\*[\s\S]*?\*\//g, '');
};
exports.removeComments = removeComments;
exports.TPL_COMP_CONTENT = `Component({})`;
exports.TPL_COMP_WXML = `<view></view>`;
const createCompJson = () => (0, exports.formatJson)({
component: true
});
exports.createCompJson = createCompJson;
//# sourceMappingURL=utils.js.map