Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
unsigned6 authored Nov 15, 2022
0 parents commit f4c0a2c
Show file tree
Hide file tree
Showing 13 changed files with 381 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"@babel/preset-react",
],
"plugins": [
"@babel/plugin-proposal-class-properties"
]
}

60 changes: 60 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"extends": ["airbnb", "prettier", "eslint:recommended"],
"settings": {
"import/resolver": {
"node": {
"paths": ["src"]
},
"exports": {}
}
},
"parser": "@babel/eslint-parser",
"env": {
"browser": true,
"node": true,
"mocha": true
},
"plugins": ["prettier", "simple-import-sort", "jsdoc"],
"rules": {
"prettier/prettier": "error",
"comma-dangle": ["error", "always-multiline"],
"array-element-newline": ["error", "consistent"],
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"one-var": ["error", { "uninitialized": "always", "initialized": "never" }],
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"prefer-template": "off",
"camelcase": "off",
"max-len": "off",
"no-console": "off",
"no-unused-expressions": "warn",
"no-confusing-arrow": "off",
"no-underscore-dangle": "off",
"no-return-assign": "off",
"consistent-return": "off",
"arrow-body-style": "off",
"import/prefer-default-export": "off",
"import/no-named-as-default-member": "warn",
"no-param-reassign": ["warn", { "props": false }],
"max-classes-per-file": "warn",
"simple-import-sort/imports": [
"warn",
{
"groups": [
// Side effect imports.
["^\\u0000"],
// Packages.
// Things that start with a letter (or digit or underscore), or `@` followed by a letter.
["^@?\\w"],
// Absolute imports
[
"^(components|configs|constants|containers|domain|enhancers|hocs|libs|pages|reducers|services|store|modules|dictionaries)(/.*|$)"
],
// Relative imports.
// Anything that starts with a dot.
["^\\."]
]
}
]
}
}

59 changes: 59 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Continuous testing and publication to NPM from 'main'

on:
workflow_dispatch:
push:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true


jobs:

run-js-tests:
runs-on: ubuntu-latest
if: github.repository != 'Exabyte-io/template-definitions'
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]

steps:
- name: Checkout this repository
uses: actions/checkout@v2

- name: Checkout actions repository
uses: actions/checkout@v2
with:
repository: Exabyte-io/actions
token: ${{ secrets.BOT_GITHUB_TOKEN }}
path: actions

- name: Run JS tests
uses: ./actions/js/test
with:
node-version: ${{ matrix.node-version }}

publish-js-package:
needs: [run-js-tests]
runs-on: ubuntu-latest
if: (github.repository != 'Exabyte-io/template-definitions') && (github.ref_name == 'main')

steps:
- name: Checkout this repository
uses: actions/checkout@v2

- name: Checkout actions repository
uses: actions/checkout@v2
with:
repository: Exabyte-io/actions
token: ${{ secrets.BOT_GITHUB_TOKEN }}
path: actions

- name: Publish JS release
uses: ./actions/js/publish
with:
node-version: 12.21.x
npm-token: ${{ secrets.NPM_TOKEN }}
github-token: ${{ secrets.BOT_GITHUB_TOKEN }}

7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dist/
build/
node_modules/
.eslintcache
.nyc_output/
.idea/

4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
8 changes: 8 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"all": true,
"include": [
"src/**/*.js",
"src/**/*.jsx"
]
}

7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": false,
"printWidth": 100,
"trailingComma": "all",
"tabWidth": 4
}

15 changes: 15 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# LICENSE

Copyright 2022 Exabyte Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# template-definitions

Template repository for entity definition libraries in Javascript

