@@ -4,26 +4,23 @@ import * as jsonc from 'jsonc-parser';
4
4
import * as path from 'path' ;
5
5
import { localize as i18n } from '../locale' ;
6
6
import { logger } from '../logger' ;
7
- import { existsAsync , extensionContext , mkdirpAsync , readdirAsync , readFileAsync , writeFileAsync } from '../utilities' ;
7
+ import { existsAsync , extensionContext , statAsync , readdirAsync , readFileAsync } from '../utilities' ;
8
8
import * as vscode from '../vscodeshim' ;
9
9
import { IExampleTemplateAPI , IExampleTemplateCreator , IUtilitiesAPI } from '../wpilibapishim' ;
10
10
import { generateCopyCpp , generateCopyJava } from './generator' ;
11
11
import { VendorLibrariesBase } from './vendorlibrariesbase' ;
12
12
13
- export interface IFile {
14
- deployloc : string ;
15
- contents : string ;
16
- }
17
-
18
13
interface IJsonExample {
19
14
name : string ;
20
15
description : string ;
16
+ tags : string [ ] ;
21
17
gradlebase : string ;
22
- language : string ;
18
+ language : string ; // either "java" or "cpp"
19
+ commandversion : number ;
23
20
mainclass ?: string | undefined ;
24
21
packagetoreplace ?: string | undefined ;
25
22
dependencies : string [ ] ;
26
- files : IFile [ ] ;
23
+ foldername : string ;
27
24
}
28
25
29
26
// tslint:disable-next-line:no-any
@@ -32,11 +29,12 @@ function isJsonExample(arg: any): arg is IJsonExample {
32
29
33
30
return jsonDep . name !== undefined && jsonDep . description !== undefined
34
31
&& jsonDep . gradlebase !== undefined && jsonDep . dependencies !== undefined
35
- && jsonDep . files !== undefined && jsonDep . language !== undefined ;
32
+ && jsonDep . foldername !== undefined && jsonDep . language !== undefined ;
36
33
}
37
34
38
35
export async function addVendorExamples ( resourceRoot : string , core : IExampleTemplateAPI , utilities : IUtilitiesAPI ,
39
36
vendorlibs : VendorLibrariesBase ) : Promise < void > {
37
+ const shimmedResourceRoot = path . join ( resourceRoot , 'vendordeps' ) ;
40
38
const storagePath = extensionContext . storagePath ;
41
39
if ( storagePath === undefined ) {
42
40
return ;
@@ -46,7 +44,11 @@ export async function addVendorExamples(resourceRoot: string, core: IExampleTemp
46
44
if ( await existsAsync ( exampleDir ) ) {
47
45
const files = await readdirAsync ( exampleDir ) ;
48
46
for ( const file of files ) {
49
- const fileContents = await readFileAsync ( path . join ( exampleDir , file ) , 'utf8' ) ;
47
+ const filePath = path . join ( exampleDir , file ) ;
48
+ if ( ( await statAsync ( filePath ) ) . isDirectory ( ) ) {
49
+ continue ;
50
+ }
51
+ const fileContents = await readFileAsync ( filePath , 'utf8' ) ;
50
52
const parsed = jsonc . parse ( fileContents ) ;
51
53
if ( Array . isArray ( parsed ) ) {
52
54
for ( const ex of parsed ) {
@@ -68,43 +70,23 @@ export async function addVendorExamples(resourceRoot: string, core: IExampleTemp
68
70
async generate ( folderInto : vscode . Uri ) : Promise < boolean > {
69
71
try {
70
72
if ( ex . language === 'java' ) {
71
- if ( ! await generateCopyJava ( resourceRoot , async ( copyPath , rootDir ) => {
72
- for ( const copyFile of ex . files ) {
73
- const copyFilePath = path . join ( copyPath , copyFile . deployloc ) ;
74
- const copyParent = path . dirname ( copyFilePath ) ;
75
- await mkdirpAsync ( copyParent ) ;
76
- await writeFileAsync ( copyFilePath , copyFile . contents ) ;
77
- }
78
- const vendorFiles = await vendorlibs . findForUUIDs ( ex . dependencies ) ;
79
- for ( const vendorFile of vendorFiles ) {
80
- await vendorlibs . installDependency ( vendorFile , vendorlibs . getVendorFolder ( rootDir ) , true ) ;
81
- }
82
- return true ;
83
- } ,
73
+ if ( ! await generateCopyJava ( shimmedResourceRoot , path . join ( exampleDir , ex . foldername ) ,
84
74
path . join ( gradleBasePath , ex . gradlebase ) , folderInto . fsPath , 'frc.robot.' + ex . mainclass ,
85
- path . join ( 'frc' , 'robot' ) , false , false , ex . packagetoreplace ) ) {
75
+ path . join ( 'frc' , 'robot' ) , false , ex . commandversion !== 2 , ex . packagetoreplace ) ) {
86
76
vscode . window . showErrorMessage ( i18n ( 'message' , 'Cannot create into non empty folder' ) ) ;
87
77
return false ;
88
78
}
89
79
} else {
90
- if ( ! await generateCopyCpp ( resourceRoot , async ( copyPath , rootDir ) => {
91
- for ( const copyFile of ex . files ) {
92
- const copyFilePath = path . join ( copyPath , copyFile . deployloc ) ;
93
- const copyParent = path . dirname ( copyFilePath ) ;
94
- await mkdirpAsync ( copyParent ) ;
95
- await writeFileAsync ( copyFilePath , copyFile . contents ) ;
96
- }
97
- const vendorFiles = await vendorlibs . findForUUIDs ( ex . dependencies ) ;
98
- for ( const vendorFile of vendorFiles ) {
99
- await vendorlibs . installDependency ( vendorFile , vendorlibs . getVendorFolder ( rootDir ) , true ) ;
100
- }
101
- return true ;
102
- } ,
103
- path . join ( gradleBasePath , ex . gradlebase ) , folderInto . fsPath , false , false , false ) ) {
80
+ if ( ! await generateCopyCpp ( shimmedResourceRoot , path . join ( exampleDir , ex . foldername ) ,
81
+ path . join ( gradleBasePath , ex . gradlebase ) , folderInto . fsPath , false , false , ex . commandversion !== 2 ) ) {
104
82
vscode . window . showErrorMessage ( i18n ( 'message' , 'Cannot create into non empty folder' ) ) ;
105
83
return false ;
106
84
}
107
85
}
86
+ const vendorFiles = await vendorlibs . findForUUIDs ( ex . dependencies ) ;
87
+ for ( const vendorFile of vendorFiles ) {
88
+ await vendorlibs . installDependency ( vendorFile , vendorlibs . getVendorFolder ( folderInto . fsPath ) , true ) ;
89
+ }
108
90
} catch ( err ) {
109
91
logger . error ( 'Example generation error: ' , err ) ;
110
92
return false ;
0 commit comments