Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Add a publish flow with "without-cli" version
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien0102 committed Feb 17, 2020
1 parent 3cc18eb commit b930d47
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 10 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/npm-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Npm publish

on:
push:
branches:
- master
paths:
- package.json

jobs:
npm-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: yarn
- run: yarn build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
npm-publish-without-cli:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: yarn
- run: yarn build
- run: node publish-without-cli.js
- run: npm publish --tag without-cli
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# `restful-react`

[![npm](https://img.shields.io/npm/v/restful-react.svg)](https://www.npmjs.com/package/restful-react)
[![Build Status](https://img.shields.io/travis/contiamo/restful-react.svg)](https://travis-ci.org/contiamo/restful-react)

Building React apps that interact with a RESTful API presents a set of questions, challenges and potential gotchas. This project aims to remove such pitfalls, and provide a pleasant developer experience when crafting such applications. It can be considered a thin wrapper around the [fetch API](https://developer.mozilla.org/en/docs/Web/API/Fetch_API) in the form of React components and hooks.

Expand Down Expand Up @@ -640,15 +639,15 @@ interface RestfulReactConfig {
base?: string;
};
customGenerator?: (data: {
componentName: string;
verb: string;
route: string;
description: string;
genericsTypes: string;
operation: OperationObject;
paramsInPath: string[];
paramsTypes: string;
}) => string;
componentName: string;
verb: string;
route: string;
description: string;
genericsTypes: string;
operation: OperationObject;
paramsInPath: string[];
paramsTypes: string;
}) => string;
};
}
```
Expand Down Expand Up @@ -691,6 +690,7 @@ module.exports = {
To support even more advanced usecases (like a promise base API, mock generator or anything else that can infer from your specs), you can define your own template in `customGenerator`. This function will be call for each route with some useful computed values (see the types above) and the resulted string will be added to the generated file.
You can see a concrete usage inside the `examples` folder and try yourself in this repository with the following command:
- `yarn build`
- `yarn example:advanced petstore-custom-fetch`
Expand All @@ -715,6 +715,20 @@ If you'd like to actively develop or help maintain this project then there are e
From there, you should be able to start developing without problems.
### How to publish to npm
Just update the `version` in `package.json`!
As soon as your branch will be merged to master, a new npm version will be automatically published for you.
## `@without-cli` npm package
If for any reasons you don't want to use our CLI to generate restful-react components, we provide a `without-cli` version of the package.
Just `npm install restful-react@without-cli` to have this light version.
This version will follow `latest` but without the cli part (more details into `publish-without-cli.js`).
## Next Steps
We're actively developing this at Contiamo to meet our use cases as they arise. If you have a use case that you'd like to implement, do it! Open an issue, submit a Pull Request, have fun! We're friendly.
35 changes: 35 additions & 0 deletions publish-without-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Script to produce a `-without-cli` restful-react version.
*
* This produce a very lightweight build, without the cli script,
* this is for easier security auditing and projects that don't use
* our amazing open-api generator.
*
* This is executed just after `yarn build`, so the `/dist` is present.
*/
const { readFileSync, writeFileSync } = require("fs");
const util = require("util");
const pick = require("lodash/pick");
const omit = require("lodash/omit");
const rimraf = util.promisify(require("rimraf"));

const restfulReactDeps = ["lodash", "lodash-es", "qs", "react-fast-compare", "url"];
const packageJSON = JSON.parse(readFileSync("package.json", "utf-8"));

// Dummy check to be sure we don't forgot a new package in the `-without-cli` version.
if (Object.keys(packageJSON.dependencies).length !== 16) {
throw new Error("The number of dependencies has changed! Please update `publish-without-cli`");
}

// Create a package.json without the cli dependencies
const lightPackageJSON = omit(packageJSON, "bin", "scripts", "husky", "devDependencies");
lightPackageJSON.dependencies = pick(packageJSON.dependencies, ...restfulReactDeps);
lightPackageJSON.version = packageJSON.version + "-without-cli";

// Delete cli folders
Promise.all([rimraf("dist/bin"), rimraf("dist/scripts")]).then(() => {
// Replace the package.json
writeFileSync("package.json", JSON.stringify(lightPackageJSON, null, 2));

// npm publish --tag without-cli
});
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6758,6 +6758,13 @@ rimraf@^3.0.0:
dependencies:
glob "^7.1.3"

rimraf@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a"
integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==
dependencies:
glob "^7.1.3"

rollup-plugin-babel@^4.3.2:
version "4.3.3"
resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-4.3.3.tgz#7eb5ac16d9b5831c3fd5d97e8df77ba25c72a2aa"
Expand Down

0 comments on commit b930d47

Please sign in to comment.