Giter Club home page Giter Club logo

prettier-package-json's Introduction

Prettier package.json

CI npm

prettier-package-json is a JSON formatter inspired by prettier. It removes all original styling and ensures that the outputted package.json conforms to a consistent style. By default it uses opinionated defaults but can be configured to your individual needs.

Features

Consistent key order

Keys in package.json will be sorted in an opinionated order but may be configured to your own preferences.

Input:

{
  "description": "Prettier formatter for package.json files",
  "name": "prettier-package-json",
  "license": "MIT",
  "version": "1.0.1",
  "author": "Cameron Hunter <[email protected]>"
}

Output:

{
  "name": "prettier-package-json",
  "description": "Prettier formatter for package.json files",
  "author": "Cameron Hunter <[email protected]>",
  "license": "MIT",
  "version": "1.0.1"
}

Sensibly sorted scripts

The scripts field is sorted alphabetically but keeps pre and post scripts surrounding their named script.

Input:

{
  "name": "prettier-package-json",
  "version": "1.0.1",
  "scripts": {
    "test": "test",
    "pretest": "pretest",
    "version": "version",
    "postversion": "postversion",
    "build": "build"
  }
}

Output:

{
  "name": "prettier-package-json",
  "version": "1.0.1",
  "scripts": {
    "build": "build",
    "pretest": "pretest",
    "test": "test",
    "version": "version",
    "postversion": "postversion"
  }
}

Expand/contract author, contributors, and maintainers

The author, contributors and maintainers fields will be shortened to their string versions and sorted by name. Use the --expand-users option if you prefer user objects.

Input:

{
  "name": "prettier-package-json",
  "version": "1.0.1",
  "author": {
    "name": "Cameron Hunter",
    "email": "[email protected]",
    "url": "https://cameronhunter.co.uk"
  },
  "contributors": ["Barry", "Adam <[email protected]>"]
}

Output:

{
  "name": "prettier-package-json",
  "version": "1.0.1",
  "author": "Cameron Hunter <[email protected]> (https://cameronhunter.co.uk)",
  "contributors": ["Adam <[email protected]>", "Barry"]
}

Filter and sort files field

Some files are included or excluded automatically by npm, these are removed from the files field before sorting alphabetically.

Input:

{
  "name": "prettier-package-json",
  "version": "1.0.1",
  "main": "src/index.js",
  "files": [
    "src/index.js",
    "src",
    "CHANGELOG.md",
    "readme.md",
    "package-lock.json"
  ]
}

Output:

{
  "name": "prettier-package-json",
  "version": "1.0.1",
  "main": "src/index.js",
  "files": ["src"]
}

Usage

Install:

yarn add prettier-package-json --dev

You can install it globally if you like:

yarn global add prettier-package-json

We're defaulting to yarn but you can use npm if you like:

npm install [-g] prettier-package-json

CLI

Run prettier-package-json through the CLI with this script. Run it without any arguments to see the options.

To format a file in-place, use --write. You may want to consider committing your file before doing that, just in case.

prettier-package-json [opts] [filename]

In practice, this may look something like:

prettier-package-json --write ./package.json

Pre-commit hook for changed files

You can use this with a pre-commit tool. This can re-format your files that are marked as "staged" via git add before you commit.

Install it along with husky:

yarn add lint-staged husky --dev

and add this config to your package.json:

{
  "scripts": {
    "precommit": "lint-staged"
  },
  "lint-staged": {
    "package.json": ["prettier-package-json --write", "git add"]
  }
}

See https://github.com/okonet/lint-staged#configuration for more details about how you can configure lint-staged.

2. bash script

Alternately you can just save this script as .git/hooks/pre-commit and give it execute permission:

#!/bin/sh
packagejsonfiles=$(git diff --cached --name-only --diff-filter=ACM | grep 'package\.json$' | tr '\n' ' ')
[ -z "$packagejsonfiles" ] && exit 0

diffs=$(node_modules/.bin/prettier-package-json -l $packagejsonfiles)
[ -z "$diffs" ] && exit 0

echo "here"
echo >&2 "package.json files must be formatted with prettier-package-json. Please run:"
echo >&2 "node_modules/.bin/prettier-package-json --write "$diffs""

