Skip to content

Commit

Permalink
Merge pull request #6 from mudlabs/allow-no-package
Browse files Browse the repository at this point in the history
Allow no package
  • Loading branch information
mudlabs authored Oct 11, 2020
2 parents cfbfbdc + 74d01a5 commit 6ceacf2
Show file tree
Hide file tree
Showing 9 changed files with 372 additions and 36 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
| Prop | Description | Default |
| :--- | :--- | :--- |
| `clean` | Specifies the action should edit the configuration file apon execution. This way every time you update the file it's a clean list of commands. Only the `install`, `update`, and `uninstall` arrays will be emptied, and they will be regardless of the package execution outcome. | `false` |
| `init` | Specifies the action should create a `package.json` file at `path` if one is not there. If the package does need to init, it will do so using `npm init -y`. | `true` |
| `issue` | You may provide an issue number to track activity. If set this action will post comments to the issue detailing what has changed, whenever it runs. For an example of what these comments will look like see the [Test Logs](https://github.com/mudlabs/npm-worker/issues/4) issue. | |
| `path` | Specifies a path from your repository _root_, where you would like _node_modules_ located. | `./` |
| `install` | An array of npm packages you want installed. | |
Expand All @@ -81,6 +82,7 @@ jobs:
```yaml
# Example Configuration
clean: true
init: true
issue: 1
path: ./dis
install:
Expand All @@ -104,7 +106,6 @@ uninstall:


## Notes
- If no `package.json` file is located at `path`, the action will create one using `npm init -y`.
- If you want the `node_modules` and `packages` to persist on your repository you will need to commit the changes. I recommend using the [Add and Commit](https://github.com/marketplace/actions/add-commit) action for this.
- You can not chain executions. Each array item is checked for, and broken at any instance of `&&`.
- Each array item is executed as `npm x item` _(i.e. npm install unirest)_.
8 changes: 6 additions & 2 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ const getWorkerConfigPath = workflow => {
return found_config_path;
};

const initJSON = async path => {
const initJSON = path => async init => {
try {
const file_path = `${path}/package.json`;

if (init === false) return;
if (fs.existsSync(file_path)) return;

const {stdout} = await execa.command('npm init -y');
const json = stdout.substring(stdout.indexOf("{"));
await fs.promises.writeFile(file_path, json);
Expand Down Expand Up @@ -118,7 +122,7 @@ const initJSON = async path => {
const has_package_json = fs.existsSync(`${node_modules_path}/package.json`);

if (!valid_node_modules_path) return core.setFailed(`The path for node_modules does not exist.`);
if (!has_package_json) await initJSON(node_modules_path);
if (!has_package_json) await initJSON(node_modules_path)(data.init);

const installed = await shell("install")(data.install)(node_modules_path);
const updated = await shell("update")(data.update)(node_modules_path);
Expand Down
121 changes: 121 additions & 0 deletions test/node_modules/short-scale-units/README.md

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

40 changes: 40 additions & 0 deletions test/node_modules/short-scale-units/dist/index.d.ts

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

111 changes: 111 additions & 0 deletions test/node_modules/short-scale-units/dist/index.js

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

Loading

0 comments on commit 6ceacf2

Please sign in to comment.