Skip to content
Closed
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
###############################################################################

node_modules
.eslintcache
.eslintcache
yarn-error.log

site/dist
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "m"]
path = m
url = https://github.com/coder/m
1 change: 1 addition & 0 deletions m
Submodule m added at 5c2a6f
30 changes: 29 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,38 @@
"repository": "https://github.com/coder/coder",
"private": true,
"scripts": {
"build": "webpack build --config site/webpack.config.js",
"format:check": "prettier --check '**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}'",
"format:write": "prettier --write '**/*.{css,htmljs,json,jsx,md,ts,tsx,yaml,yml}'"
},
"dependencies": {
"@sentry/integrations": "6.16.1",
"@sentry/react": "6.16.1",
"@sentry/tracing": "6.16.1",
"@xstate/react": "1.6.3",
"dayjs": "1.10.7",
"formik": "2.2.9",
"match-sorter": "4.2.1",
"superagent": "6.1.0"
},
"devDependencies": {
"prettier": "2.5.1"
"@material-ui/core": "4.9.4",
"@material-ui/icons": "4.5.1",
"@material-ui/lab": "4.0.0-alpha.42",
"@types/node": "14.18.4",
"@types/react": "17.0.38",
"@types/react-dom": "17.0.11",
"@types/react-router-dom": "5.1.8",
"@types/superagent": "4.1.14",
"cli": "^1.0.1",
"next": "11.1.3",
"prettier": "2.5.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-router-dom": "5.1.2",
"ts-loader": "^9.2.6",
"typescript": "4.5.4",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1"
}
}
50 changes: 50 additions & 0 deletions site/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from "react"
import ReactDOM from "react-dom"

// Code imported from 'Coder v1'
// Legacy components that we can re-use
import { CoderThemeProvider } from "@v1/product/coder/site/src/contexts/CoderThemeProvider"
import { UserContext, defaultAppState } from "@v1/product/coder/site/src/contexts/User"
import { SetupModeProvider } from "@v1/product/coder/site/src/contexts/SetupMode"

// A fun component to bring in as an example of re-using UI from 'v1':
import { ConfettiTransition } from "@v1/product/coder/site/src/pages/Onboarding/Activation/ConfettiTransition"

// And some other, simpler, componenents:
import { PrimaryButton } from "@v1/product/coder/site/src/components/Button"

// Helper function to scaffold providers that are needed to host the 'V1' UI
// Ultimately, we'd host the entire app (router and all)
const renderLegacyComponent = (component: JSX.Element) => {
const fetchSetupMode = async () => {
// Return an empty response for 'setup mode'
return {
body: null
} as any;
}

return <UserContext.Provider value={defaultAppState}>
<SetupModeProvider fetchSetupMode={fetchSetupMode}>
<CoderThemeProvider>
{component}
</CoderThemeProvider>
</SetupModeProvider>
</UserContext.Provider>
}

function component() {
const element = document.createElement('div');

// Render the legacy UI
const ui = renderLegacyComponent(<div>
<ConfettiTransition />
<div style={{ position: 'absolute', height: 250, left: 0, right: 0, bottom: 0 }}>
<PrimaryButton>A v1 button hosted in v2 app</PrimaryButton>
</div>
</div >)
ReactDOM.render(ui, element)

return element;
}

document.body.appendChild(component());
33 changes: 33 additions & 0 deletions site/match-sorter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
declare module "match-sorter" {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We have a couple of definition files that needed to be picked up to compile the 'v1' modules... If we go with this approach, I'll look for a nicer way to handle this.

export enum rankings {
CASE_SENSITIVE_EQUAL = 9,
EQUAL = 8,
STARTS_WITH = 7,
WORD_STARTS_WITH = 6,
STRING_CASE = 5,
STRING_CASE_ACRONYM = 4,
CONTAINS = 3,
ACRONYM = 2,
MATCHES = 1,
NO_MATCH = 0,
}

export type KeyOptions<T> = (item: T) => string[] | string

export type ExtendedKeyOptions<T> = { key: KeyOptions<T> } & (
| { maxRanking: number }
| { minRanking: number }
| { threshold: number }
)

export interface Options<T> {
keys?: Array<ExtendedKeyOptions<T> | KeyOptions<T> | keyof T>
threshold?: number
keepDiacritics?: boolean
baseSort?: (a: T, b: T) => number
}

declare function matchSorter<T>(items: ReadonlyArray<T>, value: string, options?: Options<T>): T[]

export default matchSorter
}
6 changes: 6 additions & 0 deletions site/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
37 changes: 37 additions & 0 deletions site/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"allowJs": true,
"downlevelIteration": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"isolatedModules": true,
"paths": {
"@v1/*": [

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These paths are important to be able to resolve dependencies correctly for the typescript compiler...

"./../m/*"
],
"lib/ts/*": [
"./../m/lib/ts/*"
],
"product/*": [
"./../m/product/*"
],
"lib/coderapi/legacy": [
"./../m/lib/ts/coderapi/src/legacy/index.ts"
],
"lib/coderapi/legacy/*": [
"./../m/lib/ts/coderapi/src/legacy/*"
],
"lib/coderapi": [
"./../m/lib/ts/coderapi/src/index.ts"
],
"lib/coderapi/*": [
"./../m/lib/ts/coderapi/src/*"
],
}
}
}
30 changes: 30 additions & 0 deletions site/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const path = require('path');

module.exports = {
entry: './site/index.tsx',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
'@v1': path.resolve(__dirname, '..', 'm'),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And these aliases and modules are necessary for webpack (or next, on top of webpack) to pick up the nested modules

'lib/coderapi': path.resolve(__dirname, '..', 'm', 'lib', 'ts', 'coderapi', 'src')
},
modules: [
'node_modules',
path.resolve(__dirname, '..', 'm'),
path.resolve(__dirname, '..', 'm', 'lib'),
path.resolve(__dirname, '..', 'm', 'product', 'coder', 'site')]
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
};
Loading