exit 1

API

The API has two functions, exported as format and check. Usage is as follows:

import { format, check } from 'prettier-package-json';

const options = {}; // optional

format(json, options);
check(json, options);

check checks to see if the file has been formatted with prettier-package-json given those options and returns a Boolean. This is similar to the --list-different parameter in the CLI and is useful for running in CI scenarios.

CI

For usage in CI scenarios, you can use the --list-different CLI flag. The command will list all invalid files and return with a proper default error code, so that in case of an error or invalid file the build pipeline automatically fails.

These are the status codes:

  • 0: all files valid, no error occured.
  • 1: an error ocurred, for example a JSON parse error. See message on stderr for details.
  • 2: not all files are valid.

These exit codes are only set when in --list-different mode.

Options

prettier-package-json ships with a handful of customizable format options, usable in both the CLI, API, and configuration file.

Option Default CLI override API override
Tab Width - Specify the number of spaces per indentation-level. 2 --tab-width <int> tabWidth: <int>
Tabs - Indent lines with tabs instead of spaces. false --use-tabs useTabs: <bool>
Expand Users - Expand author and contributors into objects. false --expand-users expandUsers: <bool>
Key Order - Specify the order of keys. See default options --key-order <comma,separated,list...> keyOrder: <array|function>

A configuration file will be searched for using cosmiconfig rules:

  • prettier-package-json field in package.json.
  • prettier-package-json file (JSON or YAML), extentionless "rc" file.
  • prettier-package-json file with the extensions .json, .yaml, .yml, .js, or .cjs.
  • prettier-package-json.config.js or prettier-package-json.config.cjs CommonJS module.

Configuration file may also be passed using the --config CLI parameter.

Contributing

See CONTRIBUTING.md.

prettier-package-json's People

Contributors

apfelbox avatar cameronhunter avatar dependabot[bot] avatar djcsdy avatar dzearing avatar friederbluemle avatar ionaru avatar jamesgelok avatar jorenbroekema avatar mykhalov avatar ofk avatar papandreou avatar sunesimonsen avatar yinzara avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

prettier-package-json's Issues

Scripts like `prettify` are sorted in wrong order

If I have a JSON file like this:

{
  "scripts": {
    "prepare": "echo prepare",
    "preprettify": "echo preprettify",
    "prettify": "echo prettify",
    "postprettify": "echo postprettify",
    "prestart": "echo prestart",
    "start": "echo start",
    "watch": "echo watch"
  }
}

Then the tool sorts this to:

{
  "scripts": {
    "prepare": "echo prepare",
    "preprettify": "echo preprettify",
    "postprettify": "echo postprettify",
    "prestart": "echo prestart",
    "start": "echo start",
    "prettify": "echo prettify",
    "watch": "echo watch"
  }
}

Note the position of prettify. It is treating prettify as the pre script of ttify. Your smart sorting logic should be modified to check if ttify is there as a key, then only consider prettify as a pre script.

The fix can be approached like this: https://github.com/brc-dd/prettier-package-json/blob/main/src/sort-scripts.ts. The project's coding style is different that what I did there, that's why I am not creating a PR.

should not publish tests folder

I try to use flow and it throw this:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/prettier-package-json/tests/__fixtures__/invalid.json:2:10

Unexpected identifier

     1 {
     2     this is: invalid JSON
     3 }
     4

I can ignore this, but I think this folder should not be published.

prettier-package-json sorts dependencies differently than npm

In case a dependency has an uppercase letter in the name, the order of the dependencies might be different:

% npm init --yes         
Wrote to /Users/mykhalov/test/package.json:

{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": ""
}


% npm i Select2      

added 1 package in 1s
% npm i select2

added 1 package, and removed 1 package in 922ms
% cat package.json 
{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "select2": "^4.1.0-rc.0",
    "Select2": "^3.5.7"
  }
}
% npx prettier-package-json
{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "license": "ISC",
  "author": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "Select2": "^3.5.7",
    "select2": "^4.1.0-rc.0"
  },
  "keywords": []
}

