@tmdjr/ngx-editor-js2 20.0.3 → 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 +1 -1
- package/schematics/ng-add/index.d.ts +1 -1
- package/schematics/ng-add/index.js +20 -101
- package/schematics/ng-add/index.ts +19 -119
- package/schematics/ng-add/schema.json +25 -2
package/package.json
CHANGED
|
@@ -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;
|
|
@@ -50,22 +50,10 @@ const optionalBlocks = {
|
|
|
50
50
|
peers: [],
|
|
51
51
|
},
|
|
52
52
|
};
|
|
53
|
-
function ngAdd() {
|
|
53
|
+
function ngAdd(options) {
|
|
54
54
|
return (tree, context) => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
{
|
|
58
|
-
type: 'checkbox',
|
|
59
|
-
name: 'blocks',
|
|
60
|
-
message: 'Select optional Ngx-Editor-JS2 blocks to install:',
|
|
61
|
-
choices: Object.keys(optionalBlocks).map((block) => ({
|
|
62
|
-
name: block,
|
|
63
|
-
message: block,
|
|
64
|
-
checked: false,
|
|
65
|
-
})),
|
|
66
|
-
},
|
|
67
|
-
])))) !== null && _b !== void 0 ? _b : { blocks: [] };
|
|
68
|
-
response.blocks.forEach((block) => {
|
|
55
|
+
const blocks = options.blocks || [];
|
|
56
|
+
blocks.forEach((block) => {
|
|
69
57
|
const { package: pkg, peers } = optionalBlocks[block];
|
|
70
58
|
(0, dependencies_1.addPackageJsonDependency)(tree, {
|
|
71
59
|
type: dependencies_1.NodeDependencyType.Default,
|
|
@@ -84,45 +72,16 @@ function ngAdd() {
|
|
|
84
72
|
});
|
|
85
73
|
});
|
|
86
74
|
context.addTask(new tasks_1.NodePackageInstallTask());
|
|
87
|
-
const sourceRoot =
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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);
|
|
91
81
|
context.logger.info('✅ Installation setup complete.');
|
|
92
82
|
return tree;
|
|
93
83
|
});
|
|
94
84
|
}
|
|
95
|
-
function getSourceRoot(tree, context) {
|
|
96
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
var _a, _b;
|
|
98
|
-
const buffer = tree.read('/angular.json');
|
|
99
|
-
if (!buffer) {
|
|
100
|
-
context.logger.error('❌ angular.json not found.');
|
|
101
|
-
throw new Error('angular.json not found... get good');
|
|
102
|
-
}
|
|
103
|
-
const angularJson = JSON.parse(buffer.toString());
|
|
104
|
-
// We need to get every project in the workspace
|
|
105
|
-
const projects = Object.keys(angularJson.projects);
|
|
106
|
-
// We will prompt the user to select a project
|
|
107
|
-
const response = (_b = (yield ((_a = context.prompt) === null || _a === void 0 ? void 0 : _a.call(context, [
|
|
108
|
-
{
|
|
109
|
-
type: 'list',
|
|
110
|
-
name: 'project',
|
|
111
|
-
message: 'Select the Angular project to update:',
|
|
112
|
-
choices: projects.map((project) => ({
|
|
113
|
-
name: project,
|
|
114
|
-
message: project,
|
|
115
|
-
})),
|
|
116
|
-
},
|
|
117
|
-
])))) !== null && _b !== void 0 ? _b : { project: projects[0] }; // fallback to first project
|
|
118
|
-
const project = response.project;
|
|
119
|
-
if (!project || !angularJson.projects[project]) {
|
|
120
|
-
context.logger.error(`❌ Project ${project} not found in angular.json.`);
|
|
121
|
-
throw new Error(`Project ${project} not found in angular.json`);
|
|
122
|
-
}
|
|
123
|
-
return angularJson.projects[project].sourceRoot;
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
85
|
function updateStylesScss(tree, blocks, context, sourceRoot) {
|
|
127
86
|
const stylePath = `${sourceRoot}/styles.scss`;
|
|
128
87
|
if (!tree.exists(stylePath)) {
|
|
@@ -183,7 +142,7 @@ function updateAppConfig(tree, blocks, context, sourceRoot) {
|
|
|
183
142
|
context.logger.info('🚀 app.config.ts updated successfully.');
|
|
184
143
|
}
|
|
185
144
|
function addCodeMirrorSetup(tree, selectedBlocks, context, sourceRoot) {
|
|
186
|
-
const needsCodeMirror = selectedBlocks.some((block) => ['
|
|
145
|
+
const needsCodeMirror = selectedBlocks.some((block) => ['codemirror', 'mermaidjs'].includes(block));
|
|
187
146
|
if (!needsCodeMirror) {
|
|
188
147
|
context.logger.info('CodeMirror dependencies not selected; skipping setup.');
|
|
189
148
|
return;
|
|
@@ -223,53 +182,13 @@ import 'codemirror/mode/xml/xml';
|
|
|
223
182
|
context.logger.warn(`styles.scss not found at path: ${stylesPath}`);
|
|
224
183
|
}
|
|
225
184
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
// }
|
|
237
|
-
// const angularJson = JSON.parse(buffer.toString());
|
|
238
|
-
// // const project = angularJson.defaultProject;
|
|
239
|
-
// // We need to get every project in the workspace
|
|
240
|
-
// const projects = Object.keys(angularJson.projects);
|
|
241
|
-
// // We will prompt the user to select a project
|
|
242
|
-
// const response = await prompt<{ project: string }>({
|
|
243
|
-
// type: 'select',
|
|
244
|
-
// name: 'project',
|
|
245
|
-
// message: 'Select the Angular project to update:',
|
|
246
|
-
// choices: projects.map((project) => ({
|
|
247
|
-
// name: project,
|
|
248
|
-
// message: project,
|
|
249
|
-
// })),
|
|
250
|
-
// });
|
|
251
|
-
// const project = response.project;
|
|
252
|
-
// if (!project || !angularJson.projects[project]) {
|
|
253
|
-
// context.logger.error(`❌ Project ${project} not found in angular.json.`);
|
|
254
|
-
// throw new Error(`Project ${project} not found in angular.json`);
|
|
255
|
-
// }
|
|
256
|
-
// const includePaths =
|
|
257
|
-
// angularJson.projects[project].architect.build.options
|
|
258
|
-
// .stylePreprocessorOptions?.includePaths || [];
|
|
259
|
-
// includePaths.push('dist/ngx-editor-js2');
|
|
260
|
-
// blocks.forEach((block) => {
|
|
261
|
-
// const stylePath = optionalBlocks[block].stylePath;
|
|
262
|
-
// if (!includePaths.includes(stylePath)) {
|
|
263
|
-
// includePaths.push(stylePath);
|
|
264
|
-
// }
|
|
265
|
-
// });
|
|
266
|
-
// angularJson.projects[
|
|
267
|
-
// project
|
|
268
|
-
// ].architect.build.options.stylePreprocessorOptions = { includePaths };
|
|
269
|
-
// tree.overwrite(angularJsonPath, JSON.stringify(angularJson, null, 2));
|
|
270
|
-
// context.logger.info('🔧 angular.json updated successfully.');
|
|
271
|
-
// return (
|
|
272
|
-
// angularJson.projects[project].sourceRoot ||
|
|
273
|
-
// angularJson.projects[project].root
|
|
274
|
-
// );
|
|
275
|
-
// }
|
|
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
|
+
}
|
|
@@ -47,22 +47,11 @@ const optionalBlocks: Record<
|
|
|
47
47
|
},
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
export function ngAdd(): Rule {
|
|
50
|
+
export function ngAdd(options: any): Rule {
|
|
51
51
|
return async (tree: Tree, context: SchematicContext) => {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
checked: false,
|
|
61
|
-
})),
|
|
62
|
-
},
|
|
63
|
-
])) ?? { blocks: [] };
|
|
64
|
-
|
|
65
|
-
response.blocks.forEach((block) => {
|
|
52
|
+
const blocks: string[] = options.blocks || [];
|
|
53
|
+
|
|
54
|
+
blocks.forEach((block) => {
|
|
66
55
|
const { package: pkg, peers } = optionalBlocks[block];
|
|
67
56
|
addPackageJsonDependency(tree, {
|
|
68
57
|
type: NodeDependencyType.Default,
|
|
@@ -83,13 +72,13 @@ export function ngAdd(): Rule {
|
|
|
83
72
|
|
|
84
73
|
context.addTask(new NodePackageInstallTask());
|
|
85
74
|
|
|
86
|
-
const sourceRoot =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
updateAppConfig(tree, response.blocks, context, sourceRoot);
|
|
75
|
+
const sourceRoot = options.project
|
|
76
|
+
? getProjectSourceRoot(tree, options.project)
|
|
77
|
+
: 'src';
|
|
91
78
|
|
|
92
|
-
|
|
79
|
+
updateStylesScss(tree, blocks, context, sourceRoot);
|
|
80
|
+
updateAppConfig(tree, blocks, context, sourceRoot);
|
|
81
|
+
addCodeMirrorSetup(tree, blocks, context, sourceRoot);
|
|
93
82
|
|
|
94
83
|
context.logger.info('✅ Installation setup complete.');
|
|
95
84
|
|
|
@@ -97,44 +86,6 @@ export function ngAdd(): Rule {
|
|
|
97
86
|
};
|
|
98
87
|
}
|
|
99
88
|
|
|
100
|
-
async function getSourceRoot(
|
|
101
|
-
tree: Tree,
|
|
102
|
-
context: SchematicContext
|
|
103
|
-
): Promise<string> {
|
|
104
|
-
const buffer = tree.read('/angular.json');
|
|
105
|
-
|
|
106
|
-
if (!buffer) {
|
|
107
|
-
context.logger.error('❌ angular.json not found.');
|
|
108
|
-
throw new Error('angular.json not found... get good');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const angularJson = JSON.parse(buffer.toString());
|
|
112
|
-
|
|
113
|
-
// We need to get every project in the workspace
|
|
114
|
-
const projects = Object.keys(angularJson.projects);
|
|
115
|
-
// We will prompt the user to select a project
|
|
116
|
-
const response = (await context.prompt?.([
|
|
117
|
-
{
|
|
118
|
-
type: 'list',
|
|
119
|
-
name: 'project',
|
|
120
|
-
message: 'Select the Angular project to update:',
|
|
121
|
-
choices: projects.map((project) => ({
|
|
122
|
-
name: project,
|
|
123
|
-
message: project,
|
|
124
|
-
})),
|
|
125
|
-
},
|
|
126
|
-
])) ?? { project: projects[0] }; // fallback to first project
|
|
127
|
-
|
|
128
|
-
const project = response.project;
|
|
129
|
-
|
|
130
|
-
if (!project || !angularJson.projects[project]) {
|
|
131
|
-
context.logger.error(`❌ Project ${project} not found in angular.json.`);
|
|
132
|
-
throw new Error(`Project ${project} not found in angular.json`);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return angularJson.projects[project].sourceRoot;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
89
|
function updateStylesScss(
|
|
139
90
|
tree: Tree,
|
|
140
91
|
blocks: string[],
|
|
@@ -242,7 +193,7 @@ function addCodeMirrorSetup(
|
|
|
242
193
|
sourceRoot: string
|
|
243
194
|
): void {
|
|
244
195
|
const needsCodeMirror = selectedBlocks.some((block) =>
|
|
245
|
-
['
|
|
196
|
+
['codemirror', 'mermaidjs'].includes(block)
|
|
246
197
|
);
|
|
247
198
|
|
|
248
199
|
if (!needsCodeMirror) {
|
|
@@ -292,62 +243,11 @@ import 'codemirror/mode/xml/xml';
|
|
|
292
243
|
}
|
|
293
244
|
}
|
|
294
245
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
// if (!buffer) {
|
|
304
|
-
// context.logger.error('❌ angular.json not found.');
|
|
305
|
-
// throw new Error('angular.json not found... get good');
|
|
306
|
-
// }
|
|
307
|
-
|
|
308
|
-
// const angularJson = JSON.parse(buffer.toString());
|
|
309
|
-
|
|
310
|
-
// // const project = angularJson.defaultProject;
|
|
311
|
-
// // We need to get every project in the workspace
|
|
312
|
-
// const projects = Object.keys(angularJson.projects);
|
|
313
|
-
// // We will prompt the user to select a project
|
|
314
|
-
// const response = await prompt<{ project: string }>({
|
|
315
|
-
// type: 'select',
|
|
316
|
-
// name: 'project',
|
|
317
|
-
// message: 'Select the Angular project to update:',
|
|
318
|
-
// choices: projects.map((project) => ({
|
|
319
|
-
// name: project,
|
|
320
|
-
// message: project,
|
|
321
|
-
// })),
|
|
322
|
-
// });
|
|
323
|
-
// const project = response.project;
|
|
324
|
-
|
|
325
|
-
// if (!project || !angularJson.projects[project]) {
|
|
326
|
-
// context.logger.error(`❌ Project ${project} not found in angular.json.`);
|
|
327
|
-
// throw new Error(`Project ${project} not found in angular.json`);
|
|
328
|
-
// }
|
|
329
|
-
|
|
330
|
-
// const includePaths =
|
|
331
|
-
// angularJson.projects[project].architect.build.options
|
|
332
|
-
// .stylePreprocessorOptions?.includePaths || [];
|
|
333
|
-
|
|
334
|
-
// includePaths.push('dist/ngx-editor-js2');
|
|
335
|
-
// blocks.forEach((block) => {
|
|
336
|
-
// const stylePath = optionalBlocks[block].stylePath;
|
|
337
|
-
// if (!includePaths.includes(stylePath)) {
|
|
338
|
-
// includePaths.push(stylePath);
|
|
339
|
-
// }
|
|
340
|
-
// });
|
|
341
|
-
|
|
342
|
-
// angularJson.projects[
|
|
343
|
-
// project
|
|
344
|
-
// ].architect.build.options.stylePreprocessorOptions = { includePaths };
|
|
345
|
-
// tree.overwrite(angularJsonPath, JSON.stringify(angularJson, null, 2));
|
|
346
|
-
|
|
347
|
-
// context.logger.info('🔧 angular.json updated successfully.');
|
|
348
|
-
|
|
349
|
-
// return (
|
|
350
|
-
// angularJson.projects[project].sourceRoot ||
|
|
351
|
-
// angularJson.projects[project].root
|
|
352
|
-
// );
|
|
353
|
-
// }
|
|
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
|
}
|