@useoptic/cli-config
Advanced tools
Comparing version 8.0.7 to 8.1.0
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseRule = exports.allowedMethods = exports.parseIgnore = void 0; | ||
const pathToRegexp = require("path-to-regexp"); | ||
const path_to_regexp_1 = __importDefault(require("path-to-regexp")); | ||
function parseIgnore(ignores) { | ||
@@ -46,3 +49,3 @@ const rules = ignores.map(parseRule).filter(notEmpty); | ||
} | ||
const regex = pathToRegexp(pathInput); | ||
const regex = path_to_regexp_1.default(pathInput); | ||
const shouldIgnore = (method, url) => methods.includes(method) && regex.exec(url) !== null; | ||
@@ -49,0 +52,0 @@ return { |
@@ -10,2 +10,5 @@ import { parseRule, parseIgnore, IIgnoreRunnable } from './helpers/ignore-parser'; | ||
} | ||
export interface ITestingConfig { | ||
authToken: string; | ||
} | ||
export interface IOpticTask { | ||
@@ -24,2 +27,3 @@ command?: string; | ||
export declare function readApiConfig(configPath: string): Promise<IApiCliConfig>; | ||
export declare function readTestingConfig(testingConfigPath: string): Promise<ITestingConfig>; | ||
export interface IOpticCliInitConfig { | ||
@@ -86,4 +90,6 @@ type: 'init'; | ||
exampleRequestsPath: string; | ||
testingConfigPath: string; | ||
} | ||
export declare function getPathsRelativeToConfig(): Promise<IPathMapping>; | ||
export declare function pathsFromCwd(cwd: string): IPathMapping; | ||
export declare function getPathsRelativeToCwd(cwd: string): Promise<IPathMapping>; | ||
@@ -95,3 +101,6 @@ export declare function createFileTree(config: string, basePath: string): Promise<{ | ||
}>; | ||
export interface ITestingConfig { | ||
authToken: string; | ||
} | ||
export { parseIgnore, parseRule, IIgnoreRunnable }; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseRule = exports.parseIgnore = exports.createFileTree = exports.getPathsRelativeToCwd = exports.getPathsRelativeToConfig = exports.TaskToStartConfig = exports.TaskNotFoundError = exports.TargetPortUnavailableError = exports.CommandExecutionFailure = exports.OpticConfigurationLocationFailure = exports.InvalidOpticConfigurationSyntaxError = exports.readApiConfig = void 0; | ||
const fs = require("fs-extra"); | ||
const path = require("path"); | ||
const url = require("url"); | ||
const yaml = require("js-yaml"); | ||
const getPort = require("get-port"); | ||
const findUp = require("find-up"); | ||
exports.parseRule = exports.parseIgnore = exports.createFileTree = exports.getPathsRelativeToCwd = exports.pathsFromCwd = exports.getPathsRelativeToConfig = exports.TaskToStartConfig = exports.TaskNotFoundError = exports.TargetPortUnavailableError = exports.CommandExecutionFailure = exports.OpticConfigurationLocationFailure = exports.InvalidOpticConfigurationSyntaxError = exports.readTestingConfig = exports.readApiConfig = void 0; | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const path_1 = __importDefault(require("path")); | ||
const url_1 = __importDefault(require("url")); | ||
const js_yaml_1 = __importDefault(require("js-yaml")); | ||
const get_port_1 = __importDefault(require("get-port")); | ||
const find_up_1 = __importDefault(require("find-up")); | ||
const ignore_parser_1 = require("./helpers/ignore-parser"); | ||
@@ -14,6 +17,6 @@ Object.defineProperty(exports, "parseRule", { enumerable: true, get: function () { return ignore_parser_1.parseRule; } }); | ||
async function readApiConfig(configPath) { | ||
const rawFile = await fs.readFile(configPath); | ||
const rawFile = await fs_extra_1.default.readFile(configPath); | ||
let parsed = null; | ||
try { | ||
parsed = yaml.safeLoad(rawFile.toString()); | ||
parsed = js_yaml_1.default.safeLoad(rawFile.toString()); | ||
} | ||
@@ -26,2 +29,8 @@ catch (e) { | ||
exports.readApiConfig = readApiConfig; | ||
async function readTestingConfig(testingConfigPath) { | ||
const parsed = await fs_extra_1.default.readJSON(testingConfigPath); | ||
// TODO: validate shape? | ||
return parsed; | ||
} | ||
exports.readTestingConfig = readTestingConfig; | ||
class InvalidOpticConfigurationSyntaxError extends Error { | ||
@@ -43,7 +52,7 @@ } | ||
async function TaskToStartConfig(task) { | ||
const parsedBaseUrl = url.parse(task.baseUrl); | ||
const randomPort = await getPort({ port: getPort.makeRange(3300, 3900) }); | ||
const parsedBaseUrl = url_1.default.parse(task.baseUrl); | ||
const randomPort = await get_port_1.default({ port: get_port_1.default.makeRange(3300, 3900) }); | ||
const serviceProtocol = parsedBaseUrl.protocol || 'http:'; | ||
const proxyPort = parsedBaseUrl.port || (serviceProtocol === 'http:' ? '80' : '443'); | ||
const parsedProxyBaseUrl = task.proxy && url.parse(task.proxy); | ||
const parsedProxyBaseUrl = task.proxy && url_1.default.parse(task.proxy); | ||
return { | ||
@@ -73,5 +82,5 @@ command: task.command, | ||
async function getPathsRelativeToConfig() { | ||
const configPath = await findUp('optic.yml', { type: 'file' }); | ||
const configPath = await find_up_1.default('optic.yml', { type: 'file' }); | ||
if (configPath) { | ||
const configParentDirectory = path.resolve(configPath, '../'); | ||
const configParentDirectory = path_1.default.resolve(configPath, '../'); | ||
return await getPathsRelativeToCwd(configParentDirectory); | ||
@@ -82,21 +91,29 @@ } | ||
exports.getPathsRelativeToConfig = getPathsRelativeToConfig; | ||
async function getPathsRelativeToCwd(cwd) { | ||
const configPath = path.join(cwd, 'optic.yml'); | ||
const basePath = path.join(cwd, '.optic'); | ||
const capturesPath = path.join(basePath, 'captures'); | ||
const gitignorePath = path.join(basePath, '.gitignore'); | ||
const specStorePath = path.join(basePath, 'api', 'specification.json'); | ||
const exampleRequestsPath = path.join(basePath, 'api', 'example-requests'); | ||
await fs.ensureDir(capturesPath); | ||
await fs.ensureDir(exampleRequestsPath); | ||
function pathsFromCwd(cwd) { | ||
const configPath = path_1.default.join(cwd, 'optic.yml'); | ||
const basePath = path_1.default.join(cwd, '.optic'); | ||
const capturesPath = path_1.default.join(basePath, 'captures'); | ||
const gitignorePath = path_1.default.join(basePath, '.gitignore'); | ||
const specStorePath = path_1.default.join(basePath, 'api', 'specification.json'); | ||
const exampleRequestsPath = path_1.default.join(basePath, 'api', 'example-requests'); | ||
const testingConfigPath = path_1.default.join(basePath, 'testing.json'); | ||
return { | ||
cwd, | ||
configPath, | ||
basePath, | ||
capturesPath, | ||
gitignorePath, | ||
specStorePath, | ||
configPath, | ||
gitignorePath, | ||
capturesPath, | ||
exampleRequestsPath, | ||
testingConfigPath, | ||
}; | ||
} | ||
exports.pathsFromCwd = pathsFromCwd; | ||
async function getPathsRelativeToCwd(cwd) { | ||
const pathMapping = pathsFromCwd(cwd); | ||
const { capturesPath, exampleRequestsPath } = pathMapping; | ||
await fs_extra_1.default.ensureDir(capturesPath); | ||
await fs_extra_1.default.ensureDir(exampleRequestsPath); | ||
return pathMapping; | ||
} | ||
exports.getPathsRelativeToCwd = getPathsRelativeToCwd; | ||
@@ -124,6 +141,6 @@ async function createFileTree(config, basePath) { | ||
await Promise.all(files.map(async (file) => { | ||
await fs.ensureFile(file.path); | ||
await fs.writeFile(file.path, file.contents); | ||
await fs_extra_1.default.ensureFile(file.path); | ||
await fs_extra_1.default.writeFile(file.path, file.contents); | ||
})); | ||
await fs.ensureDir(capturesPath); | ||
await fs_extra_1.default.ensureDir(capturesPath); | ||
return { | ||
@@ -130,0 +147,0 @@ configPath, |
{ | ||
"name": "@useoptic/cli-config", | ||
"version": "8.0.7", | ||
"version": "8.1.0", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "ws:test": "echo config", |
Sorry, the diff of this file is not supported yet
14987
319