Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor: Move package.json and other front-end collateral into 'site' #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/coder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ jobs:

- name: Install node_modules
run: yarn install
working-directory: site

- name: "yarn lint"
run: yarn lint
working-directory: site

gen:
name: "style/gen"
Expand Down Expand Up @@ -113,6 +115,7 @@ jobs:

- name: Install node_modules
run: yarn install
working-directory: site

- name: "make ${{ matrix.style }}"
run: "make --output-sync -j ${{ matrix.style }}"
Expand Down Expand Up @@ -194,15 +197,18 @@ jobs:
node-version: "14"

- run: yarn install
working-directory: site

- run: yarn build
working-directory: site

- run: yarn test:coverage
working-directory: site

- uses: codecov/codecov-action@v2
if: github.actor != 'dependabot[bot]'
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/lcov.info
files: ./site/coverage/lcov.info
flags: unittest-js
fail_ci_if_error: true
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ yarn-error.log

# Front-end ignore
.next/
site/.eslintcache
site/.next/
site/node_modules/
site/yarn-error.log
coverage/

# Build
bin/
site/out/
site/out/
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ fmt/prettier:
@echo "--- prettier"
# Avoid writing files in CI to reduce file write activity
ifdef CI
yarn run format:check
cd site && yarn run format:check
else
yarn run format:write
cd site && yarn run format:write
endif
.PHONY: fmt/prettier

Expand Down Expand Up @@ -74,6 +74,6 @@ provisionersdk/proto: provisionersdk/proto/provisioner.proto
.PHONY: provisionersdk/proto

site/out:
yarn build
yarn export
cd site && yarn build
cd site && yarn export
.PHONY: site/out
36 changes: 0 additions & 36 deletions jest.config.js

This file was deleted.

5 changes: 4 additions & 1 deletion .eslintignore → site/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
# COPY PASTA OF .gitignore
###############################################################################
node_modules
vendor
vendor
out
coverage
.next
3 changes: 1 addition & 2 deletions .eslintrc.yaml → site/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ parser: "@typescript-eslint/parser"
parserOptions:
ecmaVersion: 2018
project:
- "./tsconfig.json"
- "./site/tsconfig.json"
- "./tsconfig.test.json"
sourceType: module
ecmaFeatures:
jsx: true
Expand Down
5 changes: 2 additions & 3 deletions .prettierignore → site/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ yarn-error.log

# Front-end ignore
.next/
site/.next/
site/out/
coverage/
coverage/
out/
File renamed without changes.
3 changes: 3 additions & 0 deletions _jest/setupTests.ts → site/_jest/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
// Set up 'next-router-mock' to with our front-end tests:
// https://github.com/scottrippey/next-router-mock#quick-start
jest.mock("next/router", () => require("next-router-mock"))

// Suppress isolated modules warning
export {}
7 changes: 6 additions & 1 deletion site/components/ErrorSummary/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import React from "react"

export interface ErrorSummaryProps {
error: Error
error: Error | undefined
}

export const ErrorSummary: React.FC<ErrorSummaryProps> = ({ error }) => {
// TODO: More interesting error page

if (typeof error === "undefined") {
return <div>{"Unknown error"}</div>
}

return <div>{error.toString()}</div>
}
File renamed without changes.
41 changes: 41 additions & 0 deletions site/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = {
projects: [
{
globals: {
"ts-jest": {
tsconfig: "tsconfig.test.json",
},
},
coverageReporters: ["text", "lcov"],
displayName: "test",
preset: "ts-jest",
roots: ["<rootDir>"],
setupFilesAfterEnv: ["<rootDir>/_jest/setupTests.ts"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
testEnvironment: "jsdom",
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
testPathIgnorePatterns: ["/node_modules/", "/__tests__/fakes"],
moduleDirectories: ["node_modules", "<rootDir>"],
},
{
displayName: "lint",
runner: "jest-runner-eslint",
testMatch: ["<rootDir>/**/*.js", "<rootDir>/**/*.ts", "<rootDir>/**/*.tsx"],
testPathIgnorePatterns: ["/.next/", "/out/", "/_jest/", "jest.config.js", "jest-runner.*.js", "next.config.js"],
},
],
collectCoverageFrom: [
"<rootDir>/**/*.js",
"<rootDir>/**/*.ts",
"<rootDir>/**/*.tsx",
"!<rootDir>/**/*.stories.tsx",
"!<rootDir>/.next/**/*.*",
"!<rootDir>/api.ts",
"!<rootDir>/dev.ts",
"!<rootDir>/next-env.d.ts",
"!<rootDir>/next.config.js",
"!<rootDir>/out/**/*.*",
],
}
8 changes: 4 additions & 4 deletions package.json → site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"repository": "https://github.com/coder/coder",
"private": true,
"scripts": {
"build": "NODE_ENV=production next build site",
"build:dev": "next build site",
"dev": "ts-node site/dev.ts",
"export": "next export site",
"build": "NODE_ENV=production next build",
"build:dev": "next build",
"dev": "ts-node dev.ts",
"export": "next export",
"format:check": "prettier --check '**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}'",
"format:write": "prettier --write '**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}' && sql-formatter -l postgresql ./database/query.sql -o ./database/query.sql",
"lint": "jest --selectProjects lint",
Expand Down
4 changes: 2 additions & 2 deletions site/pages/projects/[organization]/[project]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ const ProjectPage: React.FC = () => {
<div className={styles.root}>
<Navbar user={me} onSignOut={signOut} />
<Header
title={firstOrItem(project)}
description={firstOrItem(organization)}
title={firstOrItem(project, "")}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were a couple places where the type-checks became stricter! I figured it was easier to leave them on in the stricter mode, and fix them, then to figure out how to turn them off

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, agreed!

description={firstOrItem(organization, "")}
subTitle={`${workspaces.length} workspaces`}
action={{
text: "Create Workspace",
Expand Down
6 changes: 3 additions & 3 deletions site/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
Expand All @@ -13,12 +12,13 @@
"isolatedModules": true,
"lib": ["dom", "dom.iterable", "esnext"],
"skipLibCheck": true,
"strict": false,
"strict": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"moduleResolution": "node"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
"exclude": ["node_modules", "_jest"]
}
2 changes: 2 additions & 0 deletions tsconfig.json → site/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"jsx": "react",
"downlevelIteration": true,
"strict": true,
"strictNullChecks": true,
"esModuleInterop": true
}
}
6 changes: 3 additions & 3 deletions site/util/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { firstOrItem } from "./array"
describe("array", () => {
describe("firstOrItem", () => {
it("returns null if empty array", () => {
expect(firstOrItem([])).toBeNull()
expect(firstOrItem([], null)).toBeNull()
})

it("returns first item if array with more one item", () => {
expect(firstOrItem(["a", "b"])).toEqual("a")
expect(firstOrItem(["a", "b"], "c")).toEqual("a")
})

it("returns item if single item", () => {
expect(firstOrItem("c")).toEqual("c")
expect(firstOrItem("c", "d")).toEqual("c")
})
})
})
8 changes: 6 additions & 2 deletions site/util/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
* - If an array with 1 or more elements, returns the first element
* - If a single item, returns that item
*/
export const firstOrItem = <T>(itemOrItems: T | T[]): T | null => {
export const firstOrItem = <T>(itemOrItems: undefined | T | T[], defaults: T): T => {
if (Array.isArray(itemOrItems)) {
return itemOrItems.length > 0 ? itemOrItems[0] : null
return itemOrItems.length > 0 ? itemOrItems[0] : defaults
}

if (typeof itemOrItems === "undefined") {
return defaults
}

return itemOrItems
Expand Down
Loading