@ng-doc/add 22.1.0 → 22.2.0
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/LICENSE +21 -0
- package/package.json +2 -2
- package/schematics/ng-add/steps/add-layout.d.ts +3 -1
- package/schematics/ng-add/steps/add-layout.js +25 -12
- package/schematics/ng-add/steps/add-layout.js.map +1 -1
- package/schematics/ng-add/steps/add-ng-doc-app-config.d.ts +3 -1
- package/schematics/ng-add/steps/add-ng-doc-app-config.js +18 -10
- package/schematics/ng-add/steps/add-ng-doc-app-config.js.map +1 -1
- package/schematics/ng-add/utils/layout-template.d.ts +40 -0
- package/schematics/ng-add/utils/layout-template.js +51 -0
- package/schematics/ng-add/utils/layout-template.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Aleksandr Skoropad
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-doc/add",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.2.0",
|
|
4
4
|
"description": "Adds NgDoc to an Angular or Nx project with `ng add` and sets everything up for you.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@ng-doc/builder": "22.
|
|
33
|
+
"@ng-doc/builder": "22.2.0",
|
|
34
34
|
"@angular/cdk": ">=22.0.0 < 23.0.0",
|
|
35
35
|
"@angular-devkit/schematics": ">=22.0.0 < 23.0.0",
|
|
36
36
|
"ng-morph": "4.9.0"
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Rule } from '@angular-devkit/schematics';
|
|
2
2
|
import { Schema } from '../schema';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Puts the NgDoc layout in the root component's template when that template is Angular's
|
|
5
|
+
* `ng new` placeholder, empty or only a router outlet. A template that the application wrote,
|
|
6
|
+
* and an inline one, is never overwritten: the output says how to add the layout by hand.
|
|
5
7
|
* @param options - The `ng add` options.
|
|
6
8
|
*/
|
|
7
9
|
export declare function addLayout(options: Schema): Rule;
|
|
@@ -4,18 +4,21 @@ exports.addLayout = addLayout;
|
|
|
4
4
|
const workspace_1 = require("@schematics/angular/utility/workspace");
|
|
5
5
|
const ng_morph_1 = require("ng-morph");
|
|
6
6
|
const app_component_content_1 = require("../constants/app-component-content");
|
|
7
|
-
const get_app_template_path_1 = require("../utils/get-app-template-path");
|
|
8
7
|
const get_main_path_1 = require("../utils/get-main-path");
|
|
9
8
|
const get_project_1 = require("../utils/get-project");
|
|
9
|
+
const layout_template_1 = require("../utils/layout-template");
|
|
10
|
+
/** The guide for documentation under a route of an existing application. */
|
|
11
|
+
const LAZY_ROUTE_GUIDE = 'https://ng-doc.com/docs/customize/lazy-route';
|
|
10
12
|
/**
|
|
11
|
-
*
|
|
13
|
+
* Puts the NgDoc layout in the root component's template when that template is Angular's
|
|
14
|
+
* `ng new` placeholder, empty or only a router outlet. A template that the application wrote,
|
|
15
|
+
* and an inline one, is never overwritten: the output says how to add the layout by hand.
|
|
12
16
|
* @param options - The `ng add` options.
|
|
13
17
|
*/
|
|
14
18
|
function addLayout(options) {
|
|
15
19
|
return async (tree, context) => {
|
|
16
20
|
const logger = context.logger.createChild('add-layout');
|
|
17
21
|
context.logger.info(`[INFO]: Application layout`);
|
|
18
|
-
logger.info(`🔄 Replacing the content of the root component with NgDoc layout...`);
|
|
19
22
|
try {
|
|
20
23
|
const workspace = await (0, workspace_1.getWorkspace)(tree);
|
|
21
24
|
const project = (0, get_project_1.getProject)(options, workspace);
|
|
@@ -26,15 +29,25 @@ function addLayout(options) {
|
|
|
26
29
|
const mainPath = (0, get_main_path_1.getBootstrapPath)(tree, project);
|
|
27
30
|
// A project of its own: the one of an earlier step may hold edits that step did not save.
|
|
28
31
|
(0, ng_morph_1.setActiveProject)((0, ng_morph_1.createProject)(tree, '/', ['**/*.ts', '**/*.json']));
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
const template = (0, layout_template_1.getLayoutTemplate)(tree, mainPath);
|
|
33
|
+
switch (template.action) {
|
|
34
|
+
case 'replace':
|
|
35
|
+
logger.info(`🔄 Replacing the placeholder template of the root component with NgDoc layout...`);
|
|
36
|
+
tree.overwrite(template.path, app_component_content_1.APP_COMPONENT_CONTENT);
|
|
37
|
+
logger.info('✅ Done!');
|
|
38
|
+
break;
|
|
39
|
+
case 'has-layout':
|
|
40
|
+
logger.info('✅ The root component already renders the NgDoc layout.');
|
|
41
|
+
break;
|
|
42
|
+
case 'keep':
|
|
43
|
+
logger.warn([
|
|
44
|
+
`⚠️ The root component's template belongs to your application, so it was left as it is.`,
|
|
45
|
+
`Render the NgDoc layout where the documentation should be: in the root template, or in the component of a lazy documentation route (${LAZY_ROUTE_GUIDE}):`,
|
|
46
|
+
app_component_content_1.APP_COMPONENT_CONTENT,
|
|
47
|
+
].join('\n'));
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
logger.error('❌ Could not find the default main template file for the project. Please replace the content of the root component with NgDoc layout manually.');
|
|
38
51
|
}
|
|
39
52
|
}
|
|
40
53
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-layout.js","sourceRoot":"","sources":["../../../../../../libs/add/schematics/ng-add/steps/add-layout.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"add-layout.js","sourceRoot":"","sources":["../../../../../../libs/add/schematics/ng-add/steps/add-layout.ts"],"names":[],"mappings":";;AAoBA,8BAwDC;AA1ED,qEAAqE;AACrE,uCAA+E;AAE/E,8EAA2E;AAE3E,0DAA0D;AAC1D,sDAAkD;AAClD,8DAA6E;AAE7E,4EAA4E;AAC5E,MAAM,gBAAgB,GAAW,8CAA8C,CAAC;AAEhF;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,OAAe;IACvC,OAAO,KAAK,EAAE,IAAU,EAAE,OAAyB,EAAE,EAAE;QACrD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QAExD,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QAElD,IAAI,CAAC;YACH,MAAM,SAAS,GAAwB,MAAM,IAAA,wBAAY,EAAC,IAAI,CAAC,CAAC;YAChE,MAAM,OAAO,GAAkC,IAAA,wBAAU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|
|
|
1
1
|
import { Rule } from '@angular-devkit/schematics';
|
|
2
2
|
import { Schema } from '../schema';
|
|
3
3
|
/**
|
|
4
|
-
* Adds the NgDoc providers, the router and the layout components to the application.
|
|
4
|
+
* Adds the NgDoc providers, the router and the layout components to the application. The layout
|
|
5
|
+
* components are left out when `ng add` keeps the root template (see `addLayout`): the template
|
|
6
|
+
* would not use them.
|
|
5
7
|
*
|
|
6
8
|
* Calls that the application already has (`provideRouter`, `provideHttpClient`,
|
|
7
9
|
* `RouterModule.forRoot`) are extended rather than repeated, so the rule can run more than once.
|
|
@@ -11,8 +11,11 @@ const get_initializer_1 = require("../utils/get-initializer");
|
|
|
11
11
|
const get_main_path_1 = require("../utils/get-main-path");
|
|
12
12
|
const get_project_1 = require("../utils/get-project");
|
|
13
13
|
const get_root_module_1 = require("../utils/get-root-module");
|
|
14
|
+
const layout_template_1 = require("../utils/layout-template");
|
|
14
15
|
/**
|
|
15
|
-
* Adds the NgDoc providers, the router and the layout components to the application.
|
|
16
|
+
* Adds the NgDoc providers, the router and the layout components to the application. The layout
|
|
17
|
+
* components are left out when `ng add` keeps the root template (see `addLayout`): the template
|
|
18
|
+
* would not use them.
|
|
16
19
|
*
|
|
17
20
|
* Calls that the application already has (`provideRouter`, `provideHttpClient`,
|
|
18
21
|
* `RouterModule.forRoot`) are extended rather than repeated, so the rule can run more than once.
|
|
@@ -85,6 +88,7 @@ function arrayEdit(array, entries, logger) {
|
|
|
85
88
|
*/
|
|
86
89
|
function planEdits(tree, mainPath, logger) {
|
|
87
90
|
const bootstrapApplicationFn = (0, ng_morph_1.getBootstrapApplicationFn)(mainPath);
|
|
91
|
+
const keepsTemplate = (0, layout_template_1.getLayoutTemplate)(tree, mainPath).action === 'keep';
|
|
88
92
|
if (bootstrapApplicationFn) {
|
|
89
93
|
const appComponent = (0, get_app_component_1.getAppComponent)(tree, mainPath);
|
|
90
94
|
if (!appComponent) {
|
|
@@ -102,14 +106,18 @@ function planEdits(tree, mainPath, logger) {
|
|
|
102
106
|
}
|
|
103
107
|
return [
|
|
104
108
|
arrayEdit(providers, modules_1.STANDALONE_APP.providers, logger),
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
109
|
+
...(keepsTemplate
|
|
110
|
+
? []
|
|
111
|
+
: [
|
|
112
|
+
{
|
|
113
|
+
file: appComponent.getSourceFile(),
|
|
114
|
+
entries: modules_1.STANDALONE_APP.imports,
|
|
115
|
+
apply: () => modules_1.STANDALONE_APP.imports.map((component) => {
|
|
116
|
+
(0, ng_morph_1.addImportToComponent)(appComponent, component.initializer, { unique: true });
|
|
117
|
+
return 'unchanged';
|
|
118
|
+
}),
|
|
119
|
+
},
|
|
120
|
+
]),
|
|
113
121
|
];
|
|
114
122
|
}
|
|
115
123
|
if (!(0, get_root_module_1.getBootstrapModuleFn)(mainPath)) {
|
|
@@ -132,7 +140,7 @@ function planEdits(tree, mainPath, logger) {
|
|
|
132
140
|
const routerEdit = planRouterEdit(imports, router, logger);
|
|
133
141
|
return [
|
|
134
142
|
...(routerEdit ? [routerEdit] : []),
|
|
135
|
-
arrayEdit(imports, components, logger),
|
|
143
|
+
...(keepsTemplate ? [] : [arrayEdit(imports, components, logger)]),
|
|
136
144
|
arrayEdit(providers, modules_1.MODULE_APP.providers, logger),
|
|
137
145
|
];
|
|
138
146
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-ng-doc-app-config.js","sourceRoot":"","sources":["../../../../../../libs/add/schematics/ng-add/steps/add-ng-doc-app-config.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"add-ng-doc-app-config.js","sourceRoot":"","sources":["../../../../../../libs/add/schematics/ng-add/steps/add-ng-doc-app-config.ts"],"names":[],"mappings":";;AAoDA,8CA2DC;AA5GD,qEAAqE;AACrE,uCAiBkB;AAElB,kDAAgG;AAEhG,8DAQkC;AAClC,kEAA6D;AAC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SAAS,eAAe,CAAC,QAAgB,EAAE,OAAuB;IAChE,OAAO,CAAC,OAAO,CAAC,CAAC,YAA0B,EAAE,EAAE,CAC7C,IAAA,mCAAe,EAAC,QAAQ,EAAE,YAAY,CAAC,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,CAChE,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAAC,MAAwB;IACnD,MAAM,SAAS,GAAG,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IAElD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC,YAAY,EAAE,CAAC;IAE1E,OAAO,eAAI,CAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;AACzE,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CACvB,OAA6C;IAE7C,IAAI,eAAI,CAAC,yBAAyB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5C,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,CAAC;IAEnD,OAAO,UAAU,EAAE,iBAAiB,CAAC,qBAAU,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Tree } from '@angular-devkit/schematics';
|
|
2
|
+
/**
|
|
3
|
+
* What `ng add` does with the root component's template:
|
|
4
|
+
* - `replace`: the template is Angular's `ng new` placeholder, empty or only a router outlet, so
|
|
5
|
+
* it is replaced with the NgDoc layout;
|
|
6
|
+
* - `has-layout`: it already renders `ng-doc-root`;
|
|
7
|
+
* - `keep`: it is the application's own (or inline), so it is left as it is and the layout is
|
|
8
|
+
* added by hand, for example in the component of a lazy documentation route;
|
|
9
|
+
* - `missing`: the root component or its template file can't be found.
|
|
10
|
+
*/
|
|
11
|
+
export type LayoutTemplateAction = 'replace' | 'has-layout' | 'keep' | 'missing';
|
|
12
|
+
/** A template that `ng add` replaces with the layout. */
|
|
13
|
+
interface ReplacedLayoutTemplate {
|
|
14
|
+
action: 'replace';
|
|
15
|
+
/** The template file. */
|
|
16
|
+
path: string;
|
|
17
|
+
}
|
|
18
|
+
/** A template that `ng add` leaves as it is, or that it can't find. */
|
|
19
|
+
interface KeptLayoutTemplate {
|
|
20
|
+
action: Exclude<LayoutTemplateAction, 'replace'>;
|
|
21
|
+
/** The template file, unless the template is inline or missing. */
|
|
22
|
+
path?: string;
|
|
23
|
+
}
|
|
24
|
+
/** The root component's template and what `ng add` does with it. */
|
|
25
|
+
export type LayoutTemplate = ReplacedLayoutTemplate | KeptLayoutTemplate;
|
|
26
|
+
/**
|
|
27
|
+
* Decides what `ng add` does with the root component's template. It never replaces a template
|
|
28
|
+
* that the application wrote: only Angular's `ng new` placeholder, an empty template or one that
|
|
29
|
+
* holds only a router outlet. An active ng-morph project must hold the application's sources.
|
|
30
|
+
* @param tree - The workspace tree.
|
|
31
|
+
* @param mainPath - Path of the application's main file.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getLayoutTemplate(tree: Tree, mainPath: string | undefined): LayoutTemplate;
|
|
34
|
+
/**
|
|
35
|
+
* Whether a template holds nothing the application wrote: Angular's `ng new` placeholder, nothing
|
|
36
|
+
* at all, or only a router outlet (which the NgDoc layout keeps).
|
|
37
|
+
* @param content - The template.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isPlaceholderTemplate(content: string): boolean;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLayoutTemplate = getLayoutTemplate;
|
|
4
|
+
exports.isPlaceholderTemplate = isPlaceholderTemplate;
|
|
5
|
+
const ng_morph_1 = require("ng-morph");
|
|
6
|
+
const get_app_component_1 = require("./get-app-component");
|
|
7
|
+
const get_app_template_path_1 = require("./get-app-template-path");
|
|
8
|
+
const get_initializer_1 = require("./get-initializer");
|
|
9
|
+
/** A line of the comment that `ng new` puts at the top of the placeholder template. */
|
|
10
|
+
const NG_NEW_PLACEHOLDER = 'is only a placeholder';
|
|
11
|
+
/**
|
|
12
|
+
* Decides what `ng add` does with the root component's template. It never replaces a template
|
|
13
|
+
* that the application wrote: only Angular's `ng new` placeholder, an empty template or one that
|
|
14
|
+
* holds only a router outlet. An active ng-morph project must hold the application's sources.
|
|
15
|
+
* @param tree - The workspace tree.
|
|
16
|
+
* @param mainPath - Path of the application's main file.
|
|
17
|
+
*/
|
|
18
|
+
function getLayoutTemplate(tree, mainPath) {
|
|
19
|
+
const appComponent = mainPath
|
|
20
|
+
? (0, get_app_component_1.getAppComponent)(tree, mainPath)
|
|
21
|
+
: undefined;
|
|
22
|
+
if (!mainPath || !ng_morph_1.Node.isClassDeclaration(appComponent)) {
|
|
23
|
+
return { action: 'missing' };
|
|
24
|
+
}
|
|
25
|
+
const inline = (0, get_initializer_1.getInitializer)(appComponent, 'Component', 'template');
|
|
26
|
+
if (inline) {
|
|
27
|
+
return { action: inline.getText().includes('<ng-doc-root') ? 'has-layout' : 'keep' };
|
|
28
|
+
}
|
|
29
|
+
const path = (0, get_app_template_path_1.getAppTemplatePath)(tree, mainPath);
|
|
30
|
+
const content = path ? tree.read(path)?.toString('utf-8') : undefined;
|
|
31
|
+
if (!path || content === undefined) {
|
|
32
|
+
return { action: 'missing' };
|
|
33
|
+
}
|
|
34
|
+
if (content.includes('<ng-doc-root')) {
|
|
35
|
+
return { action: 'has-layout', path };
|
|
36
|
+
}
|
|
37
|
+
return { action: isPlaceholderTemplate(content) ? 'replace' : 'keep', path };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Whether a template holds nothing the application wrote: Angular's `ng new` placeholder, nothing
|
|
41
|
+
* at all, or only a router outlet (which the NgDoc layout keeps).
|
|
42
|
+
* @param content - The template.
|
|
43
|
+
*/
|
|
44
|
+
function isPlaceholderTemplate(content) {
|
|
45
|
+
if (content.includes(NG_NEW_PLACEHOLDER)) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
const markup = content.replace(/<!--[\s\S]*?-->/g, '').replace(/\s+/g, '');
|
|
49
|
+
return markup === '' || /^<router-outlet(\/>|><\/router-outlet>)$/.test(markup);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=layout-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout-template.js","sourceRoot":"","sources":["../../../../../../libs/add/schematics/ng-add/utils/layout-template.ts"],"names":[],"mappings":";;AA6CA,8CA2BC;AAOD,sDAQC;AAtFD,uCAA8D;AAE9D,2DAAsD;AACtD,mEAA6D;AAC7D,uDAAmD;AA8BnD,uFAAuF;AACvF,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AAEnD;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAAC,IAAU,EAAE,QAA4B;IACxE,MAAM,YAAY,GAAiC,QAAQ;QACzD,CAAC,CAAC,IAAA,mCAAe,EAAC,IAAI,EAAE,QAAQ,CAAC;QACjC,CAAC,CAAC,SAAS,CAAC;IAEd,IAAI,CAAC,QAAQ,IAAI,CAAC,eAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,CAAC;QACxD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC/B,CAAC;IAED,MAAM,MAAM,GAA2B,IAAA,gCAAc,EAAC,YAAY,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;IAE7F,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC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