Skip to content

Commit

Permalink
feat(core): #6 schematic to sync nuget packages across workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed May 1, 2021
1 parent 450cbc1 commit a6168fe
Show file tree
Hide file tree
Showing 44 changed files with 279 additions and 184 deletions.
11 changes: 6 additions & 5 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG] "
title: '[BUG] '
labels: bug, needs-triage
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -24,9 +24,10 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Environment:**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
- Affected Packages

**Additional context**
Expand Down
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
name: Feature request
about: Suggest an idea for this project
title: "[Feature]"
title: '[Feature]'
labels: enhancement, needs-triage
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ env:
NX_RUN_GROUP: ${{ github.run_id }}

jobs:

build:
runs-on: ubuntu-latest
name: Building affected apps
Expand Down
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# [0.3.0-dev.4](https://github.com/nx-dotnet/nx-dotnet/compare/v0.3.0-dev.3...v0.3.0-dev.4) (2021-04-29)


### Bug Fixes

* **repo:** update .releaserc to commit package.json version back ([dea86e3](https://github.com/nx-dotnet/nx-dotnet/commit/dea86e3c2015ede2c10c508f8c79f2877ed9ee4d))

- **repo:** update .releaserc to commit package.json version back ([dea86e3](https://github.com/nx-dotnet/nx-dotnet/commit/dea86e3c2015ede2c10c508f8c79f2877ed9ee4d))

### Features

* **core:** schematic for adding npm package [#5](https://github.com/nx-dotnet/nx-dotnet/issues/5) ([b97c097](https://github.com/nx-dotnet/nx-dotnet/commit/b97c0972f1cbc87045e9047bf0222e90d3940cfe)), closes [#6](https://github.com/nx-dotnet/nx-dotnet/issues/6)
- **core:** schematic for adding npm package [#5](https://github.com/nx-dotnet/nx-dotnet/issues/5) ([b97c097](https://github.com/nx-dotnet/nx-dotnet/commit/b97c0972f1cbc87045e9047bf0222e90d3940cfe)), closes [#6](https://github.com/nx-dotnet/nx-dotnet/issues/6)

## [0.2.1](https://github.com/nx-dotnet/nx-dotnet/compare/v0.2.0...v0.2.1) (2021-04-27)

Expand Down
14 changes: 7 additions & 7 deletions e2e/core-e2e/tests/nx-dotnet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ describe('nx-dotnet e2e', () => {
ensureNxProject('@nx-dotnet/core', 'dist/packages/core');

await runNxCommandAsync(
`generate @nx-dotnet/core:app ${testApp} --language="C#" --template="webapi"`
`generate @nx-dotnet/core:app ${testApp} --language="C#" --template="webapi"`,
);

await runNxCommandAsync(
`generate @nx-dotnet/core:lib ${testLib} --language="C#" --template="classlib"`
`generate @nx-dotnet/core:lib ${testLib} --language="C#" --template="classlib"`,
);

const output = await runNxCommandAsync(
`generate @nx-dotnet/core:project-reference ${testApp} ${testLib}`
`generate @nx-dotnet/core:project-reference ${testApp} ${testLib}`,
);

expect(output.stdout).toMatch(/Reference .* added to the project/);
Expand All @@ -32,7 +32,7 @@ describe('nx-dotnet e2e', () => {
it('should obey dry-run', async () => {
const app = uniq('app');
await runNxCommandAsync(
`generate @nx-dotnet/core:app ${app} --language="C#" --template="webapi" --dry-run`
`generate @nx-dotnet/core:app ${app} --language="C#" --template="webapi" --dry-run`,
);

let exists = true;
Expand All @@ -48,7 +48,7 @@ describe('nx-dotnet e2e', () => {
it('should generate an app', async () => {
const app = uniq('app');
await runNxCommandAsync(
`generate @nx-dotnet/core:app ${app} --language="C#" --template="webapi"`
`generate @nx-dotnet/core:app ${app} --language="C#" --template="webapi"`,
);

let exists = true;
Expand All @@ -66,7 +66,7 @@ describe('nx-dotnet e2e', () => {
it('should obey dry-run', async () => {
const lib = uniq('lib');
await runNxCommandAsync(
`generate @nx-dotnet/core:lib ${lib} --language="C#" --template="webapi" --dry-run`
`generate @nx-dotnet/core:lib ${lib} --language="C#" --template="webapi" --dry-run`,
);

let exists = true;
Expand All @@ -82,7 +82,7 @@ describe('nx-dotnet e2e', () => {
it('should generate an lib', async () => {
const lib = uniq('lib');
await runNxCommandAsync(
`generate @nx-dotnet/core:lib ${lib} --language="C#" --template="webapi"`
`generate @nx-dotnet/core:lib ${lib} --language="C#" --template="webapi"`,
);

let exists = true;
Expand Down
28 changes: 14 additions & 14 deletions e2e/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function workspaceConfigName() {
}

export function updateWorkspaceConfig(
callback: (json: { [key: string]: any }) => Object
callback: (json: { [key: string]: any }) => Object,
) {
const file = workspaceConfigName();
updateFile(file, JSON.stringify(callback(readJson(file)), null, 2));
Expand All @@ -66,7 +66,7 @@ export function runCreateWorkspace(
packageManager?: 'npm' | 'yarn' | 'pnpm';
cli?: string;
extraArgs?: string;
}
},
) {
projName = name;

Expand Down Expand Up @@ -197,7 +197,7 @@ export function runCommandAsync(
opts: RunCmdOpts = {
silenceError: false,
env: process.env,
}
},
): Promise<{ stdout: string; stderr: string; combinedOutput: string }> {
return new Promise((resolve, reject) => {
exec(
Expand All @@ -211,15 +211,15 @@ export function runCommandAsync(
reject(err);
}
resolve({ stdout, stderr, combinedOutput: `${stdout}${stderr}` });
}
},
);
});
}

export function runCommandUntil(
command: string,
criteria: (output: string) => boolean,
{ kill = true } = {}
{ kill = true } = {},
): Promise<{ process: ChildProcess }> {
const pm = getPackageManagerCommand();
const p = exec(`${pm.runNx} ${command}`, {
Expand Down Expand Up @@ -259,12 +259,12 @@ export function runCLIAsync(
silenceError: false,
env: process.env,
silent: false,
}
},
): Promise<{ stdout: string; stderr: string; combinedOutput: string }> {
const pm = getPackageManagerCommand();
return runCommandAsync(
`${opts.silent ? pm.runNxSilent : pm.runNx} ${command}`,
opts
opts,
);
}

Expand All @@ -274,7 +274,7 @@ export function runNgAdd(
silenceError: false,
env: process.env,
cwd: tmpProjPath(),
}
},
): string {
try {
packageInstall('@nrwl/workspace');
Expand All @@ -283,12 +283,12 @@ export function runNgAdd(
{
cwd: tmpProjPath(),
env: opts.env as any,
}
},
)
.toString()
.replace(
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
''
'',
);
} catch (e) {
if (opts.silenceError) {
Expand All @@ -305,7 +305,7 @@ export function runCLI(
opts: RunCmdOpts = {
silenceError: false,
env: process.env,
}
},
): string {
try {
const pm = getPackageManagerCommand();
Expand All @@ -315,7 +315,7 @@ export function runCLI(
}).toString();
r = r.replace(
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
''
'',
);
if (process.env.VERBOSE_OUTPUT) {
console.log(r);
Expand Down Expand Up @@ -402,15 +402,15 @@ export function createFile(f: string, content: string = ''): void {

export function updateFile(
f: string,
content: string | ((content: string) => string)
content: string | ((content: string) => string),
): void {
ensureDirSync(path.dirname(tmpProjPath(f)));
if (typeof content === 'string') {
writeFileSync(tmpProjPath(f), content);
} else {
writeFileSync(
tmpProjPath(f),
content(readFileSync(tmpProjPath(f)).toString())
content(readFileSync(tmpProjPath(f)).toString()),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
"bugs": {
"url": "https://github.com/nx-dotnet/nx-dotnet/issues/new?assignees=&labels=bug%2C+needs-triage&template=bug_report.md&title=%5BBUG%5D+"
}
}
}
6 changes: 3 additions & 3 deletions packages/core/src/executors/build/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Build Executor', () => {
} catch (e) {
console.log(e.message);
expect(e.message).toMatch(
"Unable to find a build-able project within project's source directory!"
"Unable to find a build-able project within project's source directory!",
);
}
});
Expand All @@ -80,7 +80,7 @@ describe('Build Executor', () => {
} catch (e) {
console.log(e.message);
expect(e.message).toMatch(
"More than one build-able projects are contained within the project's source directory!"
"More than one build-able projects are contained within the project's source directory!",
);
}
});
Expand All @@ -96,7 +96,7 @@ describe('Build Executor', () => {

const res = await executor(options, context, dotnetClient);
expect(
(dotnetClient as jest.Mocked<DotNetClient>).build
(dotnetClient as jest.Mocked<DotNetClient>).build,
).toHaveBeenCalled();
expect(res.success).toBeTruthy();
});
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/executors/build/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ import { BuildExecutorSchema } from './schema';
export default async function runExecutor(
options: BuildExecutorSchema,
context: ExecutorContext,
dotnetClient: DotNetClient = new DotNetClient(dotnetFactory())
dotnetClient: DotNetClient = new DotNetClient(dotnetFactory()),
) {
const nxProjectConfiguration = getExecutedProjectConfiguration(context);
const projectFilePath = await getProjectFileForNxProject(
nxProjectConfiguration
nxProjectConfiguration,
);

dotnetClient.build(
projectFilePath,
Object.keys(options).map((x) => ({
flag: x as dotnetBuildFlags,
value: (options as Record<string, string | boolean>)[x],
}))
})),
);

return {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/executors/serve/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let projectDirectory: string;
export default function dotnetRunExecutor(
options: ServeExecutorSchema,
context: ExecutorContext,
dotnetClient: DotNetClient = new DotNetClient(dotnetFactory())
dotnetClient: DotNetClient = new DotNetClient(dotnetFactory()),
): Promise<{ success: boolean }> {
const nxProjectConfiguration = getExecutedProjectConfiguration(context);

Expand All @@ -43,7 +43,7 @@ export default function dotnetRunExecutor(
context.workspace,
(dependency) => {
watcher.add(dependency.root);
}
},
);

watcher.on('all', (event, path) => {
Expand All @@ -68,7 +68,7 @@ export default function dotnetRunExecutor(
const setupDotnetRun = (
dotnetClient: DotNetClient,
project: string,
options: ServeExecutorSchema
options: ServeExecutorSchema,
) => {
if (childProcess) {
childProcess.kill('SIGTERM');
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/executors/test/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ import { TestExecutorSchema } from './schema';
export default async function runExecutor(
options: TestExecutorSchema,
context: ExecutorContext,
dotnetClient: DotNetClient = new DotNetClient(dotnetFactory())
dotnetClient: DotNetClient = new DotNetClient(dotnetFactory()),
) {
const nxProjectConfiguration = getExecutedProjectConfiguration(context);
const projectFilePath = await getProjectFileForNxProject(
nxProjectConfiguration
nxProjectConfiguration,
);

dotnetClient.test(
projectFilePath,
Object.keys(options).map((x) => ({
flag: x as dotnetTestFlags,
value: (options as Record<string, string | boolean>)[x],
}))
})),
);

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/generators/app/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('nx-dotnet library generator', () => {
appTree,
options,
dotnetClient,
'application'
'application',
);
});
});
2 changes: 1 addition & 1 deletion packages/core/src/generators/app/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { NxDotnetGeneratorSchema } from './schema';
export default function (
host: Tree,
options: NxDotnetGeneratorSchema,
dotnetClient = new DotNetClient(dotnetFactory())
dotnetClient = new DotNetClient(dotnetFactory()),
) {
return GenerateProject(host, options, dotnetClient, 'application');
}
1 change: 1 addition & 0 deletions packages/core/src/generators/init/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readJson, Tree } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';

import { CONFIG_FILE_PATH, NxDotnetConfig } from '@nx-dotnet/utils';

import generator from './generator';
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/generators/init/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Tree,
writeJson,
} from '@nrwl/devkit';

import { CONFIG_FILE_PATH, NxDotnetConfig } from '@nx-dotnet/utils';

export default async function (host: Tree) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/generators/lib/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('nx-dotnet library generator', () => {
appTree,
options,
dotnetClient,
'library'
'library',
);
});
});
Loading

0 comments on commit a6168fe

Please sign in to comment.