npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vltansky/mockoon-config-transformer

v1.0.3

Published

A CLI tool to bundle/extract Mockoon environment files in a git-friendly files tree with 100% backward compatibility

Downloads

8

Readme

mockoon-config-transformer

npm NPM Downloads NPM License

A CLI tool to bundle/extract Mockoon environment files in a git-friendly files tree with 100% backward compatibility.

lifecycle

Features

  • Extracts the original big Mockoon environment file into a user-friendly (git-friendly) file tree.
  • Generates markdown documentation files based on the documentation fields within the Mockoon environment file.
  • Bundle the extracted file tree into an environment file that matches the original file.

See examples:

Extract features

  • Successfully processed any URI with special characters.
  • Handled duplicated routes, responses, and data cases within the Mockoon configuration.
  • Ensured compatibility with updates to the Mockoon configuration structure, processing unexpected properties when encountered.
  • Handled edge cases related to file issues on the operating system, including file and directory name length.
  • Extracted the directory tree related to route-endpoint paths.
  • Extracted the response body into a multiline file.
  • Extracted the data bucket values into a multiline file.

Bundle features

  • The bundled environment is not based on escaped directory names.
  • Correctly restores array ordering (routes, responses, etc)
  • Correctly restores unknown properties

Motivation

Mockoon currently stores each environment in a single JSON file. This file has a complex and extensive structure, making it challenging to resolve version control conflicts when multiple developers are working in the same environment simultaneously.

Developers urgently need a solution to store environment files in version control systems and facilitate clean review processes for environment updates.

At some point, Mockoon will adopt a more Git-friendly environment file structure. Therefore, our main principle is as follows:

This tool interacts with the Mockoon environment file without adding any additional values, ensuring a full restoration of the original Mockoon configuration. This allows you to discontinue using this tool at any time."

How is the CLI tool tested?

Mockoon has 2000+ samples of the APIs, which is hosted in the mock-samples repo.

Each release of that CLI tool includes a test of these APIs that described in the samples could be extracted and then correctly bundled. That means any feature that is used in the mock-samples of the Mockoon is correctly processed by the CLI tool.

For the edge cases (e.g. dirs that are not used in the mock-samples, or dirs with the same names) we have the examples dir, where described a few examples and specific edge cases and these examples also used in the tests.

So the release means all Mockoon mock-samples are correctly extracted and then bundled and the bundles are equal to the original environment files, and some edge cases are also tested.

Installing

$ npm install mockoon-config-transformer --save-dev
# or 
$ yarn add mockoon-config-transformer --dev

CLI

Usage: mockoon-config-transformer [options] [command]

Options:
  -v, --version                        Output the current version
  -f, --force                          Force override directories and files if exists
  -i, --input  <relative-path or url>  Input path or URL
  -o, --output  <relative-path>        Output file or dir path
  -h, --help                           display help for command

Commands:
  bundle                               Bundle extracted files into Mockoon environment file
  extract                              Extract Mockoon json environment file into json files tree
  help [command]                       display help for command

Usage

Extract

Extracts the original Mockoon environment file into user-friendly file tree.

# Extract environment.json into output-dir

yarn mockoon-config-transformer extract -i ./environment.json -o ./output-dir
# Extract remote environment file by URI  into output-dir

yarn mockoon-config-transformer extract \ 
  -i https://raw.githubusercontent.com/mockoon/mock-samples/main/mock-apis/data/1forgecom.json \ 
  -o ./output-dir

Bundle

Bundle extracted directory to the environment file that equals the original file.

yarn mockoon-config-transformer bundle -i ./output-dir/index.json -o ./environment.json

Extracted files tree structure details

To make the extracted structure safe for duplicates special chars, future Mockoon releases, etc. the "bundle" functionality is based not on the directories tree, but on the file's content.

The files tree has just a view-friendly structure not really related to the file that will be bundled from that tree structure.

The directories tree equals the routes path names, but the directory names skipped some special chars to make directory names and tree structure safe for the OS.

Each directory could have index.json file, includes.json.
Each directory could have optional documentation.md file.

  • documentation.md this file includes generated documentation text from the environment file based on the documentation fields of the Mockoon environment file.

  • index.json file the main file that includes all properties except properties that moved to includes file.

  • includes.json file with ordered list of the nested data. The content of that file related to the index.json data type.

When the index.json data is object then includes is key:value extend object, where is the key is extra property of the index object and the value is a file path where the value stored is.

When the index.json data is an array, then includes is a ordered file paths of where the array items stored is.