Skip to content

Commit

Permalink
feat: add the rename input parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Sep 2, 2022
1 parent 416f37d commit 558c26a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
build:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand All @@ -33,13 +33,13 @@ jobs:

- name: Create Tag
id: create_tag
uses: jaywcjlove/create-tag-action@v1.3.7
uses: jaywcjlove/create-tag-action@main
with:
package-path: ./package.json

- name: get tag version
id: tag_version
uses: jaywcjlove/changelog-generator@v1.5.7
uses: jaywcjlove/changelog-generator@main

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
Expand Down Expand Up @@ -67,10 +67,11 @@ jobs:
id: info2
uses: ./
with:
data: |
{
"name": "@jaywcjlove/github-action-package-test"
}
rename: "@jaywcjlove/github-action-package-test"
# data: |
# {
# "name": "@jaywcjlove/github-action-package-test"
# }

- run: echo "name - ${{ steps.info2.outputs.name }}"
- run: echo "version - ${{ steps.info2.outputs.version }}"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Read and modify the contents of `package.json`.
- `path` The path of the `package.json` file. Default: `package.json`
- `data` json data for changing `package.json`. Default: `{}`
- `rename` Used to change "name" data in "package.json".

### Output Parameters

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ inputs:
description: json data for changing "package.json".
required: false

rename:
description: Used to change "name" data in "package.json".
required: false

outputs:
name:
description: 'name field in package.json, The name of the package.'
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { setFailed, setOutput, getInput, info, startGroup, endGroup } from '@act
try {
const pkgPath = getInput('path');
const data = getInput('data');
const rename = getInput('rename');
const resolvePath = path.resolve(process.cwd(), pkgPath);

if (!fs.existsSync(resolvePath)) {
Expand All @@ -20,6 +21,11 @@ import { setFailed, setOutput, getInput, info, startGroup, endGroup } from '@act
await fs.promises.writeFile(resolvePath, JSON.stringify(jsonObj, null, 2));
}

if (rename) {
jsonObj = Object.assign(jsonObj, { name: rename });
await fs.promises.writeFile(resolvePath, JSON.stringify(jsonObj, null, 2));
}

startGroup(`\x1b[32;1m package.json\x1b[0m content: `);
info(`${JSON.stringify(jsonObj, null, 2)}`);
endGroup();
Expand Down

0 comments on commit 558c26a

Please # to comment.