Skip to content

Commit

Permalink
Add linting and formatting (onlook-dev#51)
Browse files Browse the repository at this point in the history
* Add eslint, husky, and prettier

* Remove vscode settings
  • Loading branch information
Kitenite authored Jul 12, 2024
1 parent 5b0db46 commit 2c0b32f
Show file tree
Hide file tree
Showing 99 changed files with 21,671 additions and 3,313 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cd app && npm run format
15 changes: 0 additions & 15 deletions .vscode/settings.json

This file was deleted.

4 changes: 4 additions & 0 deletions app/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist-electron
dist
node_modules
release
11 changes: 11 additions & 0 deletions app/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"singleQuote": true,
"printWidth": 100,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"jsxSingleQuote": false,
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf"
}
Binary file modified app/bun.lockb
Binary file not shown.
34 changes: 17 additions & 17 deletions app/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
export enum EditorAttributes {
ONLOOK_TOOLBAR = "onlook-toolbar",
ONLOOK_RECT_ID = "onlook-rect",
ONLOOK_TOOLBAR = 'onlook-toolbar',
ONLOOK_RECT_ID = 'onlook-rect',
ONLOOK_STYLESHEET_ID = 'onlook-stylesheet',

DATA_ONLOOK_ID = "data-onlook-id",
DATA_ONLOOK_IGNORE = "data-onlook-ignore",
DATA_ONLOOK_SAVED = "data-onlook-saved",
DATA_ONLOOK_SNAPSHOT = "data-onlook-snapshot",
DATA_ONLOOK_OLD_VALS = "data-onlook-old-vals",
DATA_ONLOOK_COMPONENT_ID = "data-onlook-component-id",
DATA_ONLOOK_ID = 'data-onlook-id',
DATA_ONLOOK_IGNORE = 'data-onlook-ignore',
DATA_ONLOOK_SAVED = 'data-onlook-saved',
DATA_ONLOOK_SNAPSHOT = 'data-onlook-snapshot',
DATA_ONLOOK_OLD_VALS = 'data-onlook-old-vals',
DATA_ONLOOK_COMPONENT_ID = 'data-onlook-component-id',
}

export enum WebviewChannels {
STYLE_UPDATED = "style-updated",
UPDATE_STYLE = "update-style",
CLEAR_STYLE_SHEET = "clear-style-sheet",
STYLE_UPDATED = 'style-updated',
UPDATE_STYLE = 'update-style',
CLEAR_STYLE_SHEET = 'clear-style-sheet',
}

export enum MainChannels {
WEBVIEW_PRELOAD_PATH = 'webview-preload-path',
OPEN_CODE_BLOCK = "open-code-block",
WRITE_CODE_BLOCK = "write-code-block",
GET_STYLE_CODE = "get-style-code",
OPEN_TUNNEL = "open-tunnel",
CLOSE_TUNNEL = "close-tunnel",
OPEN_CODE_BLOCK = 'open-code-block',
WRITE_CODE_BLOCK = 'write-code-block',
GET_STYLE_CODE = 'get-style-code',
OPEN_TUNNEL = 'open-tunnel',
CLOSE_TUNNEL = 'close-tunnel',
}

export const APP_NAME = 'Onlook';
export const APP_NAME = 'Onlook';
6 changes: 3 additions & 3 deletions app/common/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TemplateNode } from "./models";
import { TemplateNode } from './models';

export function querySelectorCommand(selector: string) {
return `document.querySelector('${CSS.escape(selector)}')`
return `document.querySelector('${CSS.escape(selector)}')`;
}

