Skip to content

Commit

Permalink
feat(project): initialized project
Browse files Browse the repository at this point in the history
  • Loading branch information
RCVZ committed Apr 21, 2021
1 parent 73c6598 commit f2ee34c
Show file tree
Hide file tree
Showing 30 changed files with 9,242 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules : {
'scope-enum': [
2, 'always', [
'project',
],
],
},
};

131 changes: 131 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
const restrictedGlobals = require('confusing-browser-globals');

module.exports = {
parser: '@typescript-eslint/parser',

plugins: [
// Enable Typescript linting
'@typescript-eslint',

// Enable linting imports
'import',
],

extends: [
// Use default ESLint rules
'eslint:recommended',

// Use recommended TS rules
'plugin:@typescript-eslint/recommended',

// Use recommended React rules
'plugin:react/recommended',

'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
],

env: {
// Browser conf
browser: true,
es6: true,

// Jest conf
jest: true,
node: true,
},

rules: {
// Prevent development/debugging statements
'no-console': ['error', { allow: ['warn', 'error', 'info', 'debug'] }],
'no-alert': 'error',
'no-debugger': 'error',

// Prevent usage of confusing globals
'no-restricted-globals': ['error'].concat(restrictedGlobals),

// Assignments in function returns is confusing and could lead to unwanted side-effects
'no-return-assign': ['error', 'always'],

// Strict import ordering
'import/order': [
'warn',
{
groups: ['builtin', 'external', 'parent', 'sibling', 'index'],
pathGroups: [
// Sort absolute root imports before parent imports
{
pattern: '/**',
group: 'parent',
position: 'before',
},
],
'newlines-between': 'always',
},
],
},
overrides: [
{
files: ['*.js'],
env: {
// We may still use CJS in .js files (eg. local scripts)
commonjs: true,
},
rules: {
// `require` is still allowed/recommended in JS
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: ['*.ts', '*.tsx'],
rules: {
// TypeScript 4.0 adds 'any' or 'unknown' type annotation on catch clause variables.
// We need to make sure error is of the type we are expecting
'@typescript-eslint/no-implicit-any-catch': 'error',

// These are handled by TS
'@typescript-eslint/no-explicit-any': [
'warn',
{ ignoreRestArgs: true },
],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'import/no-unresolved': 'off',
},
},
{
files: ['*.jsx', '*.tsx'],
plugins: [
// Enable linting React code
'react',
'react-hooks',
],
rules: {
// Help with Hooks syntax
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'error',

// Handled by Typescript
'react/prop-types': 'off',

// This rule causes too many false positives, eg. with default exports or child render function
'react/display-name': 'off',
},
},
],

settings: {
react: {
pragma: 'React',
version: '17',
},
},
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
};
23 changes: 23 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Description

<!-- Describe the proposed solution/fix/feature in this pull request here. -->

This PR solves # .

### Steps completed:

<!-- Check all completed steps so we know -->

According to our definition of done, I have completed the following steps:

- [ ] User stories met
- [ ] Storybook stories
- [ ] Unit tests added
- [ ] Linting passing
- [ ] Unit tests passing
- [ ] Docs updated (including config and env variables)
- [ ] Translations added
- [ ] UX tested
- [ ] Browsers / platforms tested
- [ ] Rebased & ready to merge without conflicts
- [ ] Reviewed own code
22 changes: 22 additions & 0 deletions .github/workflows/lhci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: lhci
on: [push]
jobs:
lhci:
name: Lighthouse
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: yarn install, build
run: |
yarn install
yarn run build
- name: install Lighthouse CI
run: |
sudo yarn global add @lhci/cli@0.7.x http-server
- name: run Lighthouse CI
run: |
lhci autorun
26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Jest

on: [push]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: yarn install, build, and test
run: |
yarn
yarn test
env:
CI: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.snowpack
build
node_modules
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
7 changes: 7 additions & 0 deletions blueprint/base/Base.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// remove these, if you don't need them
@import './path/styles/base/colors';
@import './path/styles/base/breakpoints';
@import './path/styles/base/mixins';

.basis {
}
10 changes: 10 additions & 0 deletions blueprint/base/Base.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { render, screen } from '@testing-library/react';

import Base from './Base';

describe('Base Component tests', () => {
test('dummy test', () => {
render(<Base></Base>);
expect(screen.getByText('hello world')).toBeInTheDocument();
});
});
18 changes: 18 additions & 0 deletions blueprint/base/Base.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';

import styles from './Base.module.scss';

type BaseProps = {
dummy?: string;
};

const Base: React.FC<BaseProps> = ({ dummy = 'defaultValue' }: BaseProps) => {
return (
<div className={styles['base']}>
<p>hello world</p>
<p>{dummy}</p>
</div>
);
};

export default Base;
67 changes: 67 additions & 0 deletions blueprint/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use-strict';

const { writeFileSync, readFileSync, mkdirSync } = require('fs');

if (process.argv.length < 3) {
console.error(`
Please pass new component name including path in kebab case!
Example:
components/basic/form-example-divider
Result:
components/basic/FormExampleDivider.tsx
components/basic/FormExampleDivider.test.tsx
components/basic/FormExampleDivider.module.scss
`);
return;
}

const path = process.argv[2];
const splitPath = path.split('/');

const componentName = {
kebabCase: splitPath[splitPath.length - 1],
pascalCase: toPascalCase(splitPath[splitPath.length - 1]),
};

const baseTsx = readFileSync('./scripts/blueprint/base/Base.tsx');
const baseTestTsx = readFileSync('./scripts/blueprint/base/Base.test.tsx');
const baseScss = readFileSync('./scripts/blueprint/base/Base.module.scss');

// creates target directory
const dir = `./src/${path}`;
mkdirSync(dir, { recursive: true });

// TSX
const componentTsx = baseTsx
.toString()
.replace(/Base/g, componentName.pascalCase)
.replace(/base/g, componentName.kebabCase);
writeFileSync(`${dir}/${componentName.pascalCase}.tsx`, componentTsx);

// TEST.TSX
const componentTestTsx = baseTestTsx
.toString()
.replace(/Base/g, componentName.pascalCase)
.replace(/base/g, componentName.kebabCase);
writeFileSync(`${dir}/${componentName.pascalCase}.test.tsx`, componentTestTsx);

// SCSS
const componentScss = baseScss
.toString()
.replace(/basis/g, componentName.kebabCase)
.replace(
/.\/path\//g,
`./${new Array(splitPath.length).fill('../').join('')}`
);
writeFileSync(`${dir}/${componentName.pascalCase}.module.scss`, componentScss);

// Helpers
function toPascalCase(input) {
const split = input.split('-');
return split.map((i) => capitalize(i)).join('');
}

function capitalize(s) {
if (typeof s !== 'string') return '';
return s.charAt(0).toUpperCase() + s.slice(1);
}
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('@snowpack/app-scripts-react/jest.config.js')(),
};
Empty file added jest.setup.js
Empty file.
18 changes: 18 additions & 0 deletions lighthouserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
ci: {
collect: {
url: [
"http://127.0.0.1:4000"
],
startServerCommand: "http-server ./build -p 4000 -g",
startServerReadyPattern: "Available on",
numberOfRuns: 1
},
upload: {
"target": "temporary-public-storage"
},
assert: {
"preset": "lighthouse:recommended",
}
}
};
Loading

0 comments on commit f2ee34c

Please sign in to comment.