Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Commit

Permalink
refactor(generators): use offsetFromRoot in templated files
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumeduboc committed Mar 21, 2022
1 parent 635969d commit 8f8bad7
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 21 deletions.
8 changes: 6 additions & 2 deletions tools/generators/helpers/packageGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface PackageGeneratorParams {
sourcePath: string;
packageJson: (options: NormalizedSchema) => PackageJson;
packageProjectJson: (root: string) => ProjectConfiguration;
packageTsConfig: TsConfig;
packageTsConfig: (options: NormalizedSchema) => TsConfig;
}

export const packageGenerator = ({
Expand All @@ -35,7 +35,11 @@ export const packageGenerator = ({
packageJson(options),
);

writeJson(tree, join(options.packageRoot, `tsconfig.json`), packageTsConfig);
writeJson(
tree,
join(options.packageRoot, `tsconfig.json`),
packageTsConfig(options),
);

const projectConfiguration = packageProjectJson(options.packageRoot);
addProjectConfiguration(tree, options.importPath, projectConfiguration);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const generateImportOrderRule = require('../../commonConfiguration/generateImportOrderRule');
const generateImportOrderRule = require('<%= offsetFromRoot %>/commonConfiguration/generateImportOrderRule');

module.exports = {
rules: generateImportOrderRule(__dirname),
Expand Down
2 changes: 1 addition & 1 deletion tools/generators/library/files/.lintstagedrc.js__tmpl__
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const baseConfig = require('../../.lintstagedrc.js');
const baseConfig = require('<%= offsetFromRoot %>/.lintstagedrc.js');
module.exports = baseConfig;
3 changes: 0 additions & 3 deletions tools/generators/library/files/babel.config.js

This file was deleted.

3 changes: 3 additions & 0 deletions tools/generators/library/files/babel.config.js__tmpl__
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const commonBabelConfig = require('<%= offsetFromRoot %>/commonConfiguration/babel.config');

module.exports = commonBabelConfig();
10 changes: 6 additions & 4 deletions tools/generators/library/typed-json-config/tsconfig.json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { TsConfig } from '../../types';
import { joinPathFragments } from '@nrwl/devkit';

export const packageTsConfig: TsConfig = {
extends: '../../tsconfig.json',
import { NormalizedSchema, TsConfig } from '../../types';

export const packageTsConfig = (options: NormalizedSchema): TsConfig => ({
extends: joinPathFragments(options.offsetFromRoot, 'tsconfig.json'),
compilerOptions: {
baseUrl: 'src',
composite: true,
Expand All @@ -12,4 +14,4 @@ export const packageTsConfig: TsConfig = {
},
exclude: ['./dist'],
include: ['./**/*.ts'],
};
});
2 changes: 1 addition & 1 deletion tools/generators/service/files/.eslintrc.js__tmpl__
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const generateImportOrderRule = require('../../commonConfiguration/generateImportOrderRule');
const generateImportOrderRule = require('<%= offsetFromRoot %>/commonConfiguration/generateImportOrderRule');

module.exports = {
rules: generateImportOrderRule(__dirname),
Expand Down
2 changes: 1 addition & 1 deletion tools/generators/service/files/.lintstagedrc.js__tmpl__
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const baseConfig = require('../../.lintstagedrc.js');
const baseConfig = require('<%= offsetFromRoot %>/.lintstagedrc.js');
module.exports = baseConfig;
38 changes: 30 additions & 8 deletions tools/generators/service/typed-json-config/tsconfig.json.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
import { TsConfig } from '../../types';
import { joinPathFragments } from '@nrwl/devkit';

export const packageTsConfig: TsConfig = {
extends: '../../tsconfig.json',
import { NormalizedSchema, TsConfig } from '../../types';

export const packageTsConfig = (options: NormalizedSchema): TsConfig => ({
extends: joinPathFragments(options.offsetFromRoot, 'tsconfig.json'),
compilerOptions: {
preserveSymlinks: true,
baseUrl: '.',
esModuleInterop: true,
},
references: [
{ path: '../../contracts/core-contracts/tsconfig.build.json' },
{ path: '../../packages/configuration/tsconfig.build.json' },
{ path: '../../packages/serverless-configuration/tsconfig.build.json' },
{ path: '../../packages/serverless-helpers/tsconfig.build.json' },
{
path: joinPathFragments(
options.offsetFromRoot,
'contracts/core-contracts/tsconfig.build.json',
),
},
{
path: joinPathFragments(
options.offsetFromRoot,
'packages/configuration/tsconfig.build.json',
),
},
{
path: joinPathFragments(
options.offsetFromRoot,
'packages/serverless-configuration/tsconfig.build.json',
),
},
{
path: joinPathFragments(
options.offsetFromRoot,
'packages/serverless-helpers/tsconfig.build.json',
),
},
],
include: ['./**/*.ts'],
'ts-node': {
files: true,
},
};
});

0 comments on commit 8f8bad7

Please sign in to comment.