Skip to content

Commit 036e9ac

Browse files
committed
fix: fix ng-add schematics for standalone app
1 parent 86aae20 commit 036e9ac

File tree

1 file changed

+55
-27
lines changed
  • projects/ngneat/cmdk/schematics/ng-add

1 file changed

+55
-27
lines changed

projects/ngneat/cmdk/schematics/ng-add/index.ts

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -118,43 +118,71 @@ const injectImports =
118118
} else {
119119
context.logger.log(
120120
'info',
121-
'ℹ️ Skipped import for stand-alone application. Need to be imported manually.'
121+
'ℹ️ Skipped writing import statement for standalone app. Need to be imported manually.'
122122
);
123123
}
124124

125125
return host;
126126
}
127127
};
128128

129-
const addModuleToImports = (options: Schema): Rule => (host: Tree, context: SchematicContext) => {
130-
if (!options.skipImport) {
131-
const workspace = getWorkspace(host) as any;
132-
const project = getProjectFromWorkspace(
133-
workspace,
134-
options.project ? options.project : Object.keys(workspace.projects)[0]
135-
);
129+
const addModuleToImports =
130+
(options: Schema): Rule =>
131+
(host: Tree, context: SchematicContext) => {
132+
if (!options.skipImport) {
133+
const workspace = getWorkspace(host) as any;
134+
const project = getProjectFromWorkspace(
135+
workspace,
136+
options.project ? options.project : Object.keys(workspace.projects)[0]
137+
);
136138

137-
if (!project || project.projectType !== 'application') {
138-
throw new SchematicsException(`A client project type of "application" is required.`);
139-
}
140-
if (!project.architect) {
141-
throw new SchematicsException(`Architect options not present for project.`);
142-
}
143-
if (!project.architect.build) {
144-
throw new SchematicsException(`Architect:Build options not present for project.`);
145-
}
139+
if (!project || project.projectType !== 'application') {
140+
throw new SchematicsException(
141+
`A client project type of "application" is required.`
142+
);
143+
}
144+
if (!project.architect) {
145+
throw new SchematicsException(
146+
`Architect options not present for project.`
147+
);
148+
}
149+
if (!project.architect.build) {
150+
throw new SchematicsException(
151+
`Architect:Build options not present for project.`
152+
);
153+
}
146154

147-
const modulePath = getAppModulePath(host, project.architect.build.options.main);
155+
if (!isStandaloneApp(host, project.architect.build.options.main)) {
156+
const modulePath = getAppModulePath(
157+
host,
158+
project.architect.build.options.main
159+
);
148160

149-
importModuleSet.forEach((item) => {
150-
if (hasNgModuleImport(host, modulePath, item.moduleName)) {
151-
context.logger.warn(`Could not set up "${item.moduleName}" in "imports[]" because it's already imported.`);
161+
importModuleSet.forEach((item) => {
162+
if (hasNgModuleImport(host, modulePath, item.moduleName)) {
163+
context.logger.warn(
164+
`Could not set up "${item.moduleName}" in "imports[]" because it's already imported.`
165+
);
166+
} else {
167+
addModuleImportToRootModule(
168+
host,
169+
item.importModuleStatement,
170+
null as any,
171+
project
172+
);
173+
context.logger.log(
174+
'info',
175+
'✅ Imported "' + item.moduleName + '" in imports'
176+
);
177+
}
178+
});
152179
} else {
153-
addModuleImportToRootModule(host, item.importModuleStatement, null as any, project);
154-
context.logger.log('info', '✅ Imported "' + item.moduleName + '" in imports');
180+
context.logger.log(
181+
'info',
182+
'ℹ️ Skipped import for stand-alone application. Need to be imported manually.'
183+
);
155184
}
156-
});
157-
}
185+
}
158186

159-
return host;
160-
};
187+
return host;
188+
};

0 commit comments

Comments
 (0)