GithubHelp home page GithubHelp logo

tomasbjerre / dictator-builder Goto Github PK

View Code? Open in Web Editor NEW
3.0 5.0 1.0 1.95 MB

Let it dictate the filesystem. Avoid code duplication in template, or boilerplate, projects.

License: Apache License 2.0

JavaScript 3.90% TypeScript 96.10%
template-repository code-generator configuration-management project-boilerplate project-templates

dictator-builder's Introduction

Dictator Builder

NPM Build Status


After developing this tool I discovered MRM. It seems to solve the exact same thing which means I am archiving this repo.


A tool designed to help create dictators. A dictator dictates how parts of a folder should look like. Originally designed to avoid code duplication in source code repositories.

When working with npm within an organization you typically agree on some parts of the package.json, like some scripts that should always be there or some dependencies that should, or should not, be used. You may also have identical linting configurations like tsconfig.json, .prettierignore, .prettierrc.json... in every repository.

A dictator is basically just a command line tool distributed with NPM. The package is self contained including all files and configuration needed. A user can work with any language, or tools, as the dictator is run from command line and its only output are files.

See the examples:

What it solves

In short: helps avoid code duplication when working with many code repositories.

The problem

When working with many code repositories we often duplicate code within them. It can be entire files like:

  • .browserlistrc
  • .editorconfig
  • .prettierignore

And, or, parts of files. Like in package.json you may have an aggreement on some scripts that should always be there:

{
  "scripts": {
    "e2e": "...",
    "e2e:cli": "...",
    "start": "...",
    "build": "..."
  },
  "repository": "..."
}

Or another example might be .gitignore that, perhaps, should always be a superset of:

out
bin
.log

This solution

This tool has supporting functionality to help create such dictators. A dictator is an NPM package that includes all files and configuration needed to verify, and apply, requirements to a code repository. So we have:

  • 1 dictator-builder (this tool).
  • 1, or more, dictators. Perhaps if you have both Angular and Vue, you create one dictator to dictate AngularJS repositories and one to dicate Vue repositories.
  • 1, or more, code repositories that use 1, or more, dictators.

Creating a dictator

There is an example dictator here dictator. There are also examples in this repo used for testing.

What you need is a /package.json like:

{
  "name": "your-dictator-name",
  "bin": {
    "your-dictator-name": "./index.js"
  },
  "dependencies": {
    "dictator-builder": "^a.b.c"
  }
}

Create an index.js file containing:

#!/usr/bin/env node
require('dictator-builder/lib/index.lib').run(__dirname);

You need a folder /dictatables/[dictatableName]/[dictatableConfig] like:

/dictatables/a_dictatable/.dictatable-config.json
/dictatables/another_dictatable/.dictatable-config.json
/dictatables/another_dictatable/some_file
  • dictatableName is something to help organize files and have a name for it.
  • dictatableConfig is at least the .dictatable-config.json file containg DictatableConfig. Rules when to apply it and such.
    • You can also place other files in dictatableConfig folder and refer to them from dictatable-config.json.

The dictatable config is documented with:

  • A markdown file in the repository
  • A dictatableconfig.schema.json in the distributed package
  • TypeScript types here

Using dictator

It can be used from command line like npx dictatorname or npx dictatorname@version:

<dictator-name> [options]

Options:
  -V, --version          output the version number
  -l, --logging <level>  One of VERBOSE,INFO,ERROR default is INFO.
  -d, --dry-run          Only show what will be done.
  -c, --check            Fail if all requirements are not fulfilled.
  -nb, --no-banner       Do not print banner.
  -h, --help             display help for command

The folder to be dictated can place an optoinal .dictatorconfig.json file in its root to make some adjustments. The dictator config is documented with:

  • A markdown file in the repository
  • A dictatorconfig.schema.json in the distributed package
  • TypeScript types here

NPM

If you are working with NPM you may use it with some variations.

You may add it as a dependency. This means you can easily manage version updates. Also you can add some extra packages to the package and use it as a meta-package, depend on it and you will get its transitive dependencies.

{
  "name": "dictator-example",
  "version": "0.0.1",
  "description": "Just example",
  "scripts": {
    "prepare": "dictatorname"
  },
  "dependencies": {
    "dictatorname": "0.0.28"
  }
}

Or just in prepare or preinstall:

{
  "name": "dictator-example",
  "version": "0.0.1",
  "description": "Just example",
  "scripts": {
    "prepare": "npx [email protected]"
  }
}

dictator-builder's People

Contributors

tomasbjerre avatar twogood avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

twogood

dictator-builder's Issues

gitIgnoreHaveLineContaining

gitIgnoreHaveLineContaining

That works just like haveLineContaining but also respect the ignore part of dictatorconfig.

Consider: Optionally modify copied-files

Perhaps with a .dictatorconfig.json like:

{
  "adjust": {
    "file": [
      { "xpath": "//...", "value": "new value" },
      { "jsonpath": "$....", "value": "new value" },
      { "content": "whatever string", "value": "new value" }
    ]
  }
}

But this can also be done by refactoring the template-code:

If you need to change whatever.html in your template. You may, for example, refactor it into whatever.html.tmpl and whatever.html.json and have it render to a whatever.html during npm run build. And that does not need to have anything to do with this tool. You may choose to ignore the whatever.html.json in the dictated folder. So that it can be adjusted by users of the dictator.

Consider: Use .gitignore to determine what should be copied

Consider using content of .gitignore to decide on what can be copied to the repository. Anything that is ignored by git can probably be copied to the folder?

Also keep the current solution to support use cases wehere the folder is just a folder and not a git repository.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.