-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ab09bc6
Showing
29 changed files
with
5,591 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changesets | ||
|
||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works | ||
with multi-package repos, or single-package repos to help you version and publish your code. You can | ||
find the full documentation for it [in our repository](https://github.com/changesets/changesets) | ||
|
||
We have a quick list of common questions to get you started engaging with this project in | ||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": ["@changesets/changelog-github", { "repo": "duniul/sort-jsonc " }], | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "restricted", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Test output | ||
coverage | ||
.coverage | ||
|
||
# Node stuff | ||
node_modules/ | ||
.node_repl_history | ||
|
||
# Caches | ||
.npm | ||
.eslintcache | ||
.cache | ||
|
||
# Packaged packages | ||
*.tgz | ||
|
||
# Yarn (see https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored) | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/releases | ||
!.yarn/plugins | ||
!.yarn/sdks | ||
!.yarn/versions | ||
.pnp.* | ||
.yarn-state.yml | ||
.yarn-integrity | ||
|
||
# Local configs and environment variables | ||
.env | ||
.config | ||
.config.* | ||
|
||
# Built files | ||
**/dist | ||
**/lib | ||
|
||
# .DS_Store | ||
.DS_Store | ||
|
||
# Temp files | ||
tmp/ | ||
|
||
# WebStorm/IntelliJ | ||
.idea/* | ||
|
||
# VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
*.code-workspace | ||
|
||
# TypeScript | ||
*.tsbuildinfo | ||
|
||
# Turbo | ||
.turbo | ||
|
||
# NextJS | ||
.next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"singleQuote": true, | ||
"printWidth": 140, | ||
"proseWrap": "always", | ||
"arrowParens": "avoid" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Daniel Grefberg | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# sort-jsonc monorepo | ||
|
||
Mini-monorepo for `sort-jsonc` and `sort-jsonc-cli`. | ||
|
||
## Packages | ||
|
||
| Package | Version | Description | | ||
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------------- | | ||
| [`sort-jsonc`](./packages/sort-jsonc) | [![npm](https://img.shields.io/npm/v/sort-jsonc.svg)](https://www.npmjs.com/package/sort-jsonc) | Sort JSONC/JSON5 without mangling comments! | | ||
| [`sort-jsonc-cli`](./packages/sort-jsonc-cli) | [![npm](https://img.shields.io/npm/v/sort-jsonc-cli.svg)](https://www.npmjs.com/package/sort-jsonc-cli) | Use `sort-jsonc` directly via the CLI. | | ||
|
||
## Motivation | ||
|
||
Lots of JSON files today are actually JSONC, or "JSON with comments", under the hood. Files like `tsconfig.json` or `.vscode/settings.json`. | ||
[JSON5](https://json5.org/) also allows comments. | ||
|
||
Tools for deep-sorting JSON files are common and frequently used, but they tend to either strip, mangle or simply not support comments. I | ||
needed an easy util (and CLI tool) for this specific use case and couldn't find a nice one, so I made these. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "sort-jsonc-monorepo", | ||
"version": "1.0.0", | ||
"description": "Monorepo for sort-jsonc and related packages.", | ||
"author": "Daniel Grefberg <[email protected]>", | ||
"license": "MIT", | ||
"private": true, | ||
"packageManager": "[email protected]", | ||
"engines": { | ||
"node": ">=18", | ||
"pnpm": ">=7" | ||
}, | ||
"scripts": { | ||
"changeset": "changeset", | ||
"changeset:status": "changeset status", | ||
"changeset:version": "changeset version", | ||
"format": "rome format src --write", | ||
"packages:build": "pnpm -r run build", | ||
"packages:test": "pnpm -r run test", | ||
"packages:sort-packagejson": "pnpm -r exec sort-jsonc ./package.json --order-file ../../sort-order.json", | ||
"lint": "rome check src", | ||
"lint:fix": "rome check src --apply-suggested", | ||
"preinstall": "npx only-allow pnpm", | ||
"sort:packagejson": "sort-jsonc ./package.json --order-file ./sort-order.json" | ||
}, | ||
"devDependencies": { | ||
"@changesets/changelog-github": "^0.4.8", | ||
"@changesets/cli": "^2.26.1", | ||
"cross-env": "^7.0.3", | ||
"prettier": "^2.8.7", | ||
"rome": "^11.0.0", | ||
"sort-jsonc-cli": "^0.1.0", | ||
"typescript": "^5.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# sort-jsonc-cli | ||
|
||
[![npm](https://img.shields.io/npm/v/sort-jsonc-cli.svg)](https://www.npmjs.com/package/sort-jsonc-cli) | ||
|
||
✅ CLI for sort JSONC/JSON5 files without mangling comments! | ||
|
||
<sup><i>Works with regular JSON files too, of course!</i></sup> | ||
|
||
See [sort-jsonc](../sort-jsonc) for the underlying library. | ||
|
||
## Usage | ||
|
||
```sh | ||
sort-jsonc [options] <files> | ||
``` | ||
|
||
## Options | ||
|
||
| Option | Alias | Description | | ||
| ------------------- | ----- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `--order` | `-o` | The preferred order to sort keys as a comma-separated string. Prioritized over `--order-file`. Keys not in this list will be sorted alphabetically at the end. | | ||
| `--order-file` | `-O` | Path to a JSON file containing a list of strings in preferred order. Keys not in this list will be sorted alphabetically at the end. | | ||
| `--remove-comments` | `-c` | Whether to remove comments from the JSON. | | ||
| `--spaces` | `-S` | Number of spaces to indent the JSON. | | ||
| `--silent` | `-s` | Whether to suppress output. | | ||
| `--help` | `-v` | Show help info. | | ||
|
||
## Examples | ||
|
||
#### Sort a file | ||
|
||
```sh | ||
$ sort-jsonc sort-jsonc path/to/file.jsonc | ||
``` | ||
|
||
#### Sort multiple files | ||
|
||
```sh | ||
$ sort-jsonc path/to/file1.jsonc path/to/file2.jsonc | ||
``` | ||
|
||
#### Sort a file by preferred order | ||
|
||
```sh | ||
$ sort-jsonc sort-jsonc path/to/file.jsonc -o name,version,description | ||
``` | ||
|
||
#### Sort a file by preferred order from a file | ||
|
||
```sh | ||
$ sort-jsonc sort-jsonc path/to/file.jsonc -O path/to/order.json | ||
``` | ||
|
||
#### Sort a file and remove comments | ||
|
||
```sh | ||
$ sort-jsonc sort-jsonc path/to/file.jsonc -c | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
(async () => { | ||
await import('../dist/cli.js'); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"name": "sort-jsonc-cli", | ||
"version": "0.1.0", | ||
"description": "CLI for sorting JSONC/JSON5 without mangling comments!", | ||
"author": "Daniel Grefberg <[email protected]>", | ||
"homepage": "https://github.com/duniul/sort-jsonc/issues", | ||
"bugs": "https://github.com/duniul/sort-jsonc/issues", | ||
"repository": { | ||
"url": "https://github.com/duniul/sort-jsonc.git", | ||
"directory": "packages/sort-jsonc-cli", | ||
"type": "git" | ||
}, | ||
"license": "MIT", | ||
"keywords": [ | ||
"cli", | ||
"sort", | ||
"json", | ||
"jsonc", | ||
"json5", | ||
"json-comments", | ||
"comments" | ||
], | ||
"bin": { | ||
"sort-jsonc": "bin/cli.js" | ||
}, | ||
"files": [ | ||
"dist", | ||
"README.md" | ||
], | ||
"type": "module", | ||
"engines": { | ||
"node": ">= 6" | ||
}, | ||
"scripts": { | ||
"bin": "node ./bin/cli.js", | ||
"build": "tsup", | ||
"dev": "tsup --watch", | ||
"prepublish": "npm run build", | ||
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests" | ||
}, | ||
"dependencies": { | ||
"clipanion": "^3.2.0", | ||
"comment-json": "^4.2.3", | ||
"sort-jsonc": "^0.1.0" | ||
}, | ||
"devDependencies": { | ||
"@swc/core": "^1.3.42", | ||
"@swc/jest": "^0.2.24", | ||
"@tsconfig/node14": "^1.0.3", | ||
"@tsconfig/strictest": "^2.0.0", | ||
"@types/jest": "^29.5.0", | ||
"@types/node": "^14", | ||
"jest": "^29.5.0", | ||
"tsup": "^6.7.0", | ||
"typescript": "^5.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Builtins, Cli } from 'clipanion'; | ||
import { createRequire } from 'node:module'; | ||
import path from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { GenerateCommand } from './commands/sort-jsonc'; | ||
|
||
const [_node, _app, ...args] = process.argv; | ||
const esmRequire = createRequire(import.meta.url); | ||
const cliDir = path.dirname(fileURLToPath(import.meta.url)); | ||
const packageJson = esmRequire(path.resolve(path.dirname(cliDir), './package.json')); | ||
|
||
const cli = new Cli({ | ||
binaryLabel: packageJson.name, | ||
binaryVersion: packageJson.version, | ||
binaryName: 'sort-jsonc', | ||
}); | ||
|
||
cli.register(GenerateCommand); | ||
cli.register(Builtins.HelpCommand); | ||
|
||
cli.runExit(args); |
Oops, something went wrong.