Skip to content

Commit

Permalink
feat(core): support for single version principle #6 (#32)
Browse files Browse the repository at this point in the history
* feat(core): #6 schematic to sync nuget packages across workspace
  • Loading branch information
AgentEnder committed May 1, 2021
1 parent b28ee64 commit 81301b6
Show file tree
Hide file tree
Showing 64 changed files with 583 additions and 262 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
4 changes: 3 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"singleQuote": true
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "always"
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"cSpell.words": [
"NXDOTNET",
"bahmutov",
"chockidar",
"classlib",
"devkit",
"nologo",
"nuget",
"nunit",
"webapi",
"writefile"
],
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
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@
"e2e-registry": "yarn verdaccio --config ./tools/scripts/local-registry/config.yml --listen 4872",
"e2e-tests": "ts-node -P ./tools/scripts/tsconfig.e2e.json ./tools/scripts/e2e.ts",
"e2e": "run-p -r e2e-registry \"e2e-tests {@}\" --",
"semantic-release": "semantic-release"
"publish-local": "run-p \"rimraf tmp\" e2e-registry \"ts-node ./tools/scripts/publish-all 99.99.99 local\"",
"semantic-release": "semantic-release",
"ts-node": "ts-node",
"rimraf": "rimraf"
},
"private": false,
"dependencies": {
"@types/xmldoc": "^1.1.5",
"chokidar": "^3.5.1",
"glob": "^7.1.6",
"inquirer": "^8.0.0",
"rimraf": "^3.0.2",
"rxjs": "^6.6.6",
"xmldoc": "^1.1.2"
Expand All @@ -58,6 +62,7 @@
"@semantic-release/exec": "^5.0.0",
"@semantic-release/git": "^9.0.0",
"@semantic-release/release-notes-generator": "^9.0.2",
"@types/inquirer": "^7.3.1",
"@types/jest": "26.0.8",
"@types/node": "14.14.33",
"@types/rimraf": "^3.0.0",
Expand Down Expand Up @@ -88,4 +93,4 @@
"url": "https://github.com/nx-dotnet/nx-dotnet.git"
},
"version": "0.3.0-dev.4"
}
}
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
Loading

0 comments on commit 81301b6

Please sign in to comment.