Skip to content

Commit

Permalink
fix: ng add cms templates (#1733)
Browse files Browse the repository at this point in the history
## Proposed change

When selecting the CMS preset, the `tsconfig.cms.json`, `cms.json` and
`placeholders.metadata.json` files should be added to the application.
  • Loading branch information
vscaiceanu-1a committed Apr 30, 2024
2 parents cf2f47b + df91f9b commit a717a5c
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 53 deletions.

This file was deleted.

4 changes: 1 addition & 3 deletions packages/@o3r/application/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import { chain } from '@angular-devkit/schematics';
import { addRootImport } from '@schematics/angular/utility';
import * as path from 'node:path';
import { generateCmsConfigFile } from './helpers/cms-registration';
import { registerDevtools } from './helpers/devtools-registration';
import type { NgAddSchematicsSchema } from './schema';

Expand Down Expand Up @@ -98,8 +97,7 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
ngAddToRun: depsInfo.o3rPeerDeps
}),
addAngularAnimationPreferences,
registerDevtoolRule,
generateCmsConfigFile(options)
registerDevtoolRule
])(tree, context);
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@o3r/extractors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"ng": "yarn nx",
"build": "yarn nx build extractors",
"postbuild": "patch-package-json-main",
"prepare:build:builders": "yarn cpy 'schematics/**/*.json' dist/schematics && yarn cpy '{collection,migration}.json' dist",
"prepare:build:builders": "yarn cpy 'schematics/**/*.json' 'schematics/**/templates/**' dist/schematics && yarn cpy '{collection,migration}.json' dist",
"build:builders": "tsc -b tsconfig.builders.json --pretty && yarn generate-cjs-manifest",
"prepare:publish": "prepare-publish ./dist"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/@o3r/extractors/schematics/cms-adapter/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { strings } from '@angular-devkit/core';
import { apply, chain, MergeStrategy, mergeWith, move, noop, Rule, SchematicContext, template, Tree, url } from '@angular-devkit/schematics';
import { apply, chain, MergeStrategy, mergeWith, move, noop, renameTemplateFiles, Rule, SchematicContext, template, Tree, url } from '@angular-devkit/schematics';
import { getTemplateFolder, getWorkspaceConfig, ignorePatterns } from '@o3r/schematics';
import * as path from 'node:path';

Expand Down Expand Up @@ -37,7 +37,8 @@ export function updateCmsAdapter(options: { projectName?: string | undefined },
buildTsConfig: buildTsConfig.startsWith('.') ? buildTsConfig : `./${buildTsConfig}`,
sourceRoot: workspaceProject?.sourceRoot || 'src'
}),
move(projectRoot)
move(projectRoot),
renameTemplateFiles()
]);

const rule = mergeWith(templateSource, MergeStrategy.AllowOverwriteConflict);
Expand Down
4 changes: 2 additions & 2 deletions packages/@o3r/extractors/schematics/ng-add/schema.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "ngAddSchematicsSchema",
"title": "Add Otter extractors ",
"description": "ngAdd Otter extractors ",
"title": "Add Otter extractors",
"description": "ngAdd Otter extractors",
"properties": {
"projectName": {
"type": "string",
Expand Down
23 changes: 0 additions & 23 deletions packages/@o3r/localization/schematics/localization-base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,6 @@ export function updateLocalization(options: { projectName?: string | null | unde
}
};

if (!tree.exists(pathTsconfigCms)) {
const tsconfigCms = {
extends: `./${tree.exists(path.posix.join(projectRoot, 'tsconfig.build.json')) ? 'tsconfig.build' : 'tsconfig.json'}`,
include: [
'src/**/*.component.ts',
'src/**/*.config.ts',
'src/**/*.module.ts'
]
};
tree.create(pathTsconfigCms, JSON.stringify(tsconfigCms, null, 2));
} else {
const localizationSourceRegExps = ['src/**/*.component.ts'];
const tsconfigCms = tree.readJson(pathTsconfigCms) as Record<string, any>;
if (!Array.isArray(tsconfigCms.include) || !localizationSourceRegExps.some((r) => tsconfigCms.include.includes(r))) {
tsconfigCms.include ||= [];
tsconfigCms.include.push(
...localizationSourceRegExps
.filter((r) => !tsconfigCms.include.includes(r))
);
tree.overwrite(pathTsconfigCms, JSON.stringify(tsconfigCms, null, 2));
}
}

if (workspaceProject.architect.build) {
const alreadyExistingBuildOption =
workspaceProject.architect.build.options?.assets?.map((a: { glob: string; input: string; output: string }) => a.output).find((output: string) => output === '/localizations');
Expand Down

0 comments on commit a717a5c

Please sign in to comment.