Skip to content

Commit

Permalink
feat: Initial version (#1)
Browse files Browse the repository at this point in the history
Introduces the following.
* Rollup.js transpiler which outputs a bundled CommonJS module for the renderer to use.
* 3 React components, File, Indent and Text. Where File.
* A component renderer which converts React to purestring.
* A template renderer which can take a filepath and render its content.
* Documentation generation to both HTML and Markdown from JSDoc
* Test and coverage reports


Co-authored-by: Maciej Urbańczyk <urbanczyk.maciej.95@gmail.com>
  • Loading branch information
jonaslagoni and magicmatatjahu committed Dec 11, 2020
1 parent e046c92 commit c884869
Show file tree
Hide file tree
Showing 37 changed files with 17,039 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
docs
lib
src/transpiler/__tests__/__transpiled_testfiles/
118 changes: 118 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
env:
es6: true

plugins:
- sonarjs
- security
- react

extends:
- eslint:recommended
- plugin:sonarjs/recommended
- plugin:react/recommended
- plugin:security/recommended

parserOptions:
ecmaVersion: 2018
sourceType: module
ecmaFeatures:
jsx: true
settings:
react:
version: detect

rules:
# Ignore Rules
strict: 0
no-underscore-dangle: 0
no-mixed-requires: 0
no-process-exit: 0
no-warning-comments: 0
curly: 0
no-multi-spaces: 0
no-alert: 0
consistent-return: 0
consistent-this: [0, self]
func-style: 0
max-nested-callbacks: 0
camelcase: 0

# Warnings
no-debugger: 1
no-empty: 1
no-invalid-regexp: 1
no-unused-expressions: 1
no-native-reassign: 1
no-fallthrough: 1
sonarjs/cognitive-complexity: 1

# Errors
eqeqeq: 2
no-undef: 2
no-dupe-keys: 2
no-empty-character-class: 2
no-self-compare: 2
valid-typeof: 2
no-unused-vars: [2, { "args": "none" }]
handle-callback-err: 2
no-shadow-restricted-names: 2
no-new-require: 2
no-mixed-spaces-and-tabs: 2
block-scoped-var: 2
no-else-return: 2
no-throw-literal: 2
no-void: 2
radix: 2
wrap-iife: [2, outside]
no-shadow: 0
no-use-before-define: [2, nofunc]
no-path-concat: 2
valid-jsdoc: [0, {requireReturn: false, requireParamDescription: false, requireReturnDescription: false}]

# stylistic errors
no-spaced-func: 2
semi-spacing: 2
quotes: [2, 'single']
key-spacing: [2, { beforeColon: false, afterColon: true }]
indent: [2, 2]
no-lonely-if: 2
no-floating-decimal: 2
brace-style: [2, 1tbs, { allowSingleLine: true }]
comma-style: [2, last]
no-multiple-empty-lines: [2, {max: 1}]
no-nested-ternary: 2
operator-assignment: [2, always]
padded-blocks: [2, never]
quote-props: [2, as-needed]
keyword-spacing: [2, {'before': true, 'after': true, 'overrides': {}}]
space-before-blocks: [2, always]
array-bracket-spacing: [2, never]
computed-property-spacing: [2, never]
space-in-parens: [2, never]
space-unary-ops: [2, {words: true, nonwords: false}]
wrap-regex: 2
linebreak-style: [2, unix]
semi: [2, always]
arrow-spacing: [2, {before: true, after: true}]
no-class-assign: 2
no-const-assign: 2
no-dupe-class-members: 2
no-this-before-super: 2
no-var: 2
object-shorthand: [2, always]
prefer-arrow-callback: 2
prefer-const: 2
prefer-spread: 2
prefer-template: 2

# React
react/jsx-uses-react: off
react/react-in-jsx-scope: off

overrides:
- files: "*.spec.js"
rules:
prefer-arrow-callback: 0
sonarjs/no-duplicate-string: 0
security/detect-object-injection: 0
security/detect-non-literal-fs-filename: 0
28 changes: 28 additions & 0 deletions .github/workflows/pull-request-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Pull request testing

on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]

jobs:
test_pr:
if: github.event.pull_request.draft == false
name: 'Testing pull request'
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- name: Install dependencies
run: npm ci
- name: Build project to make sure code is not broken
run: npm run build
- name: Run linter
run: npm run lint
- name: Run tests
run: npm test
- name: Regenerate docs to make sure jsdoc, markdown-toc etc. are not broken
run: npm run docs
59 changes: 59 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release

on:
push:
branches:
- master

jobs:
release:
name: 'Release NPM, GitHub, Docker'
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 14

- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
- name: Run tests
run: npm test
- name: Regenerate docs
run: npm run docs

# NPM
- name: Get version from package.json before release step
id: initversion
run: echo "::set-output name=version::$(npm run get-version --silent)"
- name: Release to NPM and GitHub
id: release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_AUTHOR_NAME: asyncapi-bot
GIT_AUTHOR_EMAIL: info@asyncapi.io
GIT_COMMITTER_NAME: asyncapi-bot
GIT_COMMITTER_EMAIL: info@asyncapi.io
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
run: npm run release
- name: Get version from package.json after release step
id: extractver
run: echo "::set-output name=version::$(npm run get-version --silent)"

