@tmdjr/ngx-editor-js2 20.0.2 → 20.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmdjr/ngx-editor-js2",
3
- "version": "20.0.2",
3
+ "version": "20.0.4",
4
4
  "schematics": "./schematics/collection.json",
5
5
  "peerDependencies": {
6
6
  "@angular/animations": "^20.0.4",
@@ -1,2 +1,2 @@
1
1
  import { Rule } from '@angular-devkit/schematics';
2
- export declare function ngAdd(): Rule;
2
+ export declare function ngAdd(options: any): Rule;
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ngAdd = ngAdd;
13
- const enquirer_1 = require("enquirer");
14
13
  const tasks_1 = require("@angular-devkit/schematics/tasks");
15
14
  const dependencies_1 = require("@schematics/angular/utility/dependencies");
16
15
  const optionalBlocks = {
@@ -51,18 +50,10 @@ const optionalBlocks = {
51
50
  peers: [],
52
51
  },
53
52
  };
54
- function ngAdd() {
53
+ function ngAdd(options) {
55
54
  return (tree, context) => __awaiter(this, void 0, void 0, function* () {
56
- const response = yield (0, enquirer_1.prompt)({
57
- type: 'multiselect',
58
- name: 'blocks',
59
- message: 'Select optional Ngx-Editor-JS2 blocks to install:',
60
- choices: Object.keys(optionalBlocks).map((block) => ({
61
- name: block,
62
- message: block,
63
- })),
64
- });
65
- response.blocks.forEach((block) => {
55
+ const blocks = options.blocks || [];
56
+ blocks.forEach((block) => {
66
57
  const { package: pkg, peers } = optionalBlocks[block];
67
58
  (0, dependencies_1.addPackageJsonDependency)(tree, {
68
59
  type: dependencies_1.NodeDependencyType.Default,
@@ -81,42 +72,16 @@ function ngAdd() {
81
72
  });
82
73
  });
83
74
  context.addTask(new tasks_1.NodePackageInstallTask());
84
- const sourceRoot = yield getSourceRoot(tree, context);
85
- updateStylesScss(tree, response.blocks, context, sourceRoot);
86
- updateAppConfig(tree, response.blocks, context, sourceRoot);
87
- addCodeMirrorSetup(tree, response.blocks, context, sourceRoot);
75
+ const sourceRoot = options.project
76
+ ? getProjectSourceRoot(tree, options.project)
77
+ : 'src';
78
+ updateStylesScss(tree, blocks, context, sourceRoot);
79
+ updateAppConfig(tree, blocks, context, sourceRoot);
80
+ addCodeMirrorSetup(tree, blocks, context, sourceRoot);
88
81
  context.logger.info('✅ Installation setup complete.');
89
82
  return tree;
90
83
  });
91
84
  }
92
- function getSourceRoot(tree, context) {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- const buffer = tree.read('/angular.json');
95
- if (!buffer) {
96
- context.logger.error('❌ angular.json not found.');
97
- throw new Error('angular.json not found... get good');
98
- }
99
- const angularJson = JSON.parse(buffer.toString());
100
- // We need to get every project in the workspace
101
- const projects = Object.keys(angularJson.projects);
102
- // We will prompt the user to select a project
103
- const response = yield (0, enquirer_1.prompt)({
104
- type: 'select',
105
- name: 'project',
106
- message: 'Select the Angular project to update:',
107
- choices: projects.map((project) => ({
108
- name: project,
109
- message: project,
110
- })),
111
- });
112
- const project = response.project;
113
- if (!project || !angularJson.projects[project]) {
114
- context.logger.error(`❌ Project ${project} not found in angular.json.`);
115
- throw new Error(`Project ${project} not found in angular.json`);
116
- }
117
- return angularJson.projects[project].sourceRoot;
118
- });
119
- }
120
85
  function updateStylesScss(tree, blocks, context, sourceRoot) {
121
86
  const stylePath = `${sourceRoot}/styles.scss`;
122
87
  if (!tree.exists(stylePath)) {
@@ -177,7 +142,7 @@ function updateAppConfig(tree, blocks, context, sourceRoot) {
177
142
  context.logger.info('🚀 app.config.ts updated successfully.');
178
143
  }
179
144
  function addCodeMirrorSetup(tree, selectedBlocks, context, sourceRoot) {
180
- const needsCodeMirror = selectedBlocks.some((block) => ['ngx-editor-js2-codemirror', 'ngx-editor-js2-mermaidjs'].includes(block));
145
+ const needsCodeMirror = selectedBlocks.some((block) => ['codemirror', 'mermaidjs'].includes(block));
181
146
  if (!needsCodeMirror) {
182
147
  context.logger.info('CodeMirror dependencies not selected; skipping setup.');
183
148
  return;
@@ -217,53 +182,13 @@ import 'codemirror/mode/xml/xml';
217
182
  context.logger.warn(`styles.scss not found at path: ${stylesPath}`);
218
183
  }
219
184
  }
220
- // async function updateAngularJson(
221
- // tree: Tree,
222
- // blocks: string[],
223
- // context: SchematicContext
224
- // ): Promise<string> {
225
- // const angularJsonPath = '/angular.json';
226
- // const buffer = tree.read(angularJsonPath);
227
- // if (!buffer) {
228
- // context.logger.error('❌ angular.json not found.');
229
- // throw new Error('angular.json not found... get good');
230
- // }
231
- // const angularJson = JSON.parse(buffer.toString());
232
- // // const project = angularJson.defaultProject;
233
- // // We need to get every project in the workspace
234
- // const projects = Object.keys(angularJson.projects);
235
- // // We will prompt the user to select a project
236
- // const response = await prompt<{ project: string }>({
237
- // type: 'select',
238
- // name: 'project',
239
- // message: 'Select the Angular project to update:',
240
- // choices: projects.map((project) => ({
241
- // name: project,
242
- // message: project,
243
- // })),
244
- // });
245
- // const project = response.project;
246
- // if (!project || !angularJson.projects[project]) {
247
- // context.logger.error(`❌ Project ${project} not found in angular.json.`);
248
- // throw new Error(`Project ${project} not found in angular.json`);
249
- // }
250
- // const includePaths =
251
- // angularJson.projects[project].architect.build.options
252
- // .stylePreprocessorOptions?.includePaths || [];
253
- // includePaths.push('dist/ngx-editor-js2');
254
- // blocks.forEach((block) => {
255
- // const stylePath = optionalBlocks[block].stylePath;
256
- // if (!includePaths.includes(stylePath)) {
257
- // includePaths.push(stylePath);
258
- // }
259
- // });
260
- // angularJson.projects[
261
- // project
262
- // ].architect.build.options.stylePreprocessorOptions = { includePaths };
263
- // tree.overwrite(angularJsonPath, JSON.stringify(angularJson, null, 2));
264
- // context.logger.info('🔧 angular.json updated successfully.');
265
- // return (
266
- // angularJson.projects[project].sourceRoot ||
267
- // angularJson.projects[project].root
268
- // );
269
- // }
185
+ function getProjectSourceRoot(tree, projectName) {
186
+ const buffer = tree.read('/angular.json');
187
+ if (!buffer)
188
+ throw new Error('angular.json not found');
189
+ const workspace = JSON.parse(buffer.toString());
190
+ const project = workspace.projects[projectName];
191
+ if (!project)
192
+ throw new Error(`Project ${projectName} not found`);
193
+ return project.sourceRoot || 'src';
194
+ }
@@ -1,5 +1,4 @@
1
1
  import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
2
- import { prompt } from 'enquirer';
3
2
  import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
4
3
  import {
5
4
  addPackageJsonDependency,
@@ -48,19 +47,11 @@ const optionalBlocks: Record<
48
47
  },
49
48
  };
50
49
 
51
- export function ngAdd(): Rule {
50
+ export function ngAdd(options: any): Rule {
52
51
  return async (tree: Tree, context: SchematicContext) => {
53
- const response = await prompt<{ blocks: string[] }>({
54
- type: 'multiselect',
55
- name: 'blocks',
56
- message: 'Select optional Ngx-Editor-JS2 blocks to install:',
57
- choices: Object.keys(optionalBlocks).map((block) => ({
58
- name: block,
59
- message: block,
60
- })),
61
- });
52
+ const blocks: string[] = options.blocks || [];
62
53
 
63
- response.blocks.forEach((block) => {
54
+ blocks.forEach((block) => {
64
55
  const { package: pkg, peers } = optionalBlocks[block];
65
56
  addPackageJsonDependency(tree, {
66
57
  type: NodeDependencyType.Default,
@@ -81,13 +72,13 @@ export function ngAdd(): Rule {
81
72
 
82
73
  context.addTask(new NodePackageInstallTask());
83
74
 
84
- const sourceRoot = await getSourceRoot(tree, context);
85
-
86
- updateStylesScss(tree, response.blocks, context, sourceRoot);
75
+ const sourceRoot = options.project
76
+ ? getProjectSourceRoot(tree, options.project)
77
+ : 'src';
87
78
 
88
- updateAppConfig(tree, response.blocks, context, sourceRoot);
89
-
90
- addCodeMirrorSetup(tree, response.blocks, context, sourceRoot);
79
+ updateStylesScss(tree, blocks, context, sourceRoot);
80
+ updateAppConfig(tree, blocks, context, sourceRoot);
81
+ addCodeMirrorSetup(tree, blocks, context, sourceRoot);
91
82
 
92
83
  context.logger.info('✅ Installation setup complete.');
93
84
 
@@ -95,41 +86,6 @@ export function ngAdd(): Rule {
95
86
  };
96
87
  }
97
88
 
98
- async function getSourceRoot(
99
- tree: Tree,
100
- context: SchematicContext
101
- ): Promise<string> {
102
- const buffer = tree.read('/angular.json');
103
-
104
- if (!buffer) {
105
- context.logger.error('❌ angular.json not found.');
106
- throw new Error('angular.json not found... get good');
107
- }
108
-
109
- const angularJson = JSON.parse(buffer.toString());
110
-
111
- // We need to get every project in the workspace
112
- const projects = Object.keys(angularJson.projects);
113
- // We will prompt the user to select a project
114
- const response = await prompt<{ project: string }>({
115
- type: 'select',
116
- name: 'project',
117
- message: 'Select the Angular project to update:',
118
- choices: projects.map((project) => ({
119
- name: project,
120
- message: project,
121
- })),
122
- });
123
- const project = response.project;
124
-
125
- if (!project || !angularJson.projects[project]) {
126
- context.logger.error(`❌ Project ${project} not found in angular.json.`);
127
- throw new Error(`Project ${project} not found in angular.json`);
128
- }
129
-
130
- return angularJson.projects[project].sourceRoot;
131
- }
132
-
133
89
  function updateStylesScss(
134
90
  tree: Tree,
135
91
  blocks: string[],
@@ -237,7 +193,7 @@ function addCodeMirrorSetup(
237
193
  sourceRoot: string
238
194
  ): void {
239
195
  const needsCodeMirror = selectedBlocks.some((block) =>
240
- ['ngx-editor-js2-codemirror', 'ngx-editor-js2-mermaidjs'].includes(block)
196
+ ['codemirror', 'mermaidjs'].includes(block)
241
197
  );
242
198
 
243
199
  if (!needsCodeMirror) {
@@ -287,62 +243,11 @@ import 'codemirror/mode/xml/xml';
287
243
  }
288
244
  }
289
245
 
290
- // async function updateAngularJson(
291
- // tree: Tree,
292
- // blocks: string[],
293
- // context: SchematicContext
294
- // ): Promise<string> {
295
- // const angularJsonPath = '/angular.json';
296
- // const buffer = tree.read(angularJsonPath);
297
-
298
- // if (!buffer) {
299
- // context.logger.error('❌ angular.json not found.');
300
- // throw new Error('angular.json not found... get good');
301
- // }
302
-
303
- // const angularJson = JSON.parse(buffer.toString());
304
-
305
- // // const project = angularJson.defaultProject;
306
- // // We need to get every project in the workspace
307
- // const projects = Object.keys(angularJson.projects);
308
- // // We will prompt the user to select a project
309
- // const response = await prompt<{ project: string }>({
310
- // type: 'select',
311
- // name: 'project',
312
- // message: 'Select the Angular project to update:',
313
- // choices: projects.map((project) => ({
314
- // name: project,
315
- // message: project,
316
- // })),
317
- // });
318
- // const project = response.project;
319
-
320
- // if (!project || !angularJson.projects[project]) {
321
- // context.logger.error(`❌ Project ${project} not found in angular.json.`);
322
- // throw new Error(`Project ${project} not found in angular.json`);
323
- // }
324
-
325
- // const includePaths =
326
- // angularJson.projects[project].architect.build.options
327
- // .stylePreprocessorOptions?.includePaths || [];
328
-
329
- // includePaths.push('dist/ngx-editor-js2');
330
- // blocks.forEach((block) => {
331
- // const stylePath = optionalBlocks[block].stylePath;
332
- // if (!includePaths.includes(stylePath)) {
333
- // includePaths.push(stylePath);
334
- // }
335
- // });
336
-
337
- // angularJson.projects[
338
- // project
339
- // ].architect.build.options.stylePreprocessorOptions = { includePaths };
340
- // tree.overwrite(angularJsonPath, JSON.stringify(angularJson, null, 2));
341
-
342
- // context.logger.info('🔧 angular.json updated successfully.');
343
-
344
- // return (
345
- // angularJson.projects[project].sourceRoot ||
346
- // angularJson.projects[project].root
347
- // );
348
- // }
246
+ function getProjectSourceRoot(tree: Tree, projectName: string): string {
247
+ const buffer = tree.read('/angular.json');
248
+ if (!buffer) throw new Error('angular.json not found');
249
+ const workspace = JSON.parse(buffer.toString());
250
+ const project = workspace.projects[projectName];
251
+ if (!project) throw new Error(`Project ${projectName} not found`);
252
+ return project.sourceRoot || 'src';
253
+ }
@@ -1,7 +1,30 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
3
  "$id": "NgAdd",
4
4
  "title": "Ng Add Options",
5
5
  "type": "object",
6
- "properties": {}
6
+ "properties": {
7
+ "blocks": {
8
+ "type": "array",
9
+ "description": "Optional Ngx-Editor-JS2 blocks to install",
10
+ "x-prompt": {
11
+ "message": "Select optional Ngx-Editor-JS2 blocks to install:",
12
+ "type": "list",
13
+ "multiselect": true,
14
+ "items": [
15
+ { "value": "image", "label": "Image" },
16
+ { "value": "popQuiz", "label": "Pop Quiz" },
17
+ { "value": "mermaidjs", "label": "MermaidJS" },
18
+ { "value": "codemirror", "label": "CodeMirror" },
19
+ { "value": "mfeLoader", "label": "MFE Loader" },
20
+ { "value": "blockquotes", "label": "Blockquotes" }
21
+ ]
22
+ }
23
+ },
24
+ "project": {
25
+ "type": "string",
26
+ "description": "The Angular project to update",
27
+ "x-prompt": "Which Angular project would you like to update?"
28
+ }
29
+ }
7
30
  }