@grafana/create-plugin 2.2.2 → 2.2.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v2.2.3 (Tue Oct 24 2023)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - Create Plugin: Fix wrongly named files when upgrading/migrating [#490](https://github.com/grafana/plugin-tools/pull/490) ([@jackw](https://github.com/jackw))
6
+
7
+ #### Authors: 1
8
+
9
+ - Jack Westbrook ([@jackw](https://github.com/jackw))
10
+
11
+ ---
12
+
1
13
  # v2.2.2 (Mon Oct 23 2023)
2
14
 
3
15
  #### 🐛 Bug Fix
@@ -33,6 +33,7 @@ var utils_packageManager_1 = require("../utils/utils.packageManager");
33
33
  var print_success_message_1 = require("./generate-actions/print-success-message");
34
34
  var update_go_sdk_and_packages_1 = require("./generate-actions/update-go-sdk-and-packages");
35
35
  var prettify_files_1 = require("./generate-actions/prettify-files");
36
+ var utils_files_1 = require("../utils/utils.files");
36
37
  function default_1(plop) {
37
38
  plop.setHelper('if_eq', utils_handlebars_1.ifEq);
38
39
  plop.setHelper('normalize_id', utils_handlebars_1.normalizeId);
@@ -185,31 +186,18 @@ function getActionsForTemplateFolder(_a) {
185
186
  if (templateData.packageManagerName !== 'pnpm') {
186
187
  files = files.filter(function (file) { return path_1.default.basename(file) !== 'npmrc'; });
187
188
  }
188
- function getExportFileName(f) {
189
- var baseName = path_1.default.basename(f);
190
- if (Object.keys(configFileNamesMap).includes(baseName)) {
191
- return configFileNamesMap[baseName];
192
- }
193
- return path_1.default.extname(f) === '.hbs' ? path_1.default.basename(f, '.hbs') : baseName;
194
- }
195
189
  function getExportPath(f) {
196
190
  return path_1.default.relative(folderPath, path_1.default.dirname(f));
197
191
  }
198
192
  return files.filter(isFile).map(function (f) { return ({
199
193
  type: 'add',
200
194
  templateFile: f,
201
- path: path_1.default.join(exportPath, getExportPath(f), getExportFileName(f)),
195
+ path: path_1.default.join(exportPath, getExportPath(f), (0, utils_files_1.getExportFileName)(f)),
202
196
  force: constants_1.IS_DEV,
203
197
  abortOnFail: false,
204
198
  data: __assign(__assign({}, constants_1.EXTRA_TEMPLATE_VARIABLES), templateData),
205
199
  }); });
206
200
  }
207
- var configFileNamesMap = {
208
- gitignore: '.gitignore',
209
- npmrc: '.npmrc',
210
- _eslintrc: '.eslintrc',
211
- '_package.json': 'package.json',
212
- };
213
201
  function isFile(path) {
214
202
  try {
215
203
  return fs_1.default.lstatSync(path).isFile();
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isFileStartingWith = exports.removeFilesInCwd = exports.getOnlyNotExistingInCwd = exports.getOnlyExistingInCwd = exports.readJsonFile = exports.isFile = exports.filterOutCommonFiles = void 0;
6
+ exports.isFileStartingWith = exports.getExportFileName = exports.removeFilesInCwd = exports.getOnlyNotExistingInCwd = exports.getOnlyExistingInCwd = exports.readJsonFile = exports.isFile = exports.filterOutCommonFiles = void 0;
7
7
  var path_1 = __importDefault(require("path"));
8
8
  var fs_1 = __importDefault(require("fs"));
9
9
  var constants_1 = require("../constants");
@@ -52,6 +52,20 @@ function removeFilesInCwd(files) {
52
52
  }
53
53
  }
54
54
  exports.removeFilesInCwd = removeFilesInCwd;
55
+ function getExportFileName(f) {
56
+ var baseName = path_1.default.basename(f);
57
+ if (Object.keys(configFileNamesMap).includes(baseName)) {
58
+ return configFileNamesMap[baseName];
59
+ }
60
+ return path_1.default.extname(f) === '.hbs' ? path_1.default.basename(f, '.hbs') : baseName;
61
+ }
62
+ exports.getExportFileName = getExportFileName;
63
+ var configFileNamesMap = {
64
+ gitignore: '.gitignore',
65
+ npmrc: '.npmrc',
66
+ _eslintrc: '.eslintrc',
67
+ '_package.json': 'package.json',
68
+ };
55
69
  function isFileStartingWith(file, filter) {
56
70
  if (Array.isArray(filter)) {
57
71
  return filter.some(function (f) { return file.startsWith(f); });
@@ -33,6 +33,7 @@ var utils_handlebars_1 = require("./utils.handlebars");
33
33
  var utils_plugin_1 = require("./utils.plugin");
34
34
  var constants_1 = require("../constants");
35
35
  var utils_packageManager_1 = require("./utils.packageManager");
36
+ var utils_files_2 = require("../utils/utils.files");
36
37
  function getTemplateFiles(pluginType, filter) {
37
38
  var commonFiles = glob_1.default.sync("".concat(constants_1.TEMPLATE_PATHS.common, "/**"), { dot: true });
38
39
  var pluginTypeSpecificFiles = glob_1.default.sync("".concat(constants_1.TEMPLATE_PATHS[pluginType], "/**"), { dot: true });
@@ -61,7 +62,7 @@ function compileSingleTemplateFile(pluginType, templateFile, data) {
61
62
  }
62
63
  var rendered = renderTemplateFromFile(templateFile, data);
63
64
  var relativeExportPath = templateFile.replace(constants_1.TEMPLATE_PATHS.common, '').replace(constants_1.TEMPLATE_PATHS[pluginType], '');
64
- var exportPath = path_1.default.join(constants_1.EXPORT_PATH_PREFIX, relativeExportPath);
65
+ var exportPath = path_1.default.join(constants_1.EXPORT_PATH_PREFIX, path_1.default.dirname(relativeExportPath), (0, utils_files_2.getExportFileName)(templateFile));
65
66
  mkdirp_1.default.sync(path_1.default.dirname(exportPath));
66
67
  fs_1.default.writeFileSync(exportPath, rendered);
67
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/create-plugin",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "directory": "packages/create-plugin",
@@ -66,5 +66,5 @@
66
66
  "engines": {
67
67
  "node": ">=18"
68
68
  },
69
- "gitHead": "37c4128d0cbf095ba8644938b0b503566029d0bf"
69
+ "gitHead": "2ea414b13f32a3e9e0e68c703e5d8cf6ff0c08d9"
70
70
  }
@@ -10,6 +10,7 @@ import { printGenerateSuccessMessage } from './generate-actions/print-success-me
10
10
  import { updateGoSdkAndModules } from './generate-actions/update-go-sdk-and-packages';
11
11
  import { prettifyFiles } from './generate-actions/prettify-files';
12
12
  import { CliArgs, TemplateData } from './types';
13
+ import { getExportFileName } from '../utils/utils.files';
13
14
 
14
15
  // Plopfile API documentation: https://plopjs.com/documentation/#plopfile-api
15
16
  export default function (plop: NodePlopAPI) {
@@ -236,16 +237,6 @@ function getActionsForTemplateFolder({
236
237
  files = files.filter((file) => path.basename(file) !== 'npmrc');
237
238
  }
238
239
 
239
- function getExportFileName(f: string) {
240
- const baseName = path.basename(f);
241
-
242
- if (Object.keys(configFileNamesMap).includes(baseName)) {
243
- return configFileNamesMap[baseName];
244
- }
245
-
246
- return path.extname(f) === '.hbs' ? path.basename(f, '.hbs') : baseName;
247
- }
248
-
249
240
  function getExportPath(f: string) {
250
241
  return path.relative(folderPath, path.dirname(f));
251
242
  }
@@ -266,16 +257,6 @@ function getActionsForTemplateFolder({
266
257
  }));
267
258
  }
268
259
 
269
- // yarn and npm packing will not include `.gitignore` files
270
- // so we have to manually rename them to add the dot prefix
271
- // other config files trip up the tooling in the plugin-tools monorepo
272
- const configFileNamesMap: Record<string, string> = {
273
- gitignore: '.gitignore',
274
- npmrc: '.npmrc',
275
- _eslintrc: '.eslintrc',
276
- '_package.json': 'package.json',
277
- };
278
-
279
260
  function isFile(path: string) {
280
261
  try {
281
262
  return fs.lstatSync(path).isFile();
@@ -50,6 +50,26 @@ export function removeFilesInCwd(files: string[]) {
50
50
  }
51
51
  }
52
52
 
53
+ export function getExportFileName(f: string) {
54
+ const baseName = path.basename(f);
55
+
56
+ if (Object.keys(configFileNamesMap).includes(baseName)) {
57
+ return configFileNamesMap[baseName];
58
+ }
59
+
60
+ return path.extname(f) === '.hbs' ? path.basename(f, '.hbs') : baseName;
61
+ }
62
+
63
+ // yarn and npm packing will not include `.gitignore` files
64
+ // so we have to manually rename them to add the dot prefix
65
+ // other config files trip up the tooling in the plugin-tools monorepo
66
+ const configFileNamesMap: Record<string, string> = {
67
+ gitignore: '.gitignore',
68
+ npmrc: '.npmrc',
69
+ _eslintrc: '.eslintrc',
70
+ '_package.json': 'package.json',
71
+ };
72
+
53
73
  /**
54
74
  * Returns TRUE if the file is starting with any of the provided string filters.
55
75
  *
@@ -7,6 +7,7 @@ import { renderHandlebarsTemplate } from './utils.handlebars';
7
7
  import { getPluginJson } from './utils.plugin';
8
8
  import { TEMPLATE_PATHS, EXPORT_PATH_PREFIX, EXTRA_TEMPLATE_VARIABLES } from '../constants';
9
9
  import { getPackageManagerWithFallback } from './utils.packageManager';
10
+ import { getExportFileName } from '../utils/utils.files';
10
11
 
11
12
  /**
12
13
  *
@@ -52,7 +53,7 @@ export function compileSingleTemplateFile(pluginType: string, templateFile: stri
52
53
 
53
54
  const rendered = renderTemplateFromFile(templateFile, data);
54
55
  const relativeExportPath = templateFile.replace(TEMPLATE_PATHS.common, '').replace(TEMPLATE_PATHS[pluginType], '');
55
- const exportPath = path.join(EXPORT_PATH_PREFIX, relativeExportPath);
56
+ const exportPath = path.join(EXPORT_PATH_PREFIX, path.dirname(relativeExportPath), getExportFileName(templateFile));
56
57
 
57
58
  mkdirp.sync(path.dirname(exportPath));
58
59
  fs.writeFileSync(exportPath, rendered);