This is inconvenient because every time you install something, you also have to run prettier-package-json.

Disable script sorting?

I prefer to manually sort my scripts. Can you add an option to disable the sorting of scripts?

Consideration of multiple delimiters for sorting scripts

There is a task runner package called npm-run-all which is used in the development of prettier, among other things.
This task runner uses : and / as delimiters for script names (ref).

As a result, scripts are often written like this:

{
  "scripts": {
    "lint": "npm-run-all lint:*",
    "lint:eslint": "eslint .",
    "lint:prettier": "prettier . --check",
    "lint-fix": "npm-run-all lint-fix:*",
    "lint-fix:eslint": "eslint . --fix",
    "lint-fix:prettier": "prettier . --write"
  }
}

However, prettier-package-json does not consider these delimiters when sorting, resulting in the following order:

{
  "scripts": {
    "lint": "npm-run-all lint:*",
    "lint-fix": "npm-run-all lint-fix:*",
    "lint-fix:eslint": "eslint . --fix",
    "lint-fix:prettier": "prettier . --write",
    "lint:eslint": "eslint .",
    "lint:prettier": "prettier . --check"
  }
}

Are there plans to add this sort of consideration, or would a pull request for this be accepted?

For reference I am considering the following sorting:

const scripts='lint lint-fix lint-fix:eslint lint-fix:prettier lint:eslint lint:prettier'.split(' ');

scripts.sort((a, b) => {
  const aa = a.split(/([:/])/);
  const bb = b.split(/([:/])/);
  const al = aa.length;
  const bl = bb.length;
  for (let i = 0; i < Math.min(al, bl); i++) {
    if (aa[i] !== bb[i]) {
      return aa[i] < bb[i] ? -1 : 1;
    }
  }
  if (al !== bl) {
    return al < bl ? -1 : 1;
  }
  return 0;
});

console.log(scripts); // => ['lint', 'lint:eslint', 'lint:prettier', 'lint-fix', 'lint-fix:eslint', 'lint-fix:prettier']

Package sort order different than npm install

For my current project, I've been noticing the sort order of my packages change every time I run npm install. Specifically in this case, this package sorts dashes before underscores but npm install puts underscores first. It would be ideal if these followed the same convention.

image

prettier-package-json -> npm install

please explain the reasoning behind the "opinionated order"

Correct me if I'm wrong, but according to this opinionated setup, not always dependencies and devdependencies are the last keys in package.json. We have keys following them:

'keywords',
'engines',
'engine-strict',
'engineStrict',
'os',
'cpu',
'publishConfig'

Now the reason why we put things at the bottom is easy access for consumers.

@cameronhunter With full respect, Cameron, please explain to all the visitors here why do you need easier access to engines, os or cpu instead of dependencies and devdependencies?

My arguments against this are: engines should be a badge in readme anyway, keywords are set only once and matter only to author (so putting that at the bottom is quite egotist thing to do), os/cpu are never used.

