8000 feat: deploy scripts (#3) · githubocto/flat-vscode@8e577e5 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

Commit 8e577e5

Browse files
feat: deploy scripts (#3)
2 parents 76e8531 + 175209b commit 8e577e5

File tree

9 files changed

+821
-65
lines changed

9 files changed

+821
-65
lines changed

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ node_modules
55
.vscode-test/
66
*.vsix
77
yarn-error.log
8-
media/index.css
9-
media/index.css.map
10-
media/index.js
11-
media/index.js.map
8+
media/*.css
9+
media/*.css.map
10+
media/*.js
11+
media/*.js.map

.vscodeignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.vscode/**
22
.vscode-test/**
3-
out/test/**
43
src/**
54
.gitignore
65
.yarnrc
@@ -10,4 +9,6 @@ vsc-extension-quickstart.md
109
**/*.map
1110
**/*.ts
1211
node_modules
13-
.parcel-cache
12+
.parcel-cache
13+
tailwind.config.json
14+
webpack.config.js

package.json

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"name": "flat",
33
"displayName": "flat",
44
"publisher": "GitHubOCTO",
5+
"repository": {
6+
"url": "https://github.com/githubocto/flat-vscode"
7+
},
58
"description": "",
69
"version": "0.0.1",
710
"engines": {
@@ -14,6 +17,14 @@
1417
"*"
1518
],
1619
"main": "./out/extension.js",
20+
"webview": "webview.js",
21+
"targets": {
22+
"main": false,
23+
"webview": {
24+
"distDir": "./media",
25+
"sourceMap": false
26+
}
27+
},
1728
"contributes": {
1829
"viewsContainers": {
1930
"activitybar": [
@@ -51,13 +62,18 @@
5162
]
5263
},
5364
"scripts": {
54-
"vscode:prepublish": "yarn run compile",
55-
"compile": "tsc -p ./",
56-
"watch": "tsc -watch -p ./",
65+
"vscode:prepublish": "run-s clean compile",
66+
"webpack:build": "webpack",
67+
"clean": "rm -rf out dist",
68+
"ts:watch": "tsc -watch -p ./",
69+
"ts:compile": "tsc -p ./",
70+
"compile": "run-s webpack:build webview:build",
71+
"watch": "run-p ts:watch webview:dev",
5772
"pretest": "yarn run compile && yarn run lint",
5873
"lint": "eslint src --ext ts",
5974
"test": "node ./out/test/runTest.js",
60-
"dev": "parcel src/webview/index.js --dist-dir ./media"
75+
"webview:build": "parcel build src/webview/index.js",
76+
"webview:dev": "parcel watch src/webview/index.js"
6177
},
6278
"devDependencies": {
6379
"@parcel/optimizer-cssnano": "2.0.0-nightly.610",
@@ -76,11 +92,16 @@
7692
"eslint": "^7.19.0",
7793
"glob": "^7.1.6",
7894
"mocha": "^8.2.1",
95+
"npm-run-all": "^4.1.5",
7996
"parcel": "^2.0.0-nightly.608",
8097
"postcss-nested": "^5.0.3",
8198
"tailwindcss": "^2.0.3",
99+
"ts-loader": "^8.0.17",
82100
"typescript": "^4.1.3",
83101
"vscode-test": "^1.5.0",
102+
"webpack": "^5.24.2",
103+
"webpack-cli": "^4.5.0",
104+
"webpack-filter-warnings-plugin": "^1.2.1",
84105
"yarn": "^1.22.10"
85106
},
86107
"dependencies": {
@@ -100,7 +121,7 @@
100121
"react-query": "^3.12.0",
101122
"react-router-dom": "^5.2.0",
102123
"react-use": "^17.1.1",
103-
"tweetsodium": "^0.0.5",
124+
"tweetsodium": "0.0.4",
104125
"typeorm": "^0.2.31",
105126
"yup": "^0.32.9",
106127
"zustand": "^3.3.2"

src/git.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,26 @@ export class VSCodeGit {
3131

3232
waitForRepo(times: number): Promise<{ name: string; owner: string }> {
3333
let count = 0;
34+
const timeToStop = count === times;
3435

3536
return new Promise((resolve, reject) => {
3637
const checkRepoExists = setInterval(() => {
37-
const remotes = this.repository._repository.remotes;
38-
if (remotes.length > 0) {
39-
const remote = remotes[0];
40-
const parsed = GitUrlParse(remote.pushUrl);
41-
clearInterval(checkRepoExists);
42-
resolve({
43-
name: parsed.name,
44-
owner: parsed.owner,
45-
});
46-
} else {
47-
if (count === times) {
48-
clearInterval(checkRepoExists);
49-
reject(new Error("Couldnt get repo details"));
38+
try {
39+
const remotes = this.repository._repository.remotes;
40+
if (remotes.length > 0) {
41+
const remote = remotes[0];
42+
const parsed = GitUrlParse(remote.pushUrl);
43+
resolve({ name: parsed.name, owner: parsed.owner });
44+
} else {
45+
if (timeToStop) {
46+
reject(new Error("Couldn't get repo details"));
47+
}
48+
count++;
5049
}
51-
count++;
50+
} catch (e) {
51+
reject(new Error("Couldn't get repo details"));
52+
} finally {
53+
clearInterval(checkRepoExists);
5254
}
5355
}, 1000);
5456
});

src/providers/sidebar.ts

Lines changed: 12 additions & 11 deletions
< F987 /tr>
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
102102
const stylesPath = vscode.Uri.joinPath(
103103
this._extensionUri,
104104
"media",
105-
"index.css"
105+
"webview.css"
106106
);
107107

108108
const stylesUri = webview.asWebviewUri(stylesPath);
109109

110110
const scriptPathOnDisk = vscode.Uri.joinPath(
111111
this._extensionUri,
112112
"media",
113-
"index.js"
113+
"webview.js"
114114
);
115115

116116
const scriptUri = webview.asWebviewUri(scriptPathOnDisk);
@@ -125,7 +125,8 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
125125
name = details.name;
126126
owner = details.owner;
127127
} catch (e) {
128-
console.error("no upstream, wtf?", e);
128+
name = "";
129+
owner = "";
129130
}
130131

131132
const initialAppState = {
@@ -137,21 +138,21 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
137138
};
138139

139140
return `<!DOCTYPE html>
140-
<html lang="en">
141-
<head>
142-
<meta charset="UTF-8">
143-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
141+
<html lang="en">
142+
<head>
143+
<meta charset="UTF-8">
144+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
144145
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src ${
145146
webview.cspSource
146147
}; img-src ${
147148
webview.cspSource
148149
} 'self' data: https:; script-src 'nonce-${nonce}'; connect-src https://api.github.com;">
149150
<link href="${stylesUri}" rel="stylesheet">
150-
</head>
151+
</head>
151152
<body>
152-
<div data-state=${JSON.stringify(initialAppState)} id="app"></div>
153+
<div data-state=${JSON.stringify(initialAppState)} id="app"></div>
153154
<script nonce="${nonce}" src="${scriptUri}"></script>
154-
</body>
155-
</html>`;
155+
</body>
156+
</html>`;
156157
}
157158
}

src/webview/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "regenerator-runtime/runtime";
12
import React from "react";
23
import ReactDOM from "react-dom";
34
import { QueryClient, QueryClientProvider } from "react-query";

tailwind.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
2-
purge: [],
2+
purge: ["./src/webview/**/*.{js,jsx,ts,tsx}"],
3+
34
darkMode: false, // or 'media' or 'class'
45
theme: {
56
extend: {},

webpack.config.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const path = require("path");
2+
const { IgnorePlugin } = require("webpack");
3+
const FilterWarningsPlugin = require("webpack-filter-warnings-plugin");
4+
5+
module.exports = {
6+
target: "node",
7+
mode: "production",
8+
entry: "./src/extension.ts",
9+
output: {
10+
filename: "extension.js",
11+
path: path.resolve(__dirname, "out"),
12+
libraryTarget: "commonjs2",
13+
devtoolModuleFilenameTemplate: "../[resource-path]",
14+
},
15+
devtool: "source-map",
16+
externals: {
17+
vscode: "commonjs vscode",
18+
},
19+
resolve: {
20+
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
21+
extensions: [".ts", ".js"],
22+
},
23+
module: {
24+
rules: [
25+
{
26+
test: /\.ts$/,
27+
exclude: /node_modules/,
28+
use: [
29+
{
30+
loader: "ts-loader",
31+
},
32+
],
33+
},
34+
],
35+
},
36+
plugins: [
37+
new IgnorePlugin({
38+
resourceRegExp: /^pg-native$/,
39+
}),
40+
new FilterWarningsPlugin({
41+
exclude: [
42+
/mongodb/,
43+
/mssql/,
44+
/mysql/,
45+
/mysql2/,
46+
/oracledb/,
47+
/pg/,
48+
/pg-native/,
49+
/pg-query-stream/,
50+
/react-native-sqlite-storage/,
51+
/redis/,
52+
/sqlite3/,
53+
/sql.js/,
54+
/typeorm-aurora-data-api-driver/,
55+
],
56+
}),
57+
],
58+
};

0 commit comments

Comments
 (0)
0