Skip to content

Commit 7caf4fe

Browse files
author
Danilo Tenorio Raisi
committed
fix(): #265 - Work with Monorepo mode
1 parent 1b881cf commit 7caf4fe

File tree

11 files changed

+53
-47
lines changed

11 files changed

+53
-47
lines changed
File renamed without changes.

schematics/install/files/project/__sourceRoot__/main/function.json renamed to schematics/install/files/project/__project__/function.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"type": "httpTrigger",
66
"direction": "in",
77
"name": "req",
8-
"route": "{*segments}"
8+
"route": "<%= getProjectName() %>/{*segments}"
99
},
1010
{
1111
"type": "http",
1212
"direction": "out",
1313
"name": "res"
1414
}
1515
],
16-
"scriptFile": "../../../../dist/<%= getRootDirectory() %>/main/index.js"
16+
"scriptFile": "../dist/<%= getProjectName() %>/index.js"
1717
}

schematics/install/files/project/__sourceRoot__/main/index.ts renamed to schematics/install/files/project/__project__/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Context, HttpRequest } from '@azure/functions';
22
import { AzureHttpAdapter } from '@nestjs/azure-func-http';
3-
import { createApp } from '../main.azure';
3+
import { createApp } from '../apps/<%= getProjectName() %>/src/main.azure';
44

55
export default function(context: Context, req: HttpRequest): void {
66
AzureHttpAdapter.handle(createApp, context, req);
File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = function (options) {
2+
return {
3+
...options,
4+
entry: __dirname + '/index.ts',
5+
output: {
6+
libraryTarget: 'commonjs2',
7+
filename: '<%= getProjectName() %>/index.js'
8+
}
9+
};
10+
};

schematics/install/files/project/__rootDir__/webpack.config.js

Lines changed: 0 additions & 10 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.

schematics/install/index.test.ts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ describe('Schematic Tests Nest Add', () => {
177177
'/package.json',
178178
'/tsconfig.build.json',
179179
'/tsconfig.json',
180+
'/.funcignore',
181+
'/host.json',
182+
'/local.settings.json',
183+
'/proxies.json',
180184
'/src/app.controller.spec.ts',
181185
'/src/app.controller.ts',
182186
'/src/app.module.ts',
@@ -186,22 +190,18 @@ describe('Schematic Tests Nest Add', () => {
186190
'/test/jest-e2e.json',
187191
'/apps/nestjs-azure-func-http/tsconfig.app.json',
188192
`/apps/${projectName}/tsconfig.app.json`,
189-
`/apps/${projectName}/webpack.config.js`,
190193
`/apps/${projectName}/src/app.controller.spec.ts`,
191194
`/apps/${projectName}/src/app.controller.ts`,
192195
`/apps/${projectName}/src/app.module.ts`,
193196
`/apps/${projectName}/src/app.service.ts`,
194197
`/apps/${projectName}/src/main.ts`,
195-
`/apps/${projectName}/src/.funcignore`,
196-
`/apps/${projectName}/src/host.json`,
197-
`/apps/${projectName}/src/local.settings.json`,
198198
`/apps/${projectName}/src/main.azure.ts`,
199-
`/apps/${projectName}/src/proxies.json`,
200-
`/apps/${projectName}/src/main/function.json`,
201-
`/apps/${projectName}/src/main/index.ts`,
202-
`/apps/${projectName}/src/main/sample.dat`,
203199
`/apps/${projectName}/test/app.e2e-spec.ts`,
204-
`/apps/${projectName}/test/jest-e2e.json`
200+
`/apps/${projectName}/test/jest-e2e.json`,
201+
`/${projectName}/function.json`,
202+
`/${projectName}/index.ts`,
203+
`/${projectName}/sample.dat`,
204+
`/${projectName}/webpack.config.js`
205205
]);
206206
});
207207

@@ -288,13 +288,10 @@ describe('Schematic Tests Nest Add', () => {
288288
const tree = await runner
289289
.runSchematicAsync('nest-add', options, nestTree)
290290
.toPromise();
291-
const fileContent = getFileContent(
292-
tree,
293-
`/apps/${projectName}/src/main/index.ts`
294-
);
291+
const fileContent = getFileContent(tree, `/${projectName}/index.ts`);
295292

296293
expect(fileContent).toContain(
297-
`import { createApp } from '../main.azure';`
294+
`import { createApp } from '../apps/${projectName}/src/main.azure';`
298295
);
299296
});
300297

@@ -323,11 +320,9 @@ describe('Schematic Tests Nest Add', () => {
323320

324321
const fileContent = getFileContent(
325322
tree,
326-
`/apps/${projectName}/webpack.config.js`
327-
);
328-
expect(fileContent).toContain(
329-
`filename: 'apps/${projectName}/main/index.js'`
323+
`/${projectName}/webpack.config.js`
330324
);
325+
expect(fileContent).toContain(`filename: '${projectName}/index.js'`);
331326
});
332327

333328
it('should add a custom webpack config to the compilerOptions for monorepo app', async () => {
@@ -358,7 +353,7 @@ describe('Schematic Tests Nest Add', () => {
358353
expect(compilerOptions).toEqual({
359354
tsConfigPath: `apps/${projectName}/tsconfig.app.json`,
360355
webpack: true,
361-
webpackConfigPath: `apps/${projectName}/webpack.config.js`
356+
webpackConfigPath: `${projectName}/webpack.config.js`
362357
});
363358
});
364359

@@ -385,14 +380,9 @@ describe('Schematic Tests Nest Add', () => {
385380
.runSchematicAsync('nest-add', options, nestTree)
386381
.toPromise();
387382

388-
const fileContent = getFileContent(
389-
tree,
390-
`apps/${projectName}/src/main/function.json`
391-
);
383+
const fileContent = getFileContent(tree, `${projectName}/function.json`);
392384
const parsedFile = JSON.parse(fileContent);
393-
expect(parsedFile.scriptFile).toEqual(
394-
'../../../../dist/apps/azure-2/main/index.js'
395-
);
385+
expect(parsedFile.scriptFile).toEqual(`../dist/${projectName}/index.js`);
396386
});
397387
});
398388

0 commit comments

Comments
 (0)