@grafana/create-plugin 2.11.2 → 2.12.0-canary.658.dabaee1.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/dist/bin/run.js +13 -18
- package/dist/commands/generate/prettify-files.js +15 -70
- package/dist/commands/generate/print-success-message.js +28 -31
- package/dist/commands/generate/prompt-user.js +23 -91
- package/dist/commands/generate/update-go-sdk-and-packages.js +36 -105
- package/dist/commands/generate.command.js +122 -240
- package/dist/commands/index.js +5 -21
- package/dist/commands/migrate.command.js +71 -134
- package/dist/commands/provisioning.command.js +30 -85
- package/dist/commands/types.js +1 -2
- package/dist/commands/update.command.js +44 -97
- package/dist/commands/version.command.js +16 -57
- package/dist/constants.js +37 -32
- package/dist/utils/tests/utils.files.test.js +21 -23
- package/dist/utils/tests/utils.handlebars.test.js +24 -26
- package/dist/utils/tests/utils.npm.test.js +103 -95
- package/dist/utils/tests/utils.plugin.test.js +11 -13
- package/dist/utils/tests/utils.templates.test.js +16 -18
- package/dist/utils/utils.config.js +30 -32
- package/dist/utils/utils.console.js +25 -31
- package/dist/utils/utils.files.js +38 -104
- package/dist/utils/utils.handlebars.js +30 -65
- package/dist/utils/utils.npm.js +75 -118
- package/dist/utils/utils.os.js +3 -7
- package/dist/utils/utils.packageManager.js +31 -37
- package/dist/utils/utils.packagejson.js +13 -22
- package/dist/utils/utils.path.js +7 -14
- package/dist/utils/utils.plugin.js +6 -13
- package/dist/utils/utils.templates.js +58 -80
- package/dist/utils/utils.version.js +9 -11
- package/package.json +20 -6
- package/src/bin/run.ts +2 -2
- package/src/commands/generate/prettify-files.ts +1 -1
- package/src/commands/generate/print-success-message.ts +4 -4
- package/src/commands/generate/prompt-user.ts +2 -2
- package/src/commands/generate/update-go-sdk-and-packages.ts +2 -2
- package/src/commands/generate.command.ts +15 -15
- package/src/commands/index.ts +5 -5
- package/src/commands/migrate.command.ts +6 -6
- package/src/commands/provisioning.command.ts +6 -6
- package/src/commands/types.ts +1 -1
- package/src/commands/update.command.ts +5 -5
- package/src/commands/version.command.ts +5 -2
- package/src/constants.ts +4 -1
- package/src/utils/tests/utils.files.test.ts +2 -2
- package/src/utils/tests/utils.handlebars.test.ts +2 -2
- package/src/utils/tests/utils.npm.test.ts +43 -34
- package/src/utils/tests/utils.plugin.test.ts +2 -2
- package/src/utils/tests/utils.templates.test.ts +2 -2
- package/src/utils/utils.config.ts +3 -3
- package/src/utils/utils.console.ts +16 -11
- package/src/utils/utils.files.ts +3 -3
- package/src/utils/utils.handlebars.ts +3 -3
- package/src/utils/utils.npm.ts +3 -3
- package/src/utils/utils.packageManager.ts +3 -3
- package/src/utils/utils.packagejson.ts +5 -5
- package/src/utils/utils.path.ts +3 -3
- package/src/utils/utils.plugin.ts +2 -3
- package/src/utils/utils.templates.ts +10 -10
- package/src/utils/utils.version.ts +5 -2
- package/tsconfig.json +5 -0
- package/vitest.config.ts +10 -0
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
import { updateNpmDependencies, getUpdatableNpmDependencies, hasNpmDependenciesToUpdate, getPackageJsonUpdatesAsText, updatePackageJson, } from '../utils.npm.js';
|
|
3
|
+
const mocks = vi.hoisted(() => {
|
|
4
|
+
return {
|
|
5
|
+
getPackageJson: vi.fn(),
|
|
6
|
+
getLatestPackageJson: vi.fn(),
|
|
7
|
+
writePackageJson: vi.fn(),
|
|
8
|
+
};
|
|
9
|
+
});
|
|
10
|
+
vi.mock('../utils.packagejson.js', async () => {
|
|
11
|
+
return {
|
|
12
|
+
getPackageJson: mocks.getPackageJson,
|
|
13
|
+
getLatestPackageJson: mocks.getLatestPackageJson,
|
|
14
|
+
writePackageJson: mocks.writePackageJson,
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
describe('Utils / NPM', () => {
|
|
18
|
+
describe('getUpdatableNpmDependencies()', () => {
|
|
19
|
+
test('it should return a summary of dependencies to be updated', () => {
|
|
20
|
+
expect(getUpdatableNpmDependencies({
|
|
13
21
|
'@grafana/tsconfig': '^1.2.0-rc1',
|
|
14
22
|
'@swc/core': '^1.2.162',
|
|
15
23
|
'@types/minimist': '^1.6.2',
|
|
@@ -27,8 +35,8 @@ describe('Utils / NPM', function () {
|
|
|
27
35
|
'@types/minimist': { prev: '^1.6.2', next: '^1.4.2' },
|
|
28
36
|
});
|
|
29
37
|
});
|
|
30
|
-
test('it should be possible to only update dependencies that are outdated',
|
|
31
|
-
expect(
|
|
38
|
+
test('it should be possible to only update dependencies that are outdated', () => {
|
|
39
|
+
expect(getUpdatableNpmDependencies({
|
|
32
40
|
'@grafana/tsconfig': '^1.2.0-rc1',
|
|
33
41
|
'@swc/core': '^1.2.162',
|
|
34
42
|
'@types/minimist': '^1.6.2',
|
|
@@ -45,8 +53,8 @@ describe('Utils / NPM', function () {
|
|
|
45
53
|
'@grafana/tsconfig': { prev: '^1.2.0-rc1', next: '^2.0.0' },
|
|
46
54
|
});
|
|
47
55
|
});
|
|
48
|
-
test('it should be able to override with using release channels like "latest"',
|
|
49
|
-
expect(
|
|
56
|
+
test('it should be able to override with using release channels like "latest"', () => {
|
|
57
|
+
expect(getUpdatableNpmDependencies({
|
|
50
58
|
'@grafana/tsconfig': 'latest',
|
|
51
59
|
'@swc/core': '^1.2.162',
|
|
52
60
|
'@types/minimist': '^1.6.2',
|
|
@@ -66,9 +74,9 @@ describe('Utils / NPM', function () {
|
|
|
66
74
|
});
|
|
67
75
|
});
|
|
68
76
|
});
|
|
69
|
-
describe('updateNpmDependencies()',
|
|
70
|
-
test('it should update existing dependencies',
|
|
71
|
-
expect(
|
|
77
|
+
describe('updateNpmDependencies()', () => {
|
|
78
|
+
test('it should update existing dependencies', () => {
|
|
79
|
+
expect(updateNpmDependencies({
|
|
72
80
|
'@grafana/tsconfig': '^1.2.0-rc1',
|
|
73
81
|
'@swc/core': '^1.2.162',
|
|
74
82
|
'@types/minimist': '^1.2.2',
|
|
@@ -87,8 +95,8 @@ describe('Utils / NPM', function () {
|
|
|
87
95
|
'node-plop': '0.26.3',
|
|
88
96
|
});
|
|
89
97
|
});
|
|
90
|
-
test('it should add new depdendencies',
|
|
91
|
-
expect(
|
|
98
|
+
test('it should add new depdendencies', () => {
|
|
99
|
+
expect(updateNpmDependencies({
|
|
92
100
|
'@grafana/tsconfig': '^1.2.0-rc1',
|
|
93
101
|
'@swc/core': '^1.2.162',
|
|
94
102
|
}, {
|
|
@@ -101,8 +109,8 @@ describe('Utils / NPM', function () {
|
|
|
101
109
|
'@types/minimist': '^1.4.2',
|
|
102
110
|
});
|
|
103
111
|
});
|
|
104
|
-
test('it should override `latest` and other release channels',
|
|
105
|
-
expect(
|
|
112
|
+
test('it should override `latest` and other release channels', () => {
|
|
113
|
+
expect(updateNpmDependencies({
|
|
106
114
|
'@grafana/tsconfig': 'latest',
|
|
107
115
|
'@swc/core': '^1.2.162',
|
|
108
116
|
'@types/minimist': '^1.2.2',
|
|
@@ -120,8 +128,8 @@ describe('Utils / NPM', function () {
|
|
|
120
128
|
'node-plop': '0.26.3',
|
|
121
129
|
});
|
|
122
130
|
});
|
|
123
|
-
test('it should be able to override with using release channels like "latest"',
|
|
124
|
-
expect(
|
|
131
|
+
test('it should be able to override with using release channels like "latest"', () => {
|
|
132
|
+
expect(updateNpmDependencies({
|
|
125
133
|
'@grafana/tsconfig': '^2.0.0',
|
|
126
134
|
'@swc/core': '^1.2.162',
|
|
127
135
|
'@types/minimist': '^1.2.2',
|
|
@@ -140,9 +148,9 @@ describe('Utils / NPM', function () {
|
|
|
140
148
|
});
|
|
141
149
|
});
|
|
142
150
|
});
|
|
143
|
-
describe('hasNpmDependenciesToUpdate()',
|
|
144
|
-
test('It should return false when there are no npm dependencies to update',
|
|
145
|
-
|
|
151
|
+
describe('hasNpmDependenciesToUpdate()', () => {
|
|
152
|
+
test('It should return false when there are no npm dependencies to update', () => {
|
|
153
|
+
const packageJson = {
|
|
146
154
|
dependencies: {
|
|
147
155
|
'@grafana/ui': '10.0.0',
|
|
148
156
|
react: '18.2.0',
|
|
@@ -153,13 +161,13 @@ describe('Utils / NPM', function () {
|
|
|
153
161
|
},
|
|
154
162
|
scripts: {},
|
|
155
163
|
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
164
|
+
mocks.getPackageJson.mockReturnValue(packageJson);
|
|
165
|
+
mocks.getLatestPackageJson.mockReturnValue(packageJson);
|
|
166
|
+
const result = hasNpmDependenciesToUpdate();
|
|
159
167
|
expect(result).toBe(false);
|
|
160
168
|
});
|
|
161
|
-
test('It should return true when there are npm dependencies to update',
|
|
162
|
-
|
|
169
|
+
test('It should return true when there are npm dependencies to update', () => {
|
|
170
|
+
const packageJson = {
|
|
163
171
|
dependencies: {
|
|
164
172
|
'@grafana/ui': '10.0.0',
|
|
165
173
|
react: '18.2.0',
|
|
@@ -170,7 +178,7 @@ describe('Utils / NPM', function () {
|
|
|
170
178
|
},
|
|
171
179
|
scripts: {},
|
|
172
180
|
};
|
|
173
|
-
|
|
181
|
+
const latestPackageJson = {
|
|
174
182
|
dependencies: {
|
|
175
183
|
'@grafana/ui': '10.0.0',
|
|
176
184
|
react: '18.2.1',
|
|
@@ -181,13 +189,13 @@ describe('Utils / NPM', function () {
|
|
|
181
189
|
},
|
|
182
190
|
scripts: {},
|
|
183
191
|
};
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
192
|
+
mocks.getPackageJson.mockReturnValue(packageJson);
|
|
193
|
+
mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
|
|
194
|
+
const result = hasNpmDependenciesToUpdate();
|
|
187
195
|
expect(result).toBe(true);
|
|
188
196
|
});
|
|
189
|
-
test('It should return false when there are no dev dependencies to update in devOnly mode',
|
|
190
|
-
|
|
197
|
+
test('It should return false when there are no dev dependencies to update in devOnly mode', () => {
|
|
198
|
+
const packageJson = {
|
|
191
199
|
dependencies: {
|
|
192
200
|
'@grafana/ui': '10.0.0',
|
|
193
201
|
react: '18.2.0',
|
|
@@ -198,7 +206,7 @@ describe('Utils / NPM', function () {
|
|
|
198
206
|
},
|
|
199
207
|
scripts: {},
|
|
200
208
|
};
|
|
201
|
-
|
|
209
|
+
const latestPackageJson = {
|
|
202
210
|
dependencies: {
|
|
203
211
|
'@grafana/ui': '10.0.0',
|
|
204
212
|
react: '18.2.1',
|
|
@@ -209,15 +217,15 @@ describe('Utils / NPM', function () {
|
|
|
209
217
|
},
|
|
210
218
|
scripts: {},
|
|
211
219
|
};
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
220
|
+
mocks.getPackageJson.mockReturnValue(packageJson);
|
|
221
|
+
mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
|
|
222
|
+
const result = hasNpmDependenciesToUpdate({ devOnly: true });
|
|
215
223
|
expect(result).toBe(false);
|
|
216
224
|
});
|
|
217
225
|
});
|
|
218
|
-
describe('getPackageJsonUpdatesAsText',
|
|
219
|
-
test("It should return an empty text when there's nothing to update",
|
|
220
|
-
|
|
226
|
+
describe('getPackageJsonUpdatesAsText', () => {
|
|
227
|
+
test("It should return an empty text when there's nothing to update", () => {
|
|
228
|
+
const packageJson = {
|
|
221
229
|
dependencies: {
|
|
222
230
|
'@grafana/ui': '10.0.0',
|
|
223
231
|
react: '18.2.0',
|
|
@@ -228,13 +236,13 @@ describe('Utils / NPM', function () {
|
|
|
228
236
|
},
|
|
229
237
|
scripts: {},
|
|
230
238
|
};
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
239
|
+
mocks.getPackageJson.mockReturnValue(packageJson);
|
|
240
|
+
mocks.getLatestPackageJson.mockReturnValue(packageJson);
|
|
241
|
+
const result = getPackageJsonUpdatesAsText();
|
|
234
242
|
expect(result).toBe('');
|
|
235
243
|
});
|
|
236
|
-
test("It should return the related text when there's an update",
|
|
237
|
-
|
|
244
|
+
test("It should return the related text when there's an update", () => {
|
|
245
|
+
const packageJson = {
|
|
238
246
|
dependencies: {
|
|
239
247
|
'@grafana/ui': '10.0.0',
|
|
240
248
|
react: '18.2.0',
|
|
@@ -245,7 +253,7 @@ describe('Utils / NPM', function () {
|
|
|
245
253
|
},
|
|
246
254
|
scripts: {},
|
|
247
255
|
};
|
|
248
|
-
|
|
256
|
+
const latestPackageJson = {
|
|
249
257
|
dependencies: {
|
|
250
258
|
'@grafana/ui': '10.0.0',
|
|
251
259
|
react: '18.2.1',
|
|
@@ -256,14 +264,14 @@ describe('Utils / NPM', function () {
|
|
|
256
264
|
},
|
|
257
265
|
scripts: {},
|
|
258
266
|
};
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
267
|
+
mocks.getPackageJson.mockReturnValue(packageJson);
|
|
268
|
+
mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
|
|
269
|
+
const result = getPackageJsonUpdatesAsText();
|
|
262
270
|
expect(result).toContain('sass');
|
|
263
271
|
expect(result).toContain('react');
|
|
264
272
|
});
|
|
265
|
-
test('It should not return the related text when devOnly and only dependencies to update',
|
|
266
|
-
|
|
273
|
+
test('It should not return the related text when devOnly and only dependencies to update', () => {
|
|
274
|
+
const packageJson = {
|
|
267
275
|
dependencies: {
|
|
268
276
|
'@grafana/ui': '10.0.0',
|
|
269
277
|
react: '18.2.0',
|
|
@@ -274,7 +282,7 @@ describe('Utils / NPM', function () {
|
|
|
274
282
|
},
|
|
275
283
|
scripts: {},
|
|
276
284
|
};
|
|
277
|
-
|
|
285
|
+
const latestPackageJson = {
|
|
278
286
|
dependencies: {
|
|
279
287
|
'@grafana/ui': '10.0.0',
|
|
280
288
|
react: '18.2.1',
|
|
@@ -285,13 +293,13 @@ describe('Utils / NPM', function () {
|
|
|
285
293
|
},
|
|
286
294
|
scripts: {},
|
|
287
295
|
};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
296
|
+
mocks.getPackageJson.mockReturnValue(packageJson);
|
|
297
|
+
mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
|
|
298
|
+
const result = getPackageJsonUpdatesAsText({ devOnly: true });
|
|
291
299
|
expect(result).toBe('');
|
|
292
300
|
});
|
|
293
|
-
test('It should return the related text when devOnly and only dev dependencies to update',
|
|
294
|
-
|
|
301
|
+
test('It should return the related text when devOnly and only dev dependencies to update', () => {
|
|
302
|
+
const packageJson = {
|
|
295
303
|
dependencies: {
|
|
296
304
|
'@grafana/ui': '10.0.0',
|
|
297
305
|
react: '18.2.0',
|
|
@@ -302,7 +310,7 @@ describe('Utils / NPM', function () {
|
|
|
302
310
|
},
|
|
303
311
|
scripts: {},
|
|
304
312
|
};
|
|
305
|
-
|
|
313
|
+
const latestPackageJson = {
|
|
306
314
|
dependencies: {
|
|
307
315
|
'@grafana/ui': '10.0.0',
|
|
308
316
|
react: '18.2.0',
|
|
@@ -313,15 +321,15 @@ describe('Utils / NPM', function () {
|
|
|
313
321
|
},
|
|
314
322
|
scripts: {},
|
|
315
323
|
};
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
324
|
+
mocks.getPackageJson.mockReturnValue(packageJson);
|
|
325
|
+
mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
|
|
326
|
+
const result = getPackageJsonUpdatesAsText({ devOnly: true });
|
|
319
327
|
expect(result).toContain('sass');
|
|
320
328
|
});
|
|
321
329
|
});
|
|
322
|
-
describe('updatePackageJson()',
|
|
323
|
-
test('It should not change the package.json if nothing was updated',
|
|
324
|
-
|
|
330
|
+
describe('updatePackageJson()', () => {
|
|
331
|
+
test('It should not change the package.json if nothing was updated', () => {
|
|
332
|
+
const packageJson = {
|
|
325
333
|
dependencies: {
|
|
326
334
|
'@grafana/ui': '10.0.0',
|
|
327
335
|
react: '18.2.0',
|
|
@@ -332,10 +340,10 @@ describe('Utils / NPM', function () {
|
|
|
332
340
|
},
|
|
333
341
|
scripts: {},
|
|
334
342
|
};
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
expect(
|
|
343
|
+
mocks.getPackageJson.mockReturnValue(packageJson);
|
|
344
|
+
mocks.getLatestPackageJson.mockReturnValue(packageJson);
|
|
345
|
+
updatePackageJson();
|
|
346
|
+
expect(mocks.writePackageJson).toHaveBeenCalledWith({
|
|
339
347
|
dependencies: {
|
|
340
348
|
'@grafana/ui': '10.0.0',
|
|
341
349
|
react: '18.2.0',
|
|
@@ -347,8 +355,8 @@ describe('Utils / NPM', function () {
|
|
|
347
355
|
scripts: {},
|
|
348
356
|
});
|
|
349
357
|
});
|
|
350
|
-
test('It should change the package.json when something was updated',
|
|
351
|
-
|
|
358
|
+
test('It should change the package.json when something was updated', () => {
|
|
359
|
+
const packageJson = {
|
|
352
360
|
dependencies: {
|
|
353
361
|
'@grafana/ui': '10.0.0',
|
|
354
362
|
react: '18.2.0',
|
|
@@ -359,7 +367,7 @@ describe('Utils / NPM', function () {
|
|
|
359
367
|
},
|
|
360
368
|
scripts: {},
|
|
361
369
|
};
|
|
362
|
-
|
|
370
|
+
const latestPackageJson = {
|
|
363
371
|
dependencies: {
|
|
364
372
|
'@grafana/ui': '10.0.0',
|
|
365
373
|
react: '18.2.1',
|
|
@@ -370,10 +378,10 @@ describe('Utils / NPM', function () {
|
|
|
370
378
|
},
|
|
371
379
|
scripts: {},
|
|
372
380
|
};
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
expect(
|
|
381
|
+
mocks.getPackageJson.mockReturnValue(packageJson);
|
|
382
|
+
mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
|
|
383
|
+
updatePackageJson();
|
|
384
|
+
expect(mocks.writePackageJson).toHaveBeenCalledWith({
|
|
377
385
|
dependencies: {
|
|
378
386
|
'@grafana/ui': '10.0.0',
|
|
379
387
|
react: '18.2.1',
|
|
@@ -385,8 +393,8 @@ describe('Utils / NPM', function () {
|
|
|
385
393
|
scripts: {},
|
|
386
394
|
});
|
|
387
395
|
});
|
|
388
|
-
test('It should not change the package.json when devOnly is true and only non dev dependencies changed',
|
|
389
|
-
|
|
396
|
+
test('It should not change the package.json when devOnly is true and only non dev dependencies changed', () => {
|
|
397
|
+
const packageJson = {
|
|
390
398
|
dependencies: {
|
|
391
399
|
'@grafana/ui': '10.0.0',
|
|
392
400
|
react: '18.2.0',
|
|
@@ -397,7 +405,7 @@ describe('Utils / NPM', function () {
|
|
|
397
405
|
},
|
|
398
406
|
scripts: {},
|
|
399
407
|
};
|
|
400
|
-
|
|
408
|
+
const latestPackageJson = {
|
|
401
409
|
dependencies: {
|
|
402
410
|
'@grafana/ui': '10.0.0',
|
|
403
411
|
react: '18.2.1',
|
|
@@ -408,10 +416,10 @@ describe('Utils / NPM', function () {
|
|
|
408
416
|
},
|
|
409
417
|
scripts: {},
|
|
410
418
|
};
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
expect(
|
|
419
|
+
mocks.getPackageJson.mockReturnValue(packageJson);
|
|
420
|
+
mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
|
|
421
|
+
updatePackageJson({ devOnly: true });
|
|
422
|
+
expect(mocks.writePackageJson).toHaveBeenCalledWith({
|
|
415
423
|
dependencies: {
|
|
416
424
|
'@grafana/ui': '10.0.0',
|
|
417
425
|
react: '18.2.0',
|
|
@@ -423,8 +431,8 @@ describe('Utils / NPM', function () {
|
|
|
423
431
|
scripts: {},
|
|
424
432
|
});
|
|
425
433
|
});
|
|
426
|
-
test('It should change the package.json when devOnly is true but only update dev dependencies',
|
|
427
|
-
|
|
434
|
+
test('It should change the package.json when devOnly is true but only update dev dependencies', () => {
|
|
435
|
+
const packageJson = {
|
|
428
436
|
dependencies: {
|
|
429
437
|
'@grafana/ui': '10.0.0',
|
|
430
438
|
react: '18.2.0',
|
|
@@ -435,7 +443,7 @@ describe('Utils / NPM', function () {
|
|
|
435
443
|
},
|
|
436
444
|
scripts: {},
|
|
437
445
|
};
|
|
438
|
-
|
|
446
|
+
const latestPackageJson = {
|
|
439
447
|
dependencies: {
|
|
440
448
|
'@grafana/ui': '10.0.0',
|
|
441
449
|
react: '18.2.1',
|
|
@@ -446,10 +454,10 @@ describe('Utils / NPM', function () {
|
|
|
446
454
|
},
|
|
447
455
|
scripts: {},
|
|
448
456
|
};
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
expect(
|
|
457
|
+
mocks.getPackageJson.mockReturnValue(packageJson);
|
|
458
|
+
mocks.getLatestPackageJson.mockReturnValue(latestPackageJson);
|
|
459
|
+
updatePackageJson({ devOnly: true });
|
|
460
|
+
expect(mocks.writePackageJson).toHaveBeenCalledWith({
|
|
453
461
|
dependencies: {
|
|
454
462
|
'@grafana/ui': '10.0.0',
|
|
455
463
|
react: '18.2.0',
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var srcDir = "".concat(constants_1.FIXTURES_PATH, "/test-template/src");
|
|
9
|
-
var pluginJson = (0, utils_plugin_1.getPluginJson)(srcDir);
|
|
1
|
+
import { FIXTURES_PATH, TEMPLATE_PATHS } from '../../constants.js';
|
|
2
|
+
import { getPluginJson } from '../utils.plugin.js';
|
|
3
|
+
describe('Utils / Plugins', () => {
|
|
4
|
+
describe('getPluginJson()', () => {
|
|
5
|
+
test('should return the parsed plugin JSON if the file exits', () => {
|
|
6
|
+
const srcDir = `${FIXTURES_PATH}/test-template/src`;
|
|
7
|
+
const pluginJson = getPluginJson(srcDir);
|
|
10
8
|
expect(pluginJson).toBeDefined();
|
|
11
9
|
expect(pluginJson.type).toBe('app');
|
|
12
10
|
});
|
|
13
|
-
test('should throw an error if the plugin.json is not found',
|
|
14
|
-
|
|
15
|
-
expect(
|
|
16
|
-
|
|
11
|
+
test('should throw an error if the plugin.json is not found', () => {
|
|
12
|
+
const srcDir = `${TEMPLATE_PATHS.app}/src/unknown`;
|
|
13
|
+
expect(() => {
|
|
14
|
+
getPluginJson(srcDir);
|
|
17
15
|
}).toThrow();
|
|
18
16
|
});
|
|
19
17
|
});
|
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
test('should return with a list of files', function () {
|
|
8
|
-
expect((0, utils_templates_1.getTemplateFiles)(constants_1.PLUGIN_TYPES.app).length).toBeGreaterThan(0);
|
|
1
|
+
import { PLUGIN_TYPES } from '../../constants.js';
|
|
2
|
+
import { getTemplateFiles } from '../utils.templates.js';
|
|
3
|
+
describe('Utils / Templates', () => {
|
|
4
|
+
describe('getTemplateFiles()', () => {
|
|
5
|
+
test('should return with a list of files', () => {
|
|
6
|
+
expect(getTemplateFiles(PLUGIN_TYPES.app).length).toBeGreaterThan(0);
|
|
9
7
|
});
|
|
10
|
-
test('should be possible to filter templates by a sub-folder',
|
|
11
|
-
|
|
8
|
+
test('should be possible to filter templates by a sub-folder', () => {
|
|
9
|
+
const templateFiles = getTemplateFiles(PLUGIN_TYPES.app, '.config/types');
|
|
12
10
|
expect(templateFiles.length).toBeGreaterThan(0);
|
|
13
|
-
expect(templateFiles.find(
|
|
14
|
-
expect(templateFiles.find(
|
|
11
|
+
expect(templateFiles.find((t) => t.includes('custom.d.ts'))).not.toBeUndefined();
|
|
12
|
+
expect(templateFiles.find((t) => t.includes('Dockerfile'))).toBeUndefined();
|
|
15
13
|
});
|
|
16
|
-
test('should return an empty array when filtering by a non-existing sub-folder',
|
|
17
|
-
|
|
14
|
+
test('should return an empty array when filtering by a non-existing sub-folder', () => {
|
|
15
|
+
const templateFiles = getTemplateFiles(PLUGIN_TYPES.app, '.config/types/foo/bar/unknown');
|
|
18
16
|
expect(Array.isArray(templateFiles)).toBe(true);
|
|
19
17
|
expect(templateFiles.length).toBe(0);
|
|
20
18
|
});
|
|
21
|
-
test('should be possible to filter for multiple different files',
|
|
22
|
-
|
|
19
|
+
test('should be possible to filter for multiple different files', () => {
|
|
20
|
+
const templateFiles = getTemplateFiles(PLUGIN_TYPES.app, ['.prettierrc.js', 'cypress.json', 'tsconfig.json']);
|
|
23
21
|
expect(Array.isArray(templateFiles)).toBe(true);
|
|
24
22
|
expect(templateFiles.length).toBe(3);
|
|
25
23
|
});
|
|
26
|
-
test('should be possible to filter for a single file',
|
|
27
|
-
|
|
24
|
+
test('should be possible to filter for a single file', () => {
|
|
25
|
+
const templateFiles = getTemplateFiles(PLUGIN_TYPES.app, '.config/types/custom.d.ts');
|
|
28
26
|
expect(Array.isArray(templateFiles)).toBe(true);
|
|
29
27
|
expect(templateFiles.length).toBe(1);
|
|
30
28
|
});
|
|
@@ -1,43 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getConfig = void 0;
|
|
18
|
-
var fs_1 = __importDefault(require("fs"));
|
|
19
|
-
var path_1 = __importDefault(require("path"));
|
|
20
|
-
var utils_version_1 = require("./utils.version");
|
|
21
|
-
function getConfig() {
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { getVersion } from './utils.version.js';
|
|
4
|
+
export function getConfig() {
|
|
22
5
|
try {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return
|
|
6
|
+
const rootPath = path.resolve(process.cwd(), '.config/.cprc.json');
|
|
7
|
+
const rootConfig = readRCFileSync(rootPath);
|
|
8
|
+
const userConfig = getUserConfig();
|
|
9
|
+
return {
|
|
10
|
+
...rootConfig,
|
|
11
|
+
...userConfig,
|
|
12
|
+
version: rootConfig.version,
|
|
13
|
+
features: createFeatureFlags({
|
|
14
|
+
...rootConfig.features,
|
|
15
|
+
...userConfig.features,
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
27
18
|
}
|
|
28
19
|
catch (error) {
|
|
29
20
|
return {
|
|
30
|
-
version:
|
|
21
|
+
version: getVersion(),
|
|
31
22
|
features: createFeatureFlags(),
|
|
32
23
|
};
|
|
33
24
|
}
|
|
34
25
|
}
|
|
35
|
-
exports.getConfig = getConfig;
|
|
36
26
|
function getUserConfig() {
|
|
37
27
|
try {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return
|
|
28
|
+
const userPath = path.resolve(process.cwd(), '.cprc.json');
|
|
29
|
+
const userConfig = readRCFileSync(userPath);
|
|
30
|
+
return {
|
|
31
|
+
...userConfig,
|
|
32
|
+
features: createFeatureFlags({
|
|
33
|
+
...userConfig.features,
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
41
36
|
}
|
|
42
37
|
catch (error) {
|
|
43
38
|
return {
|
|
@@ -47,7 +42,7 @@ function getUserConfig() {
|
|
|
47
42
|
}
|
|
48
43
|
function readRCFileSync(path) {
|
|
49
44
|
try {
|
|
50
|
-
|
|
45
|
+
const data = fs.readFileSync(path);
|
|
51
46
|
return JSON.parse(data.toString());
|
|
52
47
|
}
|
|
53
48
|
catch (error) {
|
|
@@ -55,5 +50,8 @@ function readRCFileSync(path) {
|
|
|
55
50
|
}
|
|
56
51
|
}
|
|
57
52
|
function createFeatureFlags(flags) {
|
|
58
|
-
return
|
|
53
|
+
return {
|
|
54
|
+
bundleGrafanaUI: false,
|
|
55
|
+
...flags,
|
|
56
|
+
};
|
|
59
57
|
}
|