One more observation; I noticed that your all of your own libraries are not using this order, for example, (local-ssl-proxy)[https://github.com/cameronhunter/local-ssl-proxy] - on the contrary, they have the old sensible order in package.json with dependencies and devdependencies at the bottom.

Sort of files property has undesired side-effect

A files property like this:

  "files": [
    "bin",
    "lib",
    "!lib/**/*.test.js"
  ],

Is rearranged as:

  "files": [
    "!lib/**/*.test.js"
    "bin",
    "lib",
  ],

However, for the first version npm pack will ignore .test.js files, while in the second version lib takes precedence and .test.js files are included. This is a bug since ideally re-formatting the package.json should not have any side-effect.

Sort scripts alphabetically without pre/post?

Would like to use this, but with sorting scripts alphabetically without considering pre/post scripts.

Example output:

{
  "name": "prettier-package-json",
  "version": "1.0.1",
  "scripts": {
    "build": "build",
    "postversion": "postversion",
    "pretest": "pretest",
    "test": "test",
    "version": "version"
  }
}

[Feature] add --check option to CLI

Hi there,

Thanks so much for making this package. I was wondering if it would be possible to add a --check option to the CLI so we could check if our package.json files are formatted correctly without having to write to them.

Thanks!

invalid JSON test failing on main branch

Problem

invalid JSON test failing on main

Steps to recreate

  1. Run yarn test

Additional notes

I wanted to make this issue because I also experienced this issue while trying to work on this library.

Originally posted by @brc-dd in #44 (comment)

@cameronhunter Actually I had linked a fix above can you check that if it's fine or not (for me it was working fine, and also working with your existing snapshot)? Also, one of your tests (invalid JSON one) is failing on your main branch itself. Here are the logs:

➜ yarn test
yarn run v1.22.5
$ jest
 PASS  tests/script-order.test.ts
 PASS  tests/use-tabs.test.ts
 PASS  tests/tab-width.test.ts
 PASS  tests/sort-contributors.test.ts
 PASS  tests/sort-files.test.ts
 PASS  tests/key-order.test.ts
 FAIL  tests/command-line.test.ts (6.573 s)
  ● prettier-package-json --list-different tests\__fixtures__\invalid.json

    expect(received).toMatch(expected)

    Expected pattern: /tests\/__fixtures__\/invalid\.json: Unexpected token t in JSON at position 6/
    Received string:  "SyntaxError: tests/__fixtures__/invalid.json: Unexpected token t in JSON at position 7
        at JSON.parse (<anonymous>)
        at Object._readFile (C:\\Users\\brc-dd\\Desktop\\prettier-package-json\\node_modules\\jsonfile\\index.js:25:16)
        at async check (C:\\Users\\brc-dd\\Desktop\\prettier-package-json\\bin\\prettier-package-json:91:18)
        at async Promise.all (index 0)
    "

      29 |   expect(result.exitCode).toBe(1);
      30 |   expect(result.stdout).toBe('');
    > 31 |   expect(result.stderr).toMatch(/tests\/__fixtures__\/invalid\.json: Unexpected token t in JSON at position 6/);
         |                         ^
      32 | });
      33 |

      at tests/command-line.test.ts:31:25

 › 7 snapshots written.
 › 7 snapshots obsolete.
   • prettier-package-json --config tests/__fixtures__/prettier-package-json.config.js tests/__fixtures__/package-1.json 1
   • prettier-package-json --list-different tests/__fixtures__/missing.json 1
   • prettier-package-json --list-different tests/__fixtures__/package-*.json 1
   • prettier-package-json --tab-width 8 tests/__fixtures__/package-1.json 1
   • prettier-package-json --use-tabs tests/__fixtures__/package-1.json 1
   • prettier-package-json tests/__fixtures__/package-*.json 1
   • prettier-package-json tests/__fixtures__/package-1.json 1
Snapshot Summary
 › 7 snapshots written from 1 test suite.
 › 7 snapshots obsolete from 1 test suite. To remove them all, run `yarn test -u`.
   ↳ tests/command-line.test.ts
       • prettier-package-json --config tests/__fixtures__/prettier-package-json.config.js tests/__fixtures__/package-1.json 1
       • prettier-package-json --list-different tests/__fixtures__/missing.json 1
       • prettier-package-json --list-different tests/__fixtures__/package-*.json 1
       • prettier-package-json --tab-width 8 tests/__fixtures__/package-1.json 1
       • prettier-package-json --use-tabs tests/__fixtures__/package-1.json 1
       • prettier-package-json tests/__fixtures__/package-*.json 1
       • prettier-package-json tests/__fixtures__/package-1.json 1

Test Suites: 1 failed, 6 passed, 7 total
Tests:       1 failed, 24 passed, 25 total
Snapshots:   7 obsolete, 7 written, 17 passed, 24 total
Time:        19.69 s, estimated 20 s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

[FEATURE request] Please add validation of `name` property

I've had issue with tsc not compiling my project due to name problem. Basically, it can contain only 1 slash / character. In my case there were 2 of them

Here is the warning shown to me by VSCode when 2 slashes used
String does not match the pattern of "^(?:(?:@(?:[a-z0-9-*~][a-z0-9-*._~]*)?/[a-z0-9-._~])|[a-z0-9-~])[a-z0-9-._~]*$". The name of the package.

Would be great to add same validation to this package. Thanks

