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

Skip to content

Commit 134c283

Browse files
committed
fix: gen vscode code
1 parent 8485dcc commit 134c283

File tree

2 files changed

+7
-56
lines changed

2 files changed

+7
-56
lines changed

packages/vscode-dev/src/gen.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { cwd } from 'node:process';
77
import { readJson, readJsonSync, writeFile, writeJson } from '@tomjs/node';
88
import chalk from 'chalk';
99
import chokidar from 'chokidar';
10-
import { formatCode, getDtsOutputPath, logger } from './utils';
10+
import { getDtsOutputPath, logger } from './utils';
1111

1212
const ROOT = cwd();
1313

@@ -107,8 +107,7 @@ async function genNlsDts(keys: string[], opts: CLIOptions) {
107107
const nslKeys = [...new Set(keys)];
108108
nslKeys.sort();
109109

110-
nlsCode = /* ts */ `
111-
import '@tomjs/vscode';
110+
nlsCode = /* ts */ `import '@tomjs/vscode';
112111
113112
declare module '@tomjs/vscode' {
114113
type I18nMessageType = ${nslKeys.map(key => `'${key}'`).join(' | ') || 'undefined'};
@@ -122,8 +121,7 @@ declare module '@tomjs/vscode' {
122121
| [message: I18nMessageType, args: Record<string, any>]
123122
) => string;
124123
}
125-
}
126-
`;
124+
}`;
127125

128126
await mergeDts(opts);
129127

@@ -147,12 +145,10 @@ function getCommandDts(pkg: IExtensionManifest, opts: CLIOptions) {
147145
return '';
148146
}
149147

150-
return /* ts */ `
151-
export type BuiltinCommand = ${builtinType || 'undefined'};
148+
return /* ts */ ` export type BuiltinCommand = ${builtinType || 'undefined'};
152149
export type UserCommand = ${commandType || 'undefined'};
153150
154151
export namespace commands {
155-
156152
export function registerCommand( command: UserCommand,
157153
callback: (...args: any[]) => any,
158154
thisArg?: any,
@@ -176,8 +172,7 @@ function getCommandDts(pkg: IExtensionManifest, opts: CLIOptions) {
176172
177173
export interface StatusBarItem {
178174
command?: BuiltinCommand | UserCommand;
179-
}
180-
`;
175+
}`;
181176
}
182177

183178
function getViewDts(pkg: IExtensionManifest) {
@@ -223,9 +218,7 @@ async function genPackageDts(opts: CLIOptions) {
223218

224219
pkgCode = /* ts */ `
225220
declare module 'vscode' {
226-
${getCommandDts(pkg, opts)}
227-
228-
${getViewDts(pkg)}
221+
${[getCommandDts(pkg, opts), getViewDts(pkg)].filter(s => s).join('\n')}
229222
}
230223
`;
231224

@@ -236,6 +229,5 @@ declare module 'vscode' {
236229

237230
async function mergeDts(opts: CLIOptions) {
238231
const codes = [nlsCode, pkgCode].filter(s => s);
239-
const code = await formatCode(codes.join('\n\n'), opts.cwd!);
240-
await writeFile(getDtsOutputPath(opts), `// generated by @tomjs/vscode-dev\n${code}`);
232+
await writeFile(getDtsOutputPath(opts), `// generated by @tomjs/vscode-dev\n${codes.join('\n')}`);
241233
}

packages/vscode-dev/src/utils.ts

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,6 @@ import { mkdirpSync } from '@tomjs/node';
66

77
export const logger = new Logger({ directory: 'vscode-dev/logs' });
88

9-
export async function formatCode(code: string, cwd: string) {
10-
try {
11-
const prettier = await import('prettier');
12-
13-
let filepath: string | undefined;
14-
const configFileNames = ['.prettierrc', '.prettier.cjs', '.prettier.mjs', '.prettier.js'];
15-
for (const name of configFileNames) {
16-
const fp = path.join(cwd, name);
17-
if (fs.existsSync(fp)) {
18-
filepath = fp;
19-
break;
20-
}
21-
}
22-
23-
if (prettier) {
24-
return prettier.format(
25-
code,
26-
filepath
27-
? { filepath }
28-
: {
29-
parser: 'babel-ts',
30-
printWidth: 100,
31-
tabWidth: 2,
32-
useTabs: false,
33-
semi: true,
34-
singleQuote: true,
35-
trailingComma: 'all',
36-
arrowParens: 'avoid',
37-
proseWrap: 'never',
38-
endOfLine: 'lf',
39-
},
40-
);
41-
}
42-
}
43-
catch (e: any) {
44-
logger.error(e);
45-
}
46-
47-
return code.replace(/^\s+/gm, '').replace(/\n/g, '');
48-
}
49-
509
function getDtsDir(cwd: string) {
5110
const folders = ['types', 'extension', 'src'];
5211
for (const folder of folders) {

0 commit comments

Comments
 (0)