# Pull request
- name: Create Pull Request with updated package files
if: steps.initversion.outputs.version != steps.extractver.outputs.version
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GH_TOKEN }}
commit-message: 'chore(release): ${{ steps.extractver.outputs.version }}'
committer: asyncapi-bot <info@asyncapi.io>
author: asyncapi-bot <info@asyncapi.io>
title: 'chore(release): ${{ steps.extractver.outputs.version }}'
body: 'Version bump in package.json and package-lock.json for release [${{ steps.extractver.outputs.version }}](https://github.com/${{github.repository}}/releases/tag/v${{ steps.extractver.outputs.version }})'
branch: version-bump/${{ steps.extractver.outputs.version }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
.vscode
coverage
lib
src/transpiler/__tests__/__transpiled_testfiles
docs
143 changes: 143 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
## Functions

<dl>
<dt><a href="#File">File()</a></dt>
<dd><p>Component is used to describe to the generator that you want a file to be created and rendered based on the defined children.</p>
</dd>
<dt><a href="#Indent">Indent()</a></dt>
<dd><p>Component is for wrapping multiple components and apply an indentation on those.</p>
<p>It supports any form of nested components as well, meaning you can have as many nested <code>Indent</code> components as you would like.</p>
</dd>
<dt><a href="#Text">Text()</a></dt>
<dd><p>Component is for defining a group of text which should be rendered on the same line.</p>
</dd>
<dt><a href="#render">render(component)</a> ⇒ <code>string</code></dt>
<dd><p>Renders given component to string</p>
</dd>
<dt><a href="#renderTemplate">renderTemplate(filepath)</a></dt>
<dd><p>render a file with react. This function automatically transforms jsx to js before importing the component.</p>
</dd>
<dt><a href="#transpileFiles">transpileFiles(directory, outputDir, options)</a></dt>
<dd><p>Transpile files in a given directory (and sub directory if recursive option are passed) and write it to an output directory, if no errors are thrown it completed successfully.</p>
</dd>
<dt><a href="#getFilesInDir">getFilesInDir(dir, includeSubDirs)</a></dt>
<dd><p>Function which finds all the files in directories</p>
</dd>
</dl>

<a name="IndentationTypes"></a>

## IndentationTypes : <code>enum</code>
Type of indentation to use

**Kind**: global enum
**Read only**: true
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| TABS | <code>string</code> | indicate to use tabs as separator |
| SPACES | <code>string</code> | indicate to use spaces as separator |

<a name="File"></a>

## File()
Component is used to describe to the generator that you want a file to be created and rendered based on the defined children.

**Kind**: global function
**Component**:
**Example**
```js
const name = "test.js"
const permissions = 0o777
return (
<File name={name} permissions={permissions}>Test</File>
)
```
<a name="Indent"></a>

## Indent()
Component is for wrapping multiple components and apply an indentation on those.

It supports any form of nested components as well, meaning you can have as many nested `Indent` components as you would like.

**Kind**: global function
**Component**:
**Example**
```js
const size = 4
const type = IndentationTypes.SPACES
return (
<Indent size={size} type={type}>test</Indent>
)
```
<a name="Text"></a>

## Text()
Component is for defining a group of text which should be rendered on the same line.

**Kind**: global function
**Component**:
**Example**
```js
const indent = 4
const type = IndentationTypes.SPACES
const newLines = 2
return (
<Text indent={size} type={type} newLines={newLines}>Test</Text>
)
```
<a name="render"></a>

## render(component) ⇒ <code>string</code>
Renders given component to string

**Kind**: global function

| Param | Type | Description |
| --- | --- | --- |
| component | <code>ReactNode</code> | a given component to rendering |

**Example**
```js
function Component({ textProp }) {
return <>{textProp}</>
}
render(<Component textProp="someText" />)
```
<a name="renderTemplate"></a>

## renderTemplate(filepath)
render a file with react. This function automatically transforms jsx to js before importing the component.

**Kind**: global function

| Param | Description |
| --- | --- |
| filepath | the path to file to render |

<a name="transpileFiles"></a>

## transpileFiles(directory, outputDir, options)
Transpile files in a given directory (and sub directory if recursive option are passed) and write it to an output directory, if no errors are thrown it completed successfully.

**Kind**: global function

| Param | Description |
| --- | --- |
| directory | to transpile. |
| outputDir | to write the transpiled files to. |
| options | any extra options that should be passed. |

<a name="getFilesInDir"></a>

## getFilesInDir(dir, includeSubDirs)
Function which finds all the files in directories

**Kind**: global function

| Param | Description |
| --- | --- |
| dir | directory to find files in. |
| includeSubDirs | should the function iterate through subdirectories to search for files? |

Loading

0 comments on commit c884869

Please sign in to comment.