Some refs to the problem: nrwl/nx#15464 (comment)


Or maybe just validating entire package.json with this schema? https://www.schemastore.org/schemas/json/package.json

Support for defining options through a config file

Right now it is possible to customize the behavior through command line arguments. It would be nice if there was also an option to define a custom config file (and maybe use a default .ppjrc.js or similar if one exists).

Allow different options for sorting scripts

In some scenarios, it might be helpful to optionally skip sorting the scripts object, or apply a simple alphabetical ordering (instead of the "smart" sort that is the default for prettier-package-json.

bundleDependencies property is rewritten incorrectly

Input:

{
  "name": "awesome-web-framework",
  "version": "1.0.0",
  "bundleDependencies": [
    "renderized",
    "super-streams"
  ]
}

Output:

{
  "name": "awesome-web-framework",
  "version": "1.0.0",
  "bundleDependencies": {
    "0": "renderized",
    "1": "super-streams"
  }
}

Expected output: same as input.

The bundleDependencies field is defined as an array, see: https://docs.npmjs.com/cli/v8/configuring-npm/package-json#bundledependencies

It can also be spelled bundledDependencies (with an extra d), in which case the same problem occurs.

Can "version" field be given higher precedence?

The "name" and "version" are arguably the most important package.json fields. People probably rely on these two fields more than any other when trying to understand package.json relationships.

With the current ordering, "version" is buried below less interesting fields. These other fields are also optional, which means their shape changes from file to file:

{
  "name": "prettier-package-json",
  "description": "Prettier formatter for package.json files",
  "license": "MIT",
  "author": "Cameron Hunter <[email protected]>",
  "repository": {
    "type": "git",
    "url": "https://github.com/cameronhunter/prettier-package-json"
  },
  "bugs": "https://github.com/cameronhunter/prettier-package-json/issues",
  "version": "2.1.3",  // <----- 🔍 where's the version... oh there it is!
  "main": "src/index.js",
  "bin": {
    "prettier-package-json": "./bin/prettier-package-json"
  },

Can we move it higher up?

{
  "name": "prettier-package-json",
  "version": "2.1.3",
  "description": "Prettier formatter for package.json files",
  "license": "MIT",
  "author": "Cameron Hunter <[email protected]>",
  "repository": {
    "type": "git",
    "url": "https://github.com/cameronhunter/prettier-package-json"
  },
  "bugs": "https://github.com/cameronhunter/prettier-package-json/issues",
  "main": "src/index.js",
  "bin": {
    "prettier-package-json": "./bin/prettier-package-json"
  },

The change to keyOrder could be like this:

  keyOrder: [
    /**
     * Details
     */
    '$schema',
    'name',
    'version', // <----- moved up
    'private', // <----- moved down, because this determines the meaning of the "version"
    'description',
    'license',
    'author',
    'maintainers',
    'contributors',
    'homepage',
    'repository',
    'bugs',
    'type',

(These options are customizable. My interest here is to improve the "opinionated" standard that prettier-package-json is promoting.)

Comments in package.json scripts section, and custom styles

What about trying addressing this issue ?
https://stackoverflow.com/questions/14221579/how-do-i-add-comments-to-package-json-for-npm-install

As an attempt, I fork your repo and try my own solutions, but I would like your inputs.
Is that something you would like to merge in your own repo ?
Here's my fork :
https://github.com/long-lazuli/package-json-tamer

It's not quite clean, now. Work in progress.

What it does, is allow a '--scripts-key-order' option.
And it also detect "\n" and "\r" in scripts.

so it can convert this (snapshot of a package.json scripts section after adding a new deps) :

  "scripts": {
    "\n# Developpement tools:": "\r# > Both are executed by `npm start`",
    "start-dev": "run-p -s -r watch serve",
    "watch": "ENV=dev run-p -s -l \"task:* -- --watch\"",
    "serve": "lite-server --baseDir=\"_dist\"",
    "\n# Production tools:": "\r# > Deploy will build project for Production, before sending `_dist` folder to `gh-pages`",
    "deploy": "chpm run build; B=gh-pages git subtree split -P _dist -b $B; git push -f origin $B:$B; git branch -D $B",
    "build": "ENV=prod run-p -ss -l --aggregate-output task:*; run-p -s -l --aggregate-output minify:*",
    "\n# Building tasks:": "\r# > These tasks are executed by `build` or `watch`, for Dev or Prod env.",
    "task:assets": "cpx \"_assets/**\" _dist",
    "task:css": "stylus --include-css -u autoprefixer-stylus -m _sources/index.styl --out _dist/index.css",
    "task:html": "pug -O \"{ENV: '${ENV}'}\" -P -b _sources/ -p _sources/ _sources/index.pug --pretty -o _dist/",
    "task:js": "tsc-bundle --project tsconfig.json --pretty",
    "\n# Optimizing tasks": "\r# > These tasks are only executed by `build`, for Production.",
    "minify:css": "postcss _dist/index.css -u cssnano -m -o _dist/index.min.css"
  },

to this :

  "scripts": {
  
  "\n# Developpement tools:":
  "\r# > Both are executed by `npm start`",
    "start-dev": "run-p -s -r watch serve",
    "watch": "ENV=dev run-p -s -l \"task:* -- --watch\"",
    "serve": "lite-server --baseDir=\"_dist\"",
  
  "\n# Production tools:":
  "\r# > Deploy will build project for Production, before sending `_dist` folder to `gh-pages`",
    "deploy": "chpm run build; B=gh-pages git subtree split -P _dist -b $B; git push -f origin $B:$B; git branch -D $B",
    "build": "ENV=prod run-p -ss -l --aggregate-output task:*; run-p -s -l --aggregate-output minify:*",
  
  "\n# Building tasks:":
  "\r# > These tasks are executed by `build` or `watch`, for Dev or Prod env.",
    "task:assets": "cpx \"_assets/**\" _dist",
    "task:css": "stylus --include-css -u autoprefixer-stylus -m _sources/index.styl --out _dist/index.css",
    "task:html": "pug -O \"{ENV: '${ENV}'}\" -P -b _sources/ -p _sources/ _sources/index.pug --pretty -o _dist/",
    "task:js": "tsc-bundle --project tsconfig.json --pretty",
  
  "\n# Optimizing tasks":
  "\r# > These tasks are only executed by `build`, for Production.",
    "minify:css": "postcss _dist/index.css -u cssnano -m -o _dist/index.min.css"
  
  },

with this command :
package-json-tamer --write --scripts-key-order '# Dev,start,watch,serve,# Prod,deploy,build,# Build,task:,# Opt,minify:'

I still need to make more documentation.
I also need to add options :

  • newLinesOnBackslash: boolean
  • indentationOnNewLine: 0, 1, 2
  • newLineAfterScripts: true/false/auto(if a new line at begin)

I used this syntax in my projects ( \n# and \r# > ) because of the result when you type npm run :

Scripts available in ######## via `npm run-script`:

# Developpement tools:
# > Both are executed by `npm start`
  start-dev
    run-p -s -r watch serve
  watch
    ENV=dev run-p -s -l "task:* -- --watch"
  serve
    lite-server --baseDir="_dist"

# Production tools:
# > Deploy will build project for Production, before sending `_dist` folder to `gh-pages`
  deploy
    chpm run build; B=gh-pages git subtree split -P _dist -b $B; git push -f origin $B:$B; git branch -D $B
  build
    ENV=prod run-p -ss -l --aggregate-output task:*; run-p -s -l --aggregate-output minify:*

# Building tasks:
# > These tasks are executed by `build` or `watch`, for Dev or Prod env.
  task:assets
    cpx "_assets/**" _dist
  task:css
    stylus --include-css -u autoprefixer-stylus -m _sources/index.styl --out _dist/index.css
  task:html
    pug -O "{ENV: '${ENV}'}" -P -b _sources/ -p _sources/ _sources/index.pug --pretty -o _dist/
  task:js
    tsc-bundle --project tsconfig.json --pretty

# Optimizing tasks
# > These tasks are only executed by `build`, for Production.
  minify:css
    postcss _dist/index.css -u cssnano -m -o _dist/index.min.css

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.