-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(init-templates): csharp and fsharp init fails when path contains …
…space When running or with a space in the path to the project, init will fail. This fix adds in handling for spaces and other special characters in the filepath for both windows systems and posix systems. Tests have been added for posix and manual testing was performed on a windows machine. Closes issue #18803.
- Loading branch information
1 parent
80cb527
commit 0960e90
Showing
7 changed files
with
88 additions
and
79 deletions.
There are no files selected for viewing
30 changes: 3 additions & 27 deletions
30
packages/aws-cdk/lib/init-templates/app/csharp/add-project.hook.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,9 @@ | ||
import * as child_process from 'child_process'; | ||
import * as path from 'path'; | ||
import { InvokeHook } from '../../../init'; | ||
import { shell } from '../util/os'; | ||
|
||
export const invoke: InvokeHook = async (targetDirectory: string) => { | ||
const slnPath = path.join(targetDirectory, 'src', '%name.PascalCased%.sln'); | ||
const csprojPath = path.join(targetDirectory, 'src', '%name.PascalCased%', '%name.PascalCased%.csproj'); | ||
|
||
const child = child_process.spawn('dotnet', ['sln', slnPath, 'add', csprojPath], { | ||
// Need this for Windows where we want .cmd and .bat to be found as well. | ||
shell: true, | ||
stdio: ['ignore', 'pipe', 'inherit'], | ||
}); | ||
|
||
await new Promise<string>((resolve, reject) => { | ||
const stdout = new Array<any>(); | ||
|
||
child.stdout.on('data', chunk => { | ||
process.stdout.write(chunk); | ||
stdout.push(chunk); | ||
}); | ||
|
||
child.once('error', reject); | ||
|
||
child.once('exit', code => { | ||
if (code === 0) { | ||
resolve(Buffer.concat(stdout).toString('utf-8')); | ||
} else { | ||
reject(new Error(`Could not add project %name.PascalCased%.csproj to solution %name.PascalCased%.sln. Error code: ${code}`)); | ||
} | ||
}); | ||
}); | ||
}; | ||
await shell(['dotnet', 'sln', slnPath, 'add', csprojPath], { errorMessage: 'Could not add project %name.PascalCased%.csproj to solution %name.PascalCased%.sln.' }); | ||
}; |
28 changes: 2 additions & 26 deletions
28
packages/aws-cdk/lib/init-templates/app/fsharp/add-project.hook.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,9 @@ | ||
import * as child_process from 'child_process'; | ||
import * as path from 'path'; | ||
import { InvokeHook } from '../../../init'; | ||
import { shell } from '../util/os'; | ||
|
||
export const invoke: InvokeHook = async (targetDirectory: string) => { | ||
const slnPath = path.join(targetDirectory, 'src', '%name.PascalCased%.sln'); | ||
const fsprojPath = path.join(targetDirectory, 'src', '%name.PascalCased%', '%name.PascalCased%.fsproj'); | ||
|
||
const child = child_process.spawn('dotnet', ['sln', slnPath, 'add', fsprojPath], { | ||
// Need this for Windows where we want .cmd and .bat to be found as well. | ||
shell: true, | ||
stdio: ['ignore', 'pipe', 'inherit'], | ||
}); | ||
|
||
await new Promise<string>((resolve, reject) => { | ||
const stdout = new Array<any>(); | ||
|
||
child.stdout.on('data', chunk => { | ||
process.stdout.write(chunk); | ||
stdout.push(chunk); | ||
}); | ||
|
||
child.once('error', reject); | ||
|
||
child.once('exit', code => { | ||
if (code === 0) { | ||
resolve(Buffer.concat(stdout).toString('utf-8')); | ||
} else { | ||
reject(new Error(`Could not add project %name.PascalCased%.fsproj to solution %name.PascalCased%.sln. Error code: ${code}`)); | ||
} | ||
}); | ||
}); | ||
await shell(['dotnet', 'sln', slnPath, 'add', fsprojPath], { errorMessage: 'Could not add project %name.PascalCased%.fsproj to solution %name.PascalCased%.sln.' }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters