-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(dotnet): add publish command to client Add a publish command for a future publish executor to use * feat(core): add publish executor Add a publish executor that delegates to `dotnet publish` Resolves #33 * feat(core): add MSBuild properties to publish executor Add support for commonly used but unusually formatted MSBuild properties. * test(core): fix name of publish executor in tests Fix the name of the executor to be consistent with real world targets. Co-authored-by: Ben Callaghan <bcallaghan@selectbankcard.com>
- Loading branch information
1 parent
282e44f
commit f7cbd27
Showing
16 changed files
with
297 additions
and
19 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,4 +93,4 @@ | |
"url": "https://github.com/nx-dotnet/nx-dotnet.git" | ||
}, | ||
"version": "0.4.2-dev.1" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { ExecutorContext } from '@nrwl/devkit'; | ||
|
||
import { promises as fs } from 'fs'; | ||
|
||
import { DotNetClient, mockDotnetFactory } from '@nx-dotnet/dotnet'; | ||
import { rimraf } from '@nx-dotnet/utils'; | ||
|
||
import executor from './executor'; | ||
import { PublishExecutorSchema } from './schema'; | ||
|
||
const options: PublishExecutorSchema = { | ||
configuration: 'Debug', | ||
}; | ||
|
||
const root = process.cwd() + '/tmp'; | ||
|
||
jest.mock('../../../../dotnet/src/lib/core/dotnet.client'); | ||
|
||
describe('Publish Executor', () => { | ||
let context: ExecutorContext; | ||
let dotnetClient: DotNetClient; | ||
|
||
beforeEach(() => { | ||
context = { | ||
root: root, | ||
cwd: root, | ||
projectName: 'my-app', | ||
targetName: 'publish', | ||
workspace: { | ||
version: 2, | ||
projects: { | ||
'my-app': { | ||
root: `${root}/apps/my-app`, | ||
sourceRoot: `${root}/apps/my-app`, | ||
targets: { | ||
publish: { | ||
executor: '@nx-dotnet/core:publish', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
isVerbose: false, | ||
}; | ||
dotnetClient = new DotNetClient(mockDotnetFactory()); | ||
}); | ||
|
||
afterEach(async () => { | ||
await rimraf(root); | ||
}); | ||
|
||
it('detects no dotnet project', async () => { | ||
expect.assertions(1); | ||
try { | ||
await executor(options, context, dotnetClient); | ||
} catch (e) { | ||
console.log(e.message); | ||
expect(e.message).toMatch( | ||
"Unable to find a build-able project within project's source directory!", | ||
); | ||
} | ||
}); | ||
|
||
it('detects multiple dotnet projects', async () => { | ||
expect.assertions(1); | ||
|
||
try { | ||
const directoryPath = `${root}/apps/my-app`; | ||
await fs.mkdir(directoryPath, { recursive: true }); | ||
await Promise.all([ | ||
fs.writeFile(`${directoryPath}/1.csproj`, ''), | ||
fs.writeFile(`${directoryPath}/2.csproj`, ''), | ||
]); | ||
} catch (e) { | ||
console.warn(e.message); | ||
} | ||
|
||
try { | ||
await executor(options, context, dotnetClient); | ||
} catch (e) { | ||
console.log(e.message); | ||
expect(e.message).toMatch( | ||
"More than one build-able projects are contained within the project's source directory!", | ||
); | ||
} | ||
}); | ||
|
||
it('calls publish when 1 project file is found', async () => { | ||
try { | ||
const directoryPath = `${root}/apps/my-app`; | ||
await fs.mkdir(directoryPath, { recursive: true }); | ||
await Promise.all([fs.writeFile(`${directoryPath}/1.csproj`, '')]); | ||
} catch (e) { | ||
console.warn(e.message); | ||
} | ||
|
||
const res = await executor(options, context, dotnetClient); | ||
expect( | ||
(dotnetClient as jest.Mocked<DotNetClient>).publish, | ||
).toHaveBeenCalled(); | ||
expect(res.success).toBeTruthy(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ExecutorContext } from '@nrwl/devkit'; | ||
|
||
import { | ||
DotNetClient, | ||
dotnetFactory, | ||
dotnetPublishFlags, | ||
} from '@nx-dotnet/dotnet'; | ||
import { | ||
getExecutedProjectConfiguration, | ||
getProjectFileForNxProject, | ||
} from '@nx-dotnet/utils'; | ||
|
||
import { PublishExecutorSchema } from './schema'; | ||
|
||
export default async function runExecutor( | ||
options: PublishExecutorSchema, | ||
context: ExecutorContext, | ||
dotnetClient: DotNetClient = new DotNetClient(dotnetFactory()), | ||
) { | ||
const nxProjectConfiguration = getExecutedProjectConfiguration(context); | ||
const projectFilePath = await getProjectFileForNxProject( | ||
nxProjectConfiguration, | ||
); | ||
|
||
const { publishProfile, extraParameters, ...flags } = options; | ||
|
||
dotnetClient.publish( | ||
projectFilePath, | ||
Object.keys(flags).map((x) => ({ | ||
flag: x as dotnetPublishFlags, | ||
value: (options as Record<string, string | boolean>)[x], | ||
})), | ||
publishProfile, | ||
extraParameters, | ||
); | ||
|
||
return { | ||
success: true, | ||
}; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { dotnetPublishFlags } from '@nx-dotnet/dotnet'; | ||
|
||
export type PublishExecutorSchema = { | ||
[key in dotnetPublishFlags]?: string | boolean; | ||
} & { | ||
publishProfile?: string; | ||
extraParameters?: string; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"cli": "nx", | ||
"title": "NxDotnet Publish", | ||
"description": "Publishes an app via the `dotnet` cli command.", | ||
"type": "object", | ||
"properties": { | ||
"configuration": { | ||
"type": "string", | ||
"enum": ["Debug", "Release"], | ||
"default": "Debug", | ||
"description": "Defines the build configuration The default for most projects is Debug, but you can override the build configuration settings in your project." | ||
}, | ||
"framework": { | ||
"type": "string", | ||
"description": "Publishes the application for the specified target framework. You must specify the target framework in the project file." | ||
}, | ||
"force": { | ||
"type": "boolean", | ||
"description": "Forces all dependencies to be resolved even if the last restore was successful. Specifying this flag is the same as deleting the project.assets.json file." | ||
}, | ||
"noBuild": { | ||
"type": "boolean", | ||
"description": "Doesn't build the project before publishing. It also implicitly sets the --no-restore flag." | ||
}, | ||
"noDependencies": { | ||
"type": "boolean", | ||
"description": "Ignores project-to-project references and only restores the root project." | ||
}, | ||
"nologo": { | ||
"type": "boolean", | ||
"description": "Doesn't display the startup banner or the copyright message. Available since .NET Core 3.0 SDK." | ||
}, | ||
"noRestore": { | ||
"type": "boolean", | ||
"description": "Doesn't execute an implicit restore when running the command." | ||
}, | ||
"output": { | ||
"type": "string", | ||
"description": "Specifies the path for the output directory." | ||
}, | ||
"selfContained": { | ||
"type": "boolean", | ||
"description": "Publishes the .NET runtime with your application so the runtime doesn't need to be installed on the target machine. Default is true if a runtime identifier is specified and the project is an executable project (not a library project)." | ||
}, | ||
"runtime": { | ||
"type": "string", | ||
"description": "Publishes the application for a given runtime." | ||
}, | ||
"verbosity": { | ||
"type": "string", | ||
"enum": ["quiet", "minimal", "normal", "detailed", "diagnostic"], | ||
"default": "minimal" | ||
}, | ||
"versionSuffix": { | ||
"type": "string", | ||
"description": "Defines the version suffix to replace the asterisk (*) in the version field of the project file." | ||
}, | ||
"publishProfile": { | ||
"type": "string", | ||
"description": "Specifies the name of the publish profile to use while publishing. Do not include the file path or the file extension. MSBuild by default looks in the Properties/PublishProfiles folder and assumes the pubxml file extension." | ||
}, | ||
"extraParameters": { | ||
"type": "string", | ||
"description": "Extra command-line arguments that are passed verbatim to the dotnet command." | ||
} | ||
}, | ||
"required": [] | ||
} |
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
22 changes: 22 additions & 0 deletions
22
packages/dotnet/src/lib/models/dotnet-publish/dotnet-publish-flags.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export type dotnetPublishFlags = | ||
| 'configuration' | ||
| 'framework' | ||
| 'force' | ||
| 'manifest' | ||
| 'noBuild' | ||
| 'noDependencies' | ||
| 'nologo' | ||
| 'noRestore' | ||
| 'output' | ||
| 'selfContained' | ||
| 'runtime' | ||
| 'verbosity' | ||
| 'versionSuffix'; | ||
|
||
export const publishKeyMap: Partial<{ [key in dotnetPublishFlags]: string }> = { | ||
noBuild: 'no-build', | ||
noDependencies: 'no-dependencies', | ||
noRestore: 'no-restore', | ||
selfContained: 'self-contained', | ||
versionSuffix: 'version-suffix', | ||
}; |
6 changes: 6 additions & 0 deletions
6
packages/dotnet/src/lib/models/dotnet-publish/dotnet-publish-options.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { dotnetPublishFlags } from './dotnet-publish-flags'; | ||
|
||
export type dotnetPublishOptions = { | ||
flag: dotnetPublishFlags; | ||
value?: string | boolean; | ||
}[]; |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './dotnet-publish-flags'; | ||
export * from './dotnet-publish-options'; |
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
Oops, something went wrong.