Skip to content

Commit

Permalink
feat(serverless): update generators to use new features
Browse files Browse the repository at this point in the history
  • Loading branch information
Bielik20 committed Jul 3, 2024
1 parent 697dbf9 commit c1d6ccc
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ describe('serverless generator', () => {
externalDependencies: 'none',
target: 'node',
compiler: 'tsc',
isolatedConfig: true,
webpackConfig: 'apps/sample/webpack.config.js',
},
configurations: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export function getBuildBaseConfig(options: NormalizedOptions): TargetConfigurat
externalDependencies: 'none',
target: 'node',
compiler: 'tsc',
isolatedConfig: true,
webpackConfig: joinPathFragments(options.projectRoot, 'webpack.config.js'),
},
configurations: {
Expand Down
23 changes: 3 additions & 20 deletions packages/nx-serverless/src/generators/init/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default async function serverlessInitGenerator(host: Tree, options: InitG
const tasks: GeneratorCallback[] = [];

updateGitignore(host);
addCacheableOperation(host);
setupTargetDefaults(host);

if (!options.unitTestRunner || options.unitTestRunner === 'jest') {
Expand Down Expand Up @@ -66,25 +65,6 @@ function updateGitignore(host: Tree) {
}
}

function addCacheableOperation(tree: Tree) {
const nxJson = readNxJson(tree);
if (!nxJson.tasksRunnerOptions || !nxJson.tasksRunnerOptions.default) {
return;
}

nxJson.tasksRunnerOptions.default.options ??= {};
nxJson.tasksRunnerOptions.default.options.cacheableOperations ??= [];

if (!nxJson.tasksRunnerOptions.default.options.cacheableOperations.includes('package')) {
nxJson.tasksRunnerOptions.default.options.cacheableOperations.push('package');
}
if (!nxJson.tasksRunnerOptions.default.options.cacheableOperations.includes('deploy')) {
nxJson.tasksRunnerOptions.default.options.cacheableOperations.push('deploy');
}

updateNxJson(tree, nxJson);
}

function setupTargetDefaults(tree: Tree) {
const nxJson = readNxJson(tree);

Expand All @@ -103,15 +83,18 @@ function setupTargetDefaults(tree: Tree) {
nxJson.targetDefaults ??= {};
nxJson.targetDefaults.deploy ??= {};
nxJson.targetDefaults.deploy.inputs ??= ['production', '^production', 'stage'];
nxJson.targetDefaults.deploy.cache ??= true;

nxJson.targetDefaults.package ??= {};
nxJson.targetDefaults.package.inputs ??= ['production', '^production', 'stage'];
nxJson.targetDefaults.package.cache ??= true;

nxJson.targetDefaults.build ??= {};
nxJson.targetDefaults.build.inputs ??= ['production', '^production', 'no-sls', '^no-sls'];
if (!nxJson.targetDefaults.build.inputs.includes('no-sls')) {
nxJson.targetDefaults.build.inputs.push('no-sls', '^no-sls');
}
nxJson.targetDefaults.build.cache ??= true;

updateNxJson(tree, nxJson);
}

0 comments on commit c1d6ccc

Please sign in to comment.