Skip to content

Commit

Permalink
initial import (#1)
Browse files Browse the repository at this point in the history
* initial cli tool

* adds git initialization

* adds gitignore, fixes issues with commit creation, adds missing dependency and includes template in build

* support downloading swagger spec

* add build setup for client library
  • Loading branch information
abillingsley authored Apr 6, 2020
1 parent a312021 commit 4cea7e2
Show file tree
Hide file tree
Showing 37 changed files with 3,242 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/lib
11 changes: 11 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": ["plugin:@typescript-eslint/recommended", "plugin:prettier/recommended", "prettier/@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-unused-vars": "warn"
}
}
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*-debug.log
*-error.log
/.nyc_output
/dist
/lib
/package-lock.json
/tmp
node_modules
/example

.DS_Store
Empty file added .prettierignore
Empty file.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 120,
"trailingComma": "all",
"arrowParens": "always"
}
76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at admin@developertown.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 DeveloperTown

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.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
create-openapi-client
# create-openapi-client

[![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
[![Version](https://img.shields.io/npm/v/create-openapi-client.svg)](https://npmjs.org/package/create-openapi-client)
[![Downloads/week](https://img.shields.io/npm/dw/create-openapi-client.svg)](https://npmjs.org/package/create-openapi-client)
[![License](https://img.shields.io/npm/l/create-openapi-client.svg)](https://github.com/developertown/create-openapi-client/blob/master/package.json)

<!-- toc -->
* [create-openapi-client](#create-openapi-client)
* [Usage](#usage)
* [Commands](#commands)
<!-- tocstop -->

# Usage

<!-- usage -->
```sh-session
$ npm install -g @developertown/create-openapi-client
$ create-openapi-client COMMAND
running command...
$ create-openapi-client (-v|--version|version)
@developertown/create-openapi-client/0.0.1 darwin-x64 node-v10.14.0
$ create-openapi-client --help [COMMAND]
USAGE
$ create-openapi-client COMMAND
...
```
<!-- usagestop -->

# Commands

<!-- commands -->

<!-- commandsstop -->
14 changes: 14 additions & 0 deletions bin/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node

const fs = require("fs");
const path = require("path");
const project = path.join(__dirname, "../tsconfig.json");
const dev = fs.existsSync(project);

if (dev) {
require("ts-node").register({ project });
}

require(`../${dev ? "src" : "lib"}`)
.run()
.catch(require("@oclif/errors/handle"));
3 changes: 3 additions & 0 deletions bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
65 changes: 65 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "@developertown/create-openapi-client",
"version": "0.0.1",
"bin": {
"create-openapi-client": "./bin/run"
},
"bugs": "https://github.com/developertown/create-openapi-client/issues",
"dependencies": {
"@oclif/command": "^1",
"@oclif/config": "^1",
"@oclif/plugin-help": "^2",
"globby": "^11.0.0",
"handlebars": "^4.7.6",
"inquirer": "^7.1.0",
"listr": "^0.14.3",
"shelljs": "^0.8.3",
"tslib": "^1"
},
"devDependencies": {
"@oclif/dev-cli": "^1",
"@types/handlebars": "^4.1.0",
"@types/inquirer": "^6.5.0",
"@types/listr": "^0.14.2",
"@types/node": "^10",
"@types/shelljs": "^0.8.7",
"@typescript-eslint/eslint-plugin": "^2.26.0",
"@typescript-eslint/parser": "^2.26.0",
"eslint": "^5.13",
"eslint-config-oclif": "^3.1",
"eslint-config-oclif-typescript": "^0.1",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.2",
"prettier": "^2.0.2",
"ts-node": "^8",
"typescript": "^3.3"
},
"engines": {
"node": ">=8.0.0"
},
"files": [
"/bin",
"/lib",
"/template"
],
"homepage": "https://github.com/developertown/create-openapi-client",
"keywords": [
"oclif",
"openapi",
"template",
"typescript"
],
"license": "MIT",
"main": "lib/index.js",
"oclif": {
"bin": "create-openapi-client"
},
"repository": "https://github.com/developertown/create-openapi-client",
"scripts": {
"posttest": "eslint . --ext .ts --config .eslintrc",
"prepack": "rm -rf lib && tsc -b && oclif-dev readme",
"test": "echo NO TESTS",
"version": "oclif-dev readme && git add README.md"
},
"types": "lib/index.d.ts"
}
92 changes: 92 additions & 0 deletions src/createOpenApiClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import * as handlebars from "handlebars";
import * as fs from "fs";
import * as path from "path";
import * as globby from "globby";
import * as Listr from "listr";
import * as git from "./git";
import { exec, performInDirectory } from "./shell";
import { PackageInfo } from "./getPackageInfo";

type OpenApiClientOptions = PackageInfo & {
packageDirectory: string;
openapiUrl: string;
};

const createOpenApiClient = async ({ packageDirectory, ...options }: OpenApiClientOptions) => {
const tasks = new Listr([
{
title: "Creating openapi client package",
task: async () => {
const templateDirectory = path.join(__dirname, "..", "template");
const templateFiles = await globby(templateDirectory.replace(/\\/g, "/"), {
dot: true,
});

templateFiles.forEach((templateFile) => {
const template = handlebars.compile(fs.readFileSync(templateFile, "utf8"));
const content = template(options);
const fileRelativePath = path.relative(templateDirectory, templateFile).replace(/\\/g, "/");
const destinationFile = path.join(packageDirectory, fileRelativePath);
const destinationDirectory = path.parse(destinationFile).dir;
if (!fs.existsSync(destinationDirectory)) {
fs.mkdirSync(destinationDirectory);
}
fs.writeFileSync(destinationFile, content, "utf8");
});
},
},
{
title: "Initializing npm dependencies. This will take a minute.",
task: () => {
return performInDirectory(packageDirectory, () => exec("yarn install"));
},
},
{
title: "Generate openapi client",
task: () => {
return performInDirectory(packageDirectory, () => exec("yarn generate"));
},
},
{
title: "Initialized a git repository.",
task: (ctx, task) => {
const gitIgnorePath = path.join(packageDirectory, ".gitignore");
performInDirectory(packageDirectory, async () => {
const hasGit = await git.isInstalled();
if (hasGit) {
const alreadyInitialized = await git.isInitialized();
if (!alreadyInitialized) {
await git.init();
fs.writeFileSync(
gitIgnorePath,
`
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
/dist
npm-debug.log*
yarn-debug.log*
yarn-error.log*
`,
`utf8`,
);
await git.commit("Initialize project using create openapi client");
} else {
task.skip("git repository is already initialized");
}
} else {
task.skip("git is not available");
}
});
},
},
]);
await tasks.run();
};

export default createOpenApiClient;
Loading

0 comments on commit 4cea7e2

Please sign in to comment.