UNPKG

file-lane

Version:

File conversion tool, can be one-to-one, one to N, N to one

63 lines (62 loc) 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _sharedUtils = require("@aiot-toolkit/shared-utils"); var _fsExtra = _interopRequireDefault(require("fs-extra")); var _path = _interopRequireDefault(require("path")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * FileLaneUtil */ class FileLaneUtil { /** * 文件路径转换为文件参数 * @param path 路径 * @param readContent 是否读取文件内容以设置 content 的值,默认 false * @returns */ static pathToFileParam(path) { let readContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; let content = ''; if (readContent && _fsExtra.default.existsSync(path)) { const stats = _fsExtra.default.statSync(path); if (stats.isFile()) { content = _fsExtra.default.readFileSync(path); } } return { path, content }; } static createContext(output, projectPath) { const cwd = process.cwd(); return { cwd, projectPath: projectPath || cwd, output }; } static checkError(message) { if (message.includes('System limit for number of file watchers reached')) { _sharedUtils.ColorConsole.error('There are too many files to watch, ', { word: 'please configure the content to be ignored.', style: { bgColor: _sharedUtils.ColorConsole.getStyle(_sharedUtils.Loglevel.ERROR).color || '#FF0000' } }, '(For example, node_modules)'); } else { _sharedUtils.ColorConsole.throw(`### file-lane ### watch error ${message}`); } } static getOutputPath(context) { const { output, projectPath } = context; return _path.default.join(projectPath, output); } } var _default = exports.default = FileLaneUtil;