File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { promises as fs } from 'node:fs';
22import { basename , resolve } from 'node:path' ;
33import { window , workspace } from 'vscode' ;
44import { getConfig } from 'vscode-get-config' ;
5- import { getOutName } from './util.ts' ;
5+ import { fileExists , getOutName } from './util.ts' ;
66
77async function createBuildTask ( isJXA = false ) : Promise < void > {
88 if ( typeof workspace . workspaceFolders === 'undefined' || workspace . workspaceFolders . length < 1 ) {
@@ -88,7 +88,18 @@ async function createBuildTask(isJXA = false): Promise<void> {
8888 const dotFolder = resolve ( workspace . workspaceFolders [ 0 ] . uri . fsPath , '.vscode' ) ;
8989 const buildFile = resolve ( dotFolder , 'tasks.json' ) ;
9090
91- await fs . mkdir ( dotFolder ) ;
91+ try {
92+ await fs . mkdir ( dotFolder ) ;
93+ } catch {
94+ console . warn ( '[idleberg.applescript] This workspace already contains a .vscode folder.' ) ;
95+ }
96+
97+ if ( await fileExists ( buildFile ) ) {
98+ window . showErrorMessage (
99+ 'This workspace already has a task file. If you want to override it, delete it manually and try again.' ,
100+ ) ;
101+ return ;
102+ }
92103
93104 try {
94105 await fs . writeFile ( buildFile , jsonString ) ;
Original file line number Diff line number Diff line change 11import { spawn } from 'node:child_process' ;
2+ import { constants } from 'node:fs' ;
3+ import { access } from 'node:fs/promises' ;
24// Dependencies
35import { basename , dirname , extname , join } from 'node:path' ;
46import lineColumn from 'line-column' ;
@@ -108,3 +110,13 @@ export async function spawnPromise(
108110 } ) ;
109111 } ) ;
110112}
113+
114+ export async function fileExists ( filePath : string ) : Promise < boolean > {
115+ try {
116+ await access ( filePath , constants . F_OK ) ;
117+ } catch {
118+ return false ;
119+ }
120+
121+ return true ;
122+ }
You can’t perform that action at this time.
0 commit comments