export function compareTemplateNodes(node1: TemplateNode, node2: TemplateNode): number {
Expand All @@ -18,4 +18,4 @@ export function compareTemplateNodes(node1: TemplateNode, node2: TemplateNode):
return 0;
}
}
}
}
13 changes: 6 additions & 7 deletions app/common/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export interface ElementMetadata {
tagName: string;
selector: string;
Expand All @@ -21,15 +20,15 @@ export interface TemplateTagPosition {
}

export interface TemplateTag {
start: TemplateTagPosition
end: TemplateTagPosition
start: TemplateTagPosition;
end: TemplateTagPosition;
}

export interface TemplateNode {
path: string,
startTag: TemplateTag,
endTag: TemplateTag,
commit: string,
path: string;
startTag: TemplateTag;
endTag: TemplateTag;
commit: string;
}

export interface CodeResult {
Expand Down
32 changes: 16 additions & 16 deletions app/components.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "src/index.css",
"baseColor": "stone",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "src/index.css",
"baseColor": "stone",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
88 changes: 38 additions & 50 deletions app/electron-builder.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,42 @@
* @see https://www.electron.build/configuration/configuration
*/
{
"appId": "dev.onlook.studio",
"asar": true,
"directories": {
"output": "release/${version}"
},
"files": [
"dist-electron",
"dist"
],
"mac": {
"artifactName": "${productName}_${version}.${ext}",
"target": [
"dmg",
"zip"
]
},
"win": {
"target": [
{
"target": "nsis",
"arch": [
"x64"
]
}
],
"artifactName": "${productName}_${version}.${ext}"
},
"linux": {
"target": [
"AppImage",
"deb",
"rpm"
],
"artifactName": "${productName}_${version}.${ext}",
"category": "Utility",
"desktop": {
"Name": "Onlook",
}
},
"nsis": {
"oneClick": false,
"perMachine": false,
"allowToChangeInstallationDirectory": true,
"deleteAppDataOnUninstall": false
},
"publish": {
"provider": "generic",
"channel": "latest",
"url": "https://onlook.dev/"
}
appId: 'dev.onlook.studio',
asar: true,
directories: {
output: 'release/${version}',
},
files: ['dist-electron', 'dist'],
mac: {
artifactName: '${productName}_${version}.${ext}',
target: ['dmg', 'zip'],
},
win: {
target: [
{
target: 'nsis',
arch: ['x64'],
},
],
artifactName: '${productName}_${version}.${ext}',
},
linux: {
target: ['AppImage', 'deb', 'rpm'],
artifactName: '${productName}_${version}.${ext}',
category: 'Utility',
desktop: {
Name: 'Onlook',
},
},
nsis: {
oneClick: false,
perMachine: false,
allowToChangeInstallationDirectory: true,
deleteAppDataOnUninstall: false,
},
publish: {
provider: 'generic',
channel: 'latest',
url: 'https://onlook.dev/',
},
}
38 changes: 19 additions & 19 deletions app/electron/electron-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/// <reference types="vite-electron-plugin/electron-env" />

declare namespace NodeJS {
interface ProcessEnv {
VSCODE_DEBUG?: 'true'
/**
* The built directory structure
*
* ```tree
* ├─┬ dist-electron
* │ ├─┬ main
* │ │ └── index.js > Electron-Main
* │ └─┬ preload
* │ └── index.mjs > Preload-Scripts
* ├─┬ dist
* │ └── index.html > Electron-Renderer
* ```
*/
APP_ROOT: string
/** /dist/ or /public/ */
VITE_PUBLIC: string
}
interface ProcessEnv {
VSCODE_DEBUG?: 'true';
/**
* The built directory structure
*
* ```tree
* ├─┬ dist-electron
* │ ├─┬ main
* │ │ └── index.js > Electron-Main
* │ └─┬ preload
* │ └── index.mjs > Preload-Scripts
* ├─┬ dist
* │ └── index.html > Electron-Renderer
* ```
*/
APP_ROOT: string;
/** /dist/ or /public/ */
VITE_PUBLIC: string;
}
}
30 changes: 20 additions & 10 deletions app/electron/main/code/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export async function readBlock(templateNode: TemplateNode): Promise<string> {
const fileContent = await readFile(filePath);
const lines = fileContent.split('\n');

const selectedText = lines.slice(startRow - 1, endRow)
const selectedText = lines
.slice(startRow - 1, endRow)
.map((line, index, array) => {
if (index === 0 && array.length === 1) {
// Only one line
Expand All @@ -66,25 +67,35 @@ export async function readBlock(templateNode: TemplateNode): Promise<string> {

export async function writeCodeResults(codeResults: CodeResult[]): Promise<void> {
// Write from bottom to prevent line offset
const sortedCodeResults = codeResults.sort((a, b) => compareTemplateNodes(a.param.templateNode, b.param.templateNode)).toReversed()
const files = new Map<string, string>()
const sortedCodeResults = codeResults
.sort((a, b) => compareTemplateNodes(a.param.templateNode, b.param.templateNode))
.toReversed();
const files = new Map<string, string>();

for (const result of sortedCodeResults) {
let fileContent = files.get(result.param.templateNode.path)
let fileContent = files.get(result.param.templateNode.path);
if (!fileContent) {
fileContent = await readFile(result.param.templateNode.path)
fileContent = await readFile(result.param.templateNode.path);
}

const newFileContent = await writeBlock(result.param.templateNode, result.generated, fileContent)
files.set(result.param.templateNode.path, newFileContent)
const newFileContent = await writeBlock(
result.param.templateNode,
result.generated,
fileContent,
);
files.set(result.param.templateNode.path, newFileContent);
}

for (const [filePath, content] of files) {
await writeFile(filePath, content)
await writeFile(filePath, content);
}
}

export async function writeBlock(templateNode: TemplateNode, newBlock: string, fileContent: string): Promise<string> {
export async function writeBlock(
templateNode: TemplateNode,
newBlock: string,
fileContent: string,
): Promise<string> {
try {
const startTag = templateNode.startTag;
const startRow = startTag.start.line;
Expand All @@ -103,7 +114,6 @@ export async function writeBlock(templateNode: TemplateNode, newBlock: string, f

const newFileContent = [before, firstLine + newBlock + lastLine, after].join('\n');
return newFileContent;

} catch (error: any) {
console.error('Error replacing range in file:', error);
throw error;
Expand Down
Loading

0 comments on commit 2c0b32f

Please sign in to comment.