@nestledjs/api 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/account/generator.d.ts +3 -0
- package/src/account/generator.js +19 -0
- package/src/account/generator.js.map +1 -0
- package/src/app/generator.d.ts +6 -0
- package/src/app/generator.js +96 -0
- package/src/app/generator.js.map +1 -0
- package/src/config/generator.d.ts +3 -0
- package/src/config/generator.js +18 -0
- package/src/config/generator.js.map +1 -0
- package/src/core/generator.d.ts +3 -0
- package/src/core/generator.js +31 -0
- package/src/core/generator.js.map +1 -0
- package/src/custom/generator.d.ts +24 -0
- package/src/custom/generator.js +199 -0
- package/src/custom/generator.js.map +1 -0
- package/src/custom/schema.d.ts +5 -0
- package/src/custom/schema.js +3 -0
- package/src/custom/schema.js.map +1 -0
- package/src/extended/generator.d.ts +3 -0
- package/src/extended/generator.js +136 -0
- package/src/extended/generator.js.map +1 -0
- package/src/extended/index.d.ts +1 -0
- package/src/extended/index.js +7 -0
- package/src/extended/index.js.map +1 -0
- package/src/extended/{schema.ts → schema.d.ts} +2 -2
- package/src/extended/schema.js +3 -0
- package/src/extended/schema.js.map +1 -0
- package/src/generate-crud/generator.d.ts +50 -0
- package/src/generate-crud/generator.js +296 -0
- package/src/generate-crud/generator.js.map +1 -0
- package/src/generate-crud/schema.d.ts +8 -0
- package/src/generate-crud/schema.js +3 -0
- package/src/generate-crud/schema.js.map +1 -0
- package/src/index.d.ts +13 -0
- package/src/index.js +17 -0
- package/src/index.js.map +1 -0
- package/src/plugin/generator.d.ts +3 -0
- package/src/plugin/generator.js +74 -0
- package/src/plugin/generator.js.map +1 -0
- package/src/plugin/{schema.ts → schema.d.ts} +3 -3
- package/src/plugin/schema.js +3 -0
- package/src/plugin/schema.js.map +1 -0
- package/src/prisma/generator.d.ts +3 -0
- package/src/prisma/generator.js +61 -0
- package/src/prisma/generator.js.map +1 -0
- package/src/setup/generator.d.ts +3 -0
- package/src/setup/generator.js +104 -0
- package/src/setup/generator.js.map +1 -0
- package/src/smtp-mailer/generator.d.ts +2 -0
- package/src/smtp-mailer/generator.js +17 -0
- package/src/smtp-mailer/generator.js.map +1 -0
- package/src/user/generator.d.ts +2 -0
- package/src/user/generator.js +18 -0
- package/src/user/generator.js.map +1 -0
- package/src/utils/generator.d.ts +2 -0
- package/src/utils/generator.js +17 -0
- package/src/utils/generator.js.map +1 -0
- package/src/workspace-setup/generator.d.ts +1 -0
- package/src/workspace-setup/generator.js +42 -0
- package/src/workspace-setup/generator.js.map +1 -0
- package/src/workspace-setup/lib/helpers.d.ts +16 -0
- package/src/workspace-setup/lib/helpers.js +164 -0
- package/src/workspace-setup/lib/helpers.js.map +1 -0
- package/eslint.config.cjs +0 -28
- package/project.json +0 -47
- package/src/account/generator.spec.ts +0 -71
- package/src/account/generator.ts +0 -20
- package/src/app/generator.spec.ts +0 -112
- package/src/app/generator.ts +0 -105
- package/src/config/generator.spec.ts +0 -47
- package/src/config/generator.ts +0 -16
- package/src/core/generator.spec.ts +0 -85
- package/src/core/generator.ts +0 -35
- package/src/custom/generator.spec.ts +0 -75
- package/src/custom/generator.ts +0 -239
- package/src/custom/schema.ts +0 -5
- package/src/extended/generator.spec.ts +0 -95
- package/src/extended/generator.ts +0 -161
- package/src/extended/index.ts +0 -1
- package/src/generate-crud/generator.spec.ts +0 -84
- package/src/generate-crud/generator.ts +0 -354
- package/src/generate-crud/schema.ts +0 -8
- package/src/index.ts +0 -13
- package/src/plugin/generator.spec.ts +0 -18
- package/src/plugin/generator.ts +0 -74
- package/src/prisma/generator.spec.ts +0 -60
- package/src/prisma/generator.ts +0 -61
- package/src/setup/generator.spec.ts +0 -18
- package/src/setup/generator.ts +0 -107
- package/src/smtp-mailer/generator.spec.ts +0 -41
- package/src/smtp-mailer/generator.ts +0 -14
- package/src/user/generator.spec.ts +0 -41
- package/src/user/generator.ts +0 -15
- package/src/utils/generator.ts +0 -14
- package/src/workspace-setup/generator.spec.ts +0 -85
- package/src/workspace-setup/generator.ts +0 -57
- package/src/workspace-setup/lib/helpers.ts +0 -149
- package/tsconfig.json +0 -16
- package/tsconfig.lib.json +0 -23
- package/tsconfig.spec.json +0 -22
- package/vite.config.mts +0 -31
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'
|
|
2
|
-
import { Tree } from '@nx/devkit'
|
|
3
|
-
import { execSync } from 'child_process'
|
|
4
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
-
import generator from './generator'
|
|
6
|
-
|
|
7
|
-
vi.mock('child_process', async (importOriginal) => {
|
|
8
|
-
const originalModule = await importOriginal()
|
|
9
|
-
return {
|
|
10
|
-
...(originalModule as object),
|
|
11
|
-
execSync: vi.fn(),
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
describe('api generator', () => {
|
|
16
|
-
let tree: Tree
|
|
17
|
-
const mockedExecSync = execSync as ReturnType<(typeof vi)['fn']>
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
tree = createTreeWithEmptyWorkspace()
|
|
21
|
-
tree.write('package.json', JSON.stringify({ name: 'test-repo', scripts: {} }))
|
|
22
|
-
|
|
23
|
-
mockedExecSync.mockImplementation((command: string) => {
|
|
24
|
-
if (command.startsWith('nx g @nx/nest:application')) {
|
|
25
|
-
tree.write(
|
|
26
|
-
'apps/api/webpack.config.js',
|
|
27
|
-
`
|
|
28
|
-
const path = require('path');
|
|
29
|
-
const { composePlugins, withNx } = require('@nx/webpack');
|
|
30
|
-
|
|
31
|
-
module.exports = composePlugins(withNx(), (config) => {
|
|
32
|
-
return {
|
|
33
|
-
...config,
|
|
34
|
-
output: {
|
|
35
|
-
...config.output,
|
|
36
|
-
devtoolModuleFilenameTemplate: (info) => {
|
|
37
|
-
const rel = path.relative(process.cwd(), info.absoluteResourcePath);
|
|
38
|
-
return \`webpack://\${rel}\`;
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
assets: ['./src/assets'],
|
|
42
|
-
generatePackageJson: true,
|
|
43
|
-
};
|
|
44
|
-
});`
|
|
45
|
-
)
|
|
46
|
-
// Add a mock tsconfig.app.json file with the compiler options we want to remove
|
|
47
|
-
tree.write('apps/api/tsconfig.app.json', JSON.stringify({
|
|
48
|
-
extends: '../../tsconfig.base.json',
|
|
49
|
-
compilerOptions: {
|
|
50
|
-
module: 'commonjs',
|
|
51
|
-
moduleResolution: 'node',
|
|
52
|
-
emitDecoratorMetadata: true,
|
|
53
|
-
experimentalDecorators: true,
|
|
54
|
-
outDir: '../../dist/out-tsc',
|
|
55
|
-
declaration: true,
|
|
56
|
-
types: ['node']
|
|
57
|
-
},
|
|
58
|
-
exclude: ['jest.config.ts', '**/*.spec.ts', '**/*.test.ts'],
|
|
59
|
-
include: ['**/*.ts']
|
|
60
|
-
}, null, 2))
|
|
61
|
-
tree.write('apps/api/src/app/.gitkeep', '')
|
|
62
|
-
tree.write('apps/api/src/assets/.gitkeep', '')
|
|
63
|
-
}
|
|
64
|
-
return ''
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
vi.spyOn(console, 'log').mockImplementation(() => { /* empty */ })
|
|
68
|
-
vi.spyOn(console, 'warn').mockImplementation(() => { /* empty */ })
|
|
69
|
-
vi.spyOn(console, 'error').mockImplementation(() => { /* empty */ })
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
afterEach(() => {
|
|
73
|
-
vi.restoreAllMocks()
|
|
74
|
-
mockedExecSync.mockClear()
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it('should run successfully', async () => {
|
|
78
|
-
await generator(tree, {})
|
|
79
|
-
|
|
80
|
-
expect(mockedExecSync).toHaveBeenCalledWith(
|
|
81
|
-
'nx g @nx/nest:application --name api --directory apps/api --no-interactive',
|
|
82
|
-
{
|
|
83
|
-
stdio: 'inherit',
|
|
84
|
-
cwd: tree.root,
|
|
85
|
-
}
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
const webpackConfig = tree.read('apps/api/webpack.config.js', 'utf-8')
|
|
89
|
-
expect(webpackConfig).not.toContain("assets: ['./src/assets']")
|
|
90
|
-
|
|
91
|
-
const packageJson = JSON.parse(tree.read('package.json', 'utf-8'))
|
|
92
|
-
expect(packageJson.scripts['dev:api']).toBe('nx serve api --skip-nx-cache')
|
|
93
|
-
|
|
94
|
-
expect(tree.exists('apps/api/src/app')).toBe(false)
|
|
95
|
-
expect(tree.exists('apps/api/src/assets')).toBe(false)
|
|
96
|
-
|
|
97
|
-
expect(tree.exists('apps/api/src/app.config.ts')).toBe(true)
|
|
98
|
-
expect(tree.exists('apps/api/src/app.module.ts')).toBe(true)
|
|
99
|
-
expect(tree.exists('apps/api/src/applogger.middleware.ts')).toBe(true)
|
|
100
|
-
expect(tree.exists('apps/api/src/main.ts')).toBe(true)
|
|
101
|
-
|
|
102
|
-
// Verify that the compiler options are removed from tsconfig.app.json
|
|
103
|
-
const tsConfig = JSON.parse(tree.read('apps/api/tsconfig.app.json', 'utf-8'))
|
|
104
|
-
expect(tsConfig.compilerOptions.module).toBeUndefined()
|
|
105
|
-
expect(tsConfig.compilerOptions.moduleResolution).toBeUndefined()
|
|
106
|
-
expect(tsConfig.compilerOptions.emitDecoratorMetadata).toBeUndefined()
|
|
107
|
-
expect(tsConfig.compilerOptions.experimentalDecorators).toBeUndefined()
|
|
108
|
-
// Verify that other compiler options are preserved
|
|
109
|
-
expect(tsConfig.compilerOptions.outDir).toBe('../../dist/out-tsc')
|
|
110
|
-
expect(tsConfig.compilerOptions.declaration).toBe(true)
|
|
111
|
-
})
|
|
112
|
-
})
|
package/src/app/generator.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { generateFiles, joinPathFragments, Tree, updateJson } from '@nx/devkit'
|
|
2
|
-
import { execSync } from 'child_process'
|
|
3
|
-
import * as path from 'path'
|
|
4
|
-
import { getNpmScope } from '@nx/js/src/utils/package-json/get-npm-scope'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Removes specific compiler options from tsconfig.app.json to use the settings from tsconfig.base.json
|
|
8
|
-
* @param tree The file system tree
|
|
9
|
-
*/
|
|
10
|
-
function updateAppTsConfig(tree: Tree): void {
|
|
11
|
-
const tsConfigPath = 'apps/api/tsconfig.app.json'
|
|
12
|
-
if (tree.exists(tsConfigPath)) {
|
|
13
|
-
updateJson(tree, tsConfigPath, (json) => {
|
|
14
|
-
if (json.compilerOptions) {
|
|
15
|
-
// Remove specific options to use the ones from tsconfig.base.json
|
|
16
|
-
delete json.compilerOptions.module
|
|
17
|
-
delete json.compilerOptions.moduleResolution
|
|
18
|
-
delete json.compilerOptions.emitDecoratorMetadata
|
|
19
|
-
delete json.compilerOptions.experimentalDecorators
|
|
20
|
-
}
|
|
21
|
-
return json
|
|
22
|
-
})
|
|
23
|
-
} else {
|
|
24
|
-
console.warn(`tsconfig.app.json not found at: ${tsConfigPath}`)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface Schema {
|
|
29
|
-
[key: string]: unknown
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default async function (tree: Tree, schema: Schema) {
|
|
33
|
-
try {
|
|
34
|
-
// Get the workspace root directory
|
|
35
|
-
const workspaceRoot = tree.root
|
|
36
|
-
|
|
37
|
-
// Create apps directory if it doesn't exist
|
|
38
|
-
if (!tree.exists('apps')) {
|
|
39
|
-
tree.write('apps/.gitkeep', '')
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Run the Nx generator command directly from the workspace root with proper workspace layout
|
|
43
|
-
execSync('nx g @nx/nest:application --name api --directory apps/api --no-interactive', {
|
|
44
|
-
stdio: 'inherit',
|
|
45
|
-
cwd: workspaceRoot,
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
// Wait a bit for files to be created
|
|
49
|
-
await new Promise((resolve) => setTimeout(resolve, 2000))
|
|
50
|
-
|
|
51
|
-
// Update tsconfig.app.json to remove specific compiler options
|
|
52
|
-
updateAppTsConfig(tree)
|
|
53
|
-
|
|
54
|
-
// Generate all files according to the template folder structure
|
|
55
|
-
generateFiles(
|
|
56
|
-
tree,
|
|
57
|
-
joinPathFragments(__dirname, './files'),
|
|
58
|
-
path.join('apps', 'api'),
|
|
59
|
-
{ ...schema, tmpl: '', npmScope: getNpmScope(tree) }
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
// Add dev:api script to package.json
|
|
63
|
-
updateJson(tree, 'package.json', (json) => {
|
|
64
|
-
if (!json.scripts) {
|
|
65
|
-
json.scripts = {}
|
|
66
|
-
}
|
|
67
|
-
json.scripts['dev:api'] = 'nx serve api --skip-nx-cache'
|
|
68
|
-
return json
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
// Update the build target in apps/api/project.json to use custom webpack command
|
|
72
|
-
const projectJsonPath = path.join('apps', 'api', 'project.json')
|
|
73
|
-
if (tree.exists(projectJsonPath)) {
|
|
74
|
-
updateJson(tree, projectJsonPath, (json) => {
|
|
75
|
-
json.targets = json.targets || {}
|
|
76
|
-
json.targets.build = {
|
|
77
|
-
executor: 'nx:run-commands',
|
|
78
|
-
options: {
|
|
79
|
-
command: 'NODE_ENV=production webpack-cli --config apps/api/webpack.config.js',
|
|
80
|
-
},
|
|
81
|
-
configurations: {
|
|
82
|
-
development: {
|
|
83
|
-
command: 'NODE_ENV=development webpack-cli --config apps/api/webpack.config.js',
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
}
|
|
87
|
-
return json
|
|
88
|
-
})
|
|
89
|
-
} else {
|
|
90
|
-
console.warn(`project.json not found at: ${projectJsonPath}`)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Optionally, delete the unused default app files if they exist
|
|
94
|
-
const targetPath = path.join('apps', 'api', 'src')
|
|
95
|
-
const filesToDelete = [path.join(targetPath, 'assets'), path.join(targetPath, 'app')]
|
|
96
|
-
filesToDelete.forEach((filePath) => {
|
|
97
|
-
if (tree.exists(filePath)) {
|
|
98
|
-
tree.delete(filePath)
|
|
99
|
-
}
|
|
100
|
-
})
|
|
101
|
-
} catch (error) {
|
|
102
|
-
console.error('Error generating API app:', error)
|
|
103
|
-
throw error
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { formatFiles, installPackagesTask, Tree } from '@nx/devkit'
|
|
2
|
-
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'
|
|
3
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
4
|
-
import { apiLibraryGenerator } from '@nestledjs/utils'
|
|
5
|
-
|
|
6
|
-
import generator from './generator'
|
|
7
|
-
|
|
8
|
-
vi.mock('@nestledjs/utils', async () => {
|
|
9
|
-
const actual = await vi.importActual('@nestledjs/utils')
|
|
10
|
-
return {
|
|
11
|
-
...actual,
|
|
12
|
-
apiLibraryGenerator: vi.fn(),
|
|
13
|
-
}
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
vi.mock('@nx/devkit', async () => {
|
|
17
|
-
const actual = await vi.importActual('@nx/devkit')
|
|
18
|
-
return {
|
|
19
|
-
...actual,
|
|
20
|
-
formatFiles: vi.fn(),
|
|
21
|
-
installPackagesTask: vi.fn(),
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
describe('config generator', () => {
|
|
26
|
-
let tree: Tree
|
|
27
|
-
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
tree = createTreeWithEmptyWorkspace()
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('should run successfully', async () => {
|
|
33
|
-
const callback = await generator(tree)
|
|
34
|
-
callback()
|
|
35
|
-
|
|
36
|
-
expect(apiLibraryGenerator).toHaveBeenCalledWith(tree, { name: 'config', overwrite: false }, expect.any(String))
|
|
37
|
-
expect(formatFiles).toHaveBeenCalledWith(tree)
|
|
38
|
-
expect(installPackagesTask).toHaveBeenCalledWith(tree)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('should pass overwrite flag to apiLibraryGenerator when overwrite is true', async () => {
|
|
42
|
-
const callback = await generator(tree, { overwrite: true })
|
|
43
|
-
callback()
|
|
44
|
-
|
|
45
|
-
expect(apiLibraryGenerator).toHaveBeenCalledWith(tree, { name: 'config', overwrite: true }, expect.any(String))
|
|
46
|
-
})
|
|
47
|
-
})
|
package/src/config/generator.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { formatFiles, installPackagesTask, joinPathFragments, Tree } from '@nx/devkit'
|
|
2
|
-
import { apiLibraryGenerator } from '@nestledjs/utils'
|
|
3
|
-
import { ApiConfigGeneratorSchema } from './schema'
|
|
4
|
-
|
|
5
|
-
export default async function generateLibraries(tree: Tree, options: ApiConfigGeneratorSchema = {}) {
|
|
6
|
-
const templateRootPath = joinPathFragments(__dirname, './files')
|
|
7
|
-
const overwrite = options.overwrite === true
|
|
8
|
-
|
|
9
|
-
await apiLibraryGenerator(tree, { name: 'config', overwrite }, templateRootPath)
|
|
10
|
-
|
|
11
|
-
await formatFiles(tree)
|
|
12
|
-
|
|
13
|
-
return () => {
|
|
14
|
-
installPackagesTask(tree)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { formatFiles, installPackagesTask, Tree } from '@nx/devkit'
|
|
2
|
-
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'
|
|
3
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
4
|
-
import { apiLibraryGenerator, installPlugins } from '@nestledjs/utils'
|
|
5
|
-
|
|
6
|
-
import generator from './generator'
|
|
7
|
-
|
|
8
|
-
vi.mock('@nestledjs/utils', async () => {
|
|
9
|
-
const actual = await vi.importActual('@nestledjs/utils')
|
|
10
|
-
return {
|
|
11
|
-
...actual,
|
|
12
|
-
apiLibraryGenerator: vi.fn(),
|
|
13
|
-
installPlugins: vi.fn(),
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
vi.mock('@nx/devkit', async () => {
|
|
18
|
-
const actual = await vi.importActual('@nx/devkit')
|
|
19
|
-
return {
|
|
20
|
-
...actual,
|
|
21
|
-
formatFiles: vi.fn(),
|
|
22
|
-
installPackagesTask: vi.fn(),
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
describe('core generator', () => {
|
|
27
|
-
let tree: Tree
|
|
28
|
-
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
tree = createTreeWithEmptyWorkspace()
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('should run successfully', async () => {
|
|
34
|
-
const callback = await generator(tree)
|
|
35
|
-
callback()
|
|
36
|
-
|
|
37
|
-
expect(installPlugins).toHaveBeenCalled()
|
|
38
|
-
expect(apiLibraryGenerator).toHaveBeenCalledWith(
|
|
39
|
-
tree,
|
|
40
|
-
{ name: 'core', overwrite: false },
|
|
41
|
-
expect.any(String),
|
|
42
|
-
'data-access',
|
|
43
|
-
)
|
|
44
|
-
expect(apiLibraryGenerator).toHaveBeenCalledWith(
|
|
45
|
-
tree,
|
|
46
|
-
{ name: 'core', overwrite: false },
|
|
47
|
-
expect.any(String),
|
|
48
|
-
'feature',
|
|
49
|
-
true,
|
|
50
|
-
)
|
|
51
|
-
expect(apiLibraryGenerator).toHaveBeenCalledWith(
|
|
52
|
-
tree,
|
|
53
|
-
{ name: 'core', overwrite: false },
|
|
54
|
-
expect.any(String),
|
|
55
|
-
'models',
|
|
56
|
-
)
|
|
57
|
-
expect(formatFiles).toHaveBeenCalledWith(tree)
|
|
58
|
-
expect(installPackagesTask).toHaveBeenCalledWith(tree)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('should pass overwrite flag to apiLibraryGenerator when overwrite is true', async () => {
|
|
62
|
-
const callback = await generator(tree, { overwrite: true })
|
|
63
|
-
callback()
|
|
64
|
-
|
|
65
|
-
expect(apiLibraryGenerator).toHaveBeenCalledWith(
|
|
66
|
-
tree,
|
|
67
|
-
{ name: 'core', overwrite: true },
|
|
68
|
-
expect.any(String),
|
|
69
|
-
'data-access',
|
|
70
|
-
)
|
|
71
|
-
expect(apiLibraryGenerator).toHaveBeenCalledWith(
|
|
72
|
-
tree,
|
|
73
|
-
{ name: 'core', overwrite: true },
|
|
74
|
-
expect.any(String),
|
|
75
|
-
'feature',
|
|
76
|
-
true,
|
|
77
|
-
)
|
|
78
|
-
expect(apiLibraryGenerator).toHaveBeenCalledWith(
|
|
79
|
-
tree,
|
|
80
|
-
{ name: 'core', overwrite: true },
|
|
81
|
-
expect.any(String),
|
|
82
|
-
'models',
|
|
83
|
-
)
|
|
84
|
-
})
|
|
85
|
-
})
|
package/src/core/generator.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { formatFiles, GeneratorCallback, installPackagesTask, joinPathFragments, Tree } from '@nx/devkit'
|
|
2
|
-
import { apiLibraryGenerator, installPlugins } from '@nestledjs/utils'
|
|
3
|
-
import { ApiCoreGeneratorSchema } from './schema'
|
|
4
|
-
|
|
5
|
-
export default async function generateLibraries(
|
|
6
|
-
tree: Tree,
|
|
7
|
-
options: ApiCoreGeneratorSchema = {},
|
|
8
|
-
): Promise<GeneratorCallback> {
|
|
9
|
-
const templateRootPath = joinPathFragments(__dirname, './files')
|
|
10
|
-
const overwrite = options.overwrite === true
|
|
11
|
-
|
|
12
|
-
const dependencies = {
|
|
13
|
-
'graphql-type-json': '^0.3.2',
|
|
14
|
-
'@nestjs/graphql': '^12.0.0',
|
|
15
|
-
'@nestjs/common': '^10.0.0',
|
|
16
|
-
'@nestjs/passport': '^10.0.0',
|
|
17
|
-
'@nestjs/axios': '^3.0.0',
|
|
18
|
-
'@prisma/client': '^6.9.0',
|
|
19
|
-
'@apollo/server': '^4.9.0',
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const devDependencies = {}
|
|
23
|
-
|
|
24
|
-
await installPlugins(tree, dependencies, devDependencies)
|
|
25
|
-
|
|
26
|
-
await apiLibraryGenerator(tree, { name: 'core', overwrite }, templateRootPath, 'data-access')
|
|
27
|
-
await apiLibraryGenerator(tree, { name: 'core', overwrite }, templateRootPath, 'feature', true)
|
|
28
|
-
await apiLibraryGenerator(tree, { name: 'core', overwrite }, templateRootPath, 'models')
|
|
29
|
-
|
|
30
|
-
await formatFiles(tree)
|
|
31
|
-
|
|
32
|
-
return () => {
|
|
33
|
-
installPackagesTask(tree)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { Tree } from '@nx/devkit'
|
|
2
|
-
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'
|
|
3
|
-
import { vi, describe, it, expect, beforeEach } from 'vitest'
|
|
4
|
-
import { customGeneratorLogic, CustomGeneratorDependencies } from './generator'
|
|
5
|
-
|
|
6
|
-
const dmmf = {
|
|
7
|
-
datamodel: {
|
|
8
|
-
models: [
|
|
9
|
-
{
|
|
10
|
-
name: 'User',
|
|
11
|
-
fields: [
|
|
12
|
-
{ name: 'id', type: 'Int', isId: true },
|
|
13
|
-
{ name: 'name', type: 'String' },
|
|
14
|
-
],
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
},
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
describe('custom-generator', () => {
|
|
21
|
-
let tree: Tree
|
|
22
|
-
let mockDependencies: CustomGeneratorDependencies
|
|
23
|
-
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
tree = createTreeWithEmptyWorkspace()
|
|
26
|
-
mockDependencies = {
|
|
27
|
-
formatFiles: vi.fn(),
|
|
28
|
-
installPackagesTask: vi.fn(),
|
|
29
|
-
getDMMF: vi.fn().mockResolvedValue(dmmf),
|
|
30
|
-
addToModules: vi.fn(),
|
|
31
|
-
apiLibraryGenerator: vi.fn(),
|
|
32
|
-
getPrismaSchemaPath: vi.fn(() => 'prisma/schema.prisma'),
|
|
33
|
-
readPrismaSchema: vi.fn(() => `model User {}`),
|
|
34
|
-
execSync: vi.fn(),
|
|
35
|
-
getNpmScope: vi.fn(() => 'test-scope'),
|
|
36
|
-
pluralize: vi.fn((name: string) => (name.endsWith('s') ? name : name + 's')) as any,
|
|
37
|
-
join: vi.fn((...args: string[]) => args.join('/')),
|
|
38
|
-
}
|
|
39
|
-
vi.clearAllMocks()
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it('should generate files correctly', async () => {
|
|
43
|
-
await customGeneratorLogic(tree, { name: 'custom' }, mockDependencies)
|
|
44
|
-
expect(mockDependencies.apiLibraryGenerator).toHaveBeenCalledWith(
|
|
45
|
-
tree,
|
|
46
|
-
{ name: 'custom' },
|
|
47
|
-
'',
|
|
48
|
-
undefined,
|
|
49
|
-
false,
|
|
50
|
-
)
|
|
51
|
-
// Check if files are generated in the new structure
|
|
52
|
-
expect(tree.exists('libs/api/custom/src/lib/default/user/user.service.ts')).toBe(true)
|
|
53
|
-
expect(tree.exists('libs/api/custom/src/lib/default/user/user.resolver.ts')).toBe(true)
|
|
54
|
-
expect(tree.exists('libs/api/custom/src/lib/default/user/user.module.ts')).toBe(true)
|
|
55
|
-
expect(tree.exists('libs/api/custom/src/index.ts')).toBe(true)
|
|
56
|
-
expect(tree.exists('libs/api/custom/src/lib/plugins')).toBe(true)
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('should be idempotent and not overwrite existing model folders', async () => {
|
|
60
|
-
// First run
|
|
61
|
-
await customGeneratorLogic(tree, { name: 'custom' }, mockDependencies)
|
|
62
|
-
// Write a marker file to simulate user customization
|
|
63
|
-
tree.write('libs/api/custom/src/lib/default/user/custom.txt', 'do not overwrite')
|
|
64
|
-
// Second run
|
|
65
|
-
await customGeneratorLogic(tree, { name: 'custom' }, mockDependencies)
|
|
66
|
-
// The marker file should still exist
|
|
67
|
-
expect(tree.read('libs/api/custom/src/lib/default/user/custom.txt', 'utf-8')).toBe('do not overwrite')
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
it('should not generate files if no models are found', async () => {
|
|
71
|
-
mockDependencies.getDMMF = vi.fn().mockResolvedValue({ datamodel: { models: [] } })
|
|
72
|
-
await customGeneratorLogic(tree, { name: 'custom' }, mockDependencies)
|
|
73
|
-
expect(mockDependencies.execSync).not.toHaveBeenCalled()
|
|
74
|
-
})
|
|
75
|
-
})
|