From f4c0a2c9f438363bd5b4e178089ef29ab34b2ce8 Mon Sep 17 00:00:00 2001 From: Yurii Vlasiuk Date: Tue, 15 Nov 2022 14:32:28 +0200 Subject: [PATCH] Initial commit --- .babelrc | 17 +++++ .eslintrc.json | 60 ++++++++++++++++++ .github/workflows/cicd.yml | 59 ++++++++++++++++++ .gitignore | 7 +++ .husky/pre-commit | 4 ++ .nycrc | 8 +++ .prettierrc | 7 +++ LICENSE.md | 15 +++++ README.md | 12 ++++ package.json | 66 ++++++++++++++++++++ src/index.js | 1 + template.py | 123 +++++++++++++++++++++++++++++++++++++ tests/setup.js | 2 + 13 files changed, 381 insertions(+) create mode 100644 .babelrc create mode 100644 .eslintrc.json create mode 100644 .github/workflows/cicd.yml create mode 100644 .gitignore create mode 100755 .husky/pre-commit create mode 100644 .nycrc create mode 100644 .prettierrc create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 package.json create mode 100644 src/index.js create mode 100644 template.py create mode 100644 tests/setup.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..4fce77d --- /dev/null +++ b/.babelrc @@ -0,0 +1,17 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "node": "current" + } + } + ], + "@babel/preset-react", + ], + "plugins": [ + "@babel/plugin-proposal-class-properties" + ] +} + diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..35ab6dd --- /dev/null +++ b/.eslintrc.json @@ -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. + ["^\\."] + ] + } + ] + } +} + diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..3c24d38 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -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 }} + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1cdadc5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +dist/ +build/ +node_modules/ +.eslintcache +.nyc_output/ +.idea/ + diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..36af219 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npx lint-staged diff --git a/.nycrc b/.nycrc new file mode 100644 index 0000000..6d6542d --- /dev/null +++ b/.nycrc @@ -0,0 +1,8 @@ +{ + "all": true, + "include": [ + "src/**/*.js", + "src/**/*.jsx" + ] +} + diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..a15f7f0 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "singleQuote": false, + "printWidth": 100, + "trailingComma": "all", + "tabWidth": 4 +} + diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..a21c7c6 --- /dev/null +++ b/LICENSE.md @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..54d6f62 --- /dev/null +++ b/README.md @@ -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. + diff --git a/package.json b/package.json new file mode 100644 index 0000000..478515e --- /dev/null +++ b/package.json @@ -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" + } +} + diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..80c88d8 --- /dev/null +++ b/src/index.js @@ -0,0 +1 @@ +// Add exports here diff --git a/template.py b/template.py new file mode 100644 index 0000000..b886f24 --- /dev/null +++ b/template.py @@ -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)) diff --git a/tests/setup.js b/tests/setup.js new file mode 100644 index 0000000..d2aa584 --- /dev/null +++ b/tests/setup.js @@ -0,0 +1,2 @@ +import chai from "chai"; +