Skip to content

Commit

Permalink
update project
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 13, 2023
1 parent 9c3d08c commit 0f47a7e
Show file tree
Hide file tree
Showing 22 changed files with 4,298 additions and 3,699 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8

[*.js]
indent_style = space
indent_size = 2

[{package.json,*.yml,*.cjson}]
indent_style = space
indent_size = 2
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules
coverage
dist

7 changes: 4 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": [
"@nuxtjs/eslint-config-typescript"
]
"extends": ["eslint-config-unjs"],
"rules": {
"no-useless-constructor": 0
}
}
42 changes: 11 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,16 @@ on:

jobs:
ci:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest]
node: [14]

runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: checkout
uses: actions/checkout@master

- name: cache node_modules
uses: actions/cache@v1
- uses: actions/checkout@v3
- run: corepack enable
- uses: actions/setup-node@v3
with:
path: node_modules
key: ${{ matrix.os }}-node-v${{ matrix.node }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }}

- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: yarn

- name: Lint
run: yarn lint

- name: Test
run: yarn dev

# - name: Coverage
# uses: codecov/codecov-action@v1
node-version: 18
cache: "pnpm"
- run: pnpm install
- run: pnpm lint
- run: pnpm build
- run: pnpm vitest --coverage
- uses: codecov/codecov-action@v3
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
node_modules
coverage
dist
*.log
types
.vscode
.DS_Store
.eslintcache
*.log*
*.conf*
*.env*
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 0 additions & 5 deletions CHANGELOG.md

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021
Copyright (c) Pooya Parsa <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
73 changes: 48 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# 🧀 Paneer

Modify code like a cheese! Using [recast](https://github.com/benjamn/recast) for AST modifications.
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Github Actions][github-actions-src]][github-actions-href]
[![Codecov][codecov-src]][codecov-href]

Modify code like a cheese! Powered by [recast](https://github.com/benjamn/recast) for AST modifications.

## Usage

Expand All @@ -12,18 +17,21 @@ yarn add --dev paneer

# using npm
npm install -D paneer

# using pnpm
pnpm add -D paneer
```

Import utilities:

```js
// ESM / Bundler
import { parse, compile } from 'paneer'
import * as p from 'paneer'
import { parseCode, generateCode } from "paneer";
import * as p from "paneer";

// CommonJS
const { parse, compile } = require('panner')
const p = require('panner')
const { parseCode, generateCode } = require("panner");
const p = require("panner");
```

**Example:** Modify a file:
Expand All @@ -32,51 +40,66 @@ const p = require('panner')

```js
export default {
foo: ['a']
}
foo: ["a"],
};
```

Code to modify and append `b` to `foo` prop of defaultExport:

```js
import { load, write } from 'paneer'
import { loadFile, writeFile } from "paneer";

const ast = await load('config.js')
const _module = await loadFile("config.js");

ast.exports.default.props.foo.push('b')
_module.exports.default.props.foo.push("b");

await write(ast)
await writeFile(_module);
```

Updated `config.js`:

```js
export default {
foo: ['a', "b"]
}
foo: ["a", "b"],
};
```

**Example:** Directly use AST utils:

```js
import * as p from 'paneer'
import { parseCode, generateCode } from "paneer";

// Parse to AST
const ast = p.parse(`export default { foo: ['a'] }`)

// Find default export
const defaultExport = p.defaultExport(ast)
const _module = parseCode(`export default { foo: ['a'] }`);

// Get foo prop of object
const foo = p.get(p.defaultExport(ast), 'foo')

// Push 'b' literal to array
p.push(foo, 'b')
// Add a new array member
_module.exports.default.props.foo.push("b");

// Generate code
const { code, map } = p.generate(node)
const { code, map } = generateCode(_module);
```

## Development

- Clone this repository
- Install latest LTS version of [Node.js](https://nodejs.org/en/)
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
- Install dependencies using `pnpm install`
- Run interactive tests using `pnpm dev`

## License

MIT
Made with 💛

Published under [MIT License](./LICENSE).

<!-- Badges -->

[npm-version-src]: https://img.shields.io/npm/v/packageName?style=flat-square
[npm-version-href]: https://npmjs.com/package/packageName
[npm-downloads-src]: https://img.shields.io/npm/dm/packageName?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/packageName
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/packageName/ci/main?style=flat-square
[github-actions-href]: https://github.com/unjs/packageName/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/packageName/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/packageName
43 changes: 26 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
{
"name": "paneer",
"version": "0.0.1",
"description": "Modify code like cheese!",
"version": "0.1.0",
"description": "",
"repository": "unjs/paneer",
"license": "MIT",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"require": "./dist/index.cjs"
}
},
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "siroc build",
"dev": "jiti test/test.ts",
"lint": "eslint --ext .js,.ts .",
"prepack": "yarn build",
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
"test": "yarn lint"
"build": "unbuild",
"dev": "vitest dev",
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test",
"lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test -w",
"prepack": "pnpm run build",
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
"test": "pnpm lint && vitest run --coverage"
},
"dependencies": {
"recast": "^0.20.4"
"recast": "^0.22.0",
"@types/estree": "^1.0.0"
},
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "latest",
"eslint": "latest",
"jiti": "latest",
"siroc": "latest",
"standard-version": "latest"
}
"@types/node": "^18.13.0",
"@vitest/coverage-c8": "^0.28.4",
"changelogen": "^0.4.1",
"eslint": "^8.34.0",
"eslint-config-unjs": "^0.1.0",
"prettier": "^2.8.4",
"typescript": "^4.9.5",
"unbuild": "^1.1.1",
"vitest": "^0.28.4"
},
"packageManager": "[email protected]"
}
Loading

0 comments on commit 0f47a7e

Please sign in to comment.