See [here](https://docs.github.com/en/github-ae@latest/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template)
for details on how to use this repository.

Included is a simple `template.py` analog to `cookiecutter` which will prompt
the user for some information and then write out templated values in select files.
After usage, the `template.py` file can be removed and the `README.md` and associated
`files` can be committed.

66 changes: 66 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"name": "@exabyte-io/PROJECT_NAME",
"version": "0.0.0",
"description": "PROJECT_DESCRIPTION",
"scripts": {
"test": "nyc --reporter=text mocha --recursive --bail --require @babel/register/lib --require tests/setup.js tests",
"lint": "eslint src tests && prettier --write src tests",
"lint:fix": "eslint --fix --cache src tests && prettier --write src tests",
"transpile": "babel --out-dir dist src",
"postinstall": "npm run transpile",
"prettier": "prettier --check src tests",
"prepare": "husky install"
},
"repository": {
"type": "git",
"url": "https://github.com/Exabyte-io/PROJECT_NAME.git"
},
"main": "dist/index.js",
"files": [
"/dist",
"/src",
".babelrc"
],
"author": "Exabyte Inc.",
"bugs": {
"url": "https://github.com/Exabyte-io/PROJECT_NAME/issues"
},
"license": "Apache-2.0",
"homepage": "https://github.com/Exabyte-io/PROJECT_NAME",
"dependencies": {
"@babel/cli": "7.16.0",
"@babel/core": "7.16.0",
"@babel/eslint-parser": "7.16.3",
"@babel/plugin-proposal-class-properties": "7.16.0",
"@babel/preset-env": "7.16.4",
"@babel/preset-react": "7.16.7",
"@babel/register": "^7.16.0",
"@babel/runtime-corejs3": "7.16.8"
},
"devDependencies": {
"chai": "^4.3.4",
"eslint": "7.32.0",
"eslint-config-airbnb": "19.0.2",
"eslint-config-prettier": "8.3.0",
"eslint-import-resolver-exports": "^1.0.0-beta.2",
"eslint-plugin-import": "2.25.3",
"eslint-plugin-jsdoc": "37.1.0",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-react": "7.30.0",
"eslint-plugin-simple-import-sort": "7.0.0",
"husky": "^7.0.4",
"lint-staged": "^12.1.2",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"prettier": "^2.7.1"
},
"engines": {
"node": ">=12.0.0"
},
"lint-staged": {
"*.js": "eslint --cache --fix",
"*.{js,css}": "prettier --write"
}
}

1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Add exports here
123 changes: 123 additions & 0 deletions template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env python
"""
Safely delete this script and commit edited files after use
"""

files = [
"package.json",
]

params = [
"PROJECT_NAME",
"PROJECT_DESCRIPTION",
]

descriptions = [
"(Ex. made.js, code.js, ...)",
"(Ex. 'COre DEfinitions')",
]

readme = """\
[![npm version](https://badge.fury.io/js/%40exabyte-io%2FPROJECT_NAME.svg)](https://badge.fury.io/js/%40exabyte-io%2FPROJECT_NAME)
[![License: Apache](https://img.shields.io/badge/License-Apache-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
# PROJECT_NAME
PROJECT_NAME houses entity definitions for use in the Mat3ra platform.
### Installation
For usage within a javascript project:
```bash
npm install @exabyte-io/PROJECT_NAME
```
For development:
```bash
git clone https://github.com/Exabyte-io/PROJECT_NAME.git
```
### Contribution
This repository is an [open-source](LICENSE.md) work-in-progress and we welcome contributions.
We regularly deploy the latest code containing all accepted contributions online as part of the
[Mat3ra.com](https://mat3ra.com) platform, so contributors will see their code in action there.
See [ESSE](https://github.com/Exabyte-io/esse) for additional context regarding the data schemas used here.
Useful commands for development:
```bash
# run linter without persistence
npm run lint
# run linter and save edits
npm run lint:fix
# compile the library
npm run transpile
# run tests
npm run test
```
## Using Linter
Linter setup will prevent committing files that don't adhere to the code standard. It will
attempt to fix what it can automatically prior to the commit in order to reduce diff noise. This can lead to "unexpected" behavior where a
file that is staged for commit is not identical to the file that actually gets committed. This happens
in the `lint-staged` directive of the `package.json` file (by using a `husky` pre-commit hook). For example,
if you add extra whitespace to a file, stage it, and try to commit it, you will see the following:
```bash
➜ repo-js git:(feature/cool-feature) ✗ git commit -m "Awesome feature works great"
✔ Preparing...
✔ Running tasks...
✖ Prevented an empty git commit!
✔ Reverting to original state because of errors...
✔ Cleaning up...
⚠ lint-staged prevented an empty git commit.
Use the --allow-empty option to continue, or check your task configuration
husky - pre-commit hook exited with code 1 (error)
```
The staged change may remain but will not have been committed. Then it will look like you still have a staged
change to commit, but the pre-commit hook will not actually commit it for you, quite frustrating! Styling can
be applied manually and fixed by running:
```bash
npm run lint:fix
```
In which case, you may need to then add the linter edits to your staging, which in the example above, puts the
file back to identical with the base branch, resulting in no staged changes whatsoever.
"""

values = {}
for param, desc in zip(params, descriptions):
values[param] = input(f"Please provide a value for {param} {desc}: ")


def replace(content, values):
for key, val in values.items():
content = content.replace(key, val)
return content


for fl in files:
with open(fl, "r") as f:
content = f.read()
with open(fl, "w") as f:
f.write(replace(content, values))


with open("README.md", "w") as f:
f.write(replace(readme, values))
2 changes: 2 additions & 0 deletions tests/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import chai from "chai";

0 comments on commit f4c0a2c

Please sign in to comment.