@oak-digital/types-4-strapi-2 0.2.5 → 0.2.6

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/README.md CHANGED
@@ -48,9 +48,15 @@ This can be done with the `--out` flag like in the following example.
48
48
  * Support for localization
49
49
  * Support if you are using other plugins, such as `url-alias`, which should add extra fields for some interfaces.
50
50
 
51
- ## Help
52
-
53
- use `t4s --help` to display which options are available for you
51
+ ## Flags
52
+
53
+ | **flag** | **Description** |
54
+ |-----------------------------|------------------------------------------------------------------------------------|
55
+ | -i, --in <dir> | The src directory for strapi |
56
+ | -o, --out <dir> | The output directory to output the types to |
57
+ | --component-prefix <prefix> | A prefix for components |
58
+ | -D, --delete-old | CAUTION: This option is equivalent to running rm -rf on the output directory first |
59
+ | --prettier <file> | The prettier config file to use for formatting typescript interfaces |
54
60
 
55
61
  ## Building
56
62
 
package/lib/index.js CHANGED
@@ -11,13 +11,15 @@ commander_1.program
11
11
  .option('-i, --in <dir>', 'The src directory for strapi', './src')
12
12
  .option('-o, --out <dir>', 'The output directory to output the types to', './types')
13
13
  .option('--component-prefix <prefix>', 'A prefix for components', '')
14
+ .option('-D, --delete-old', 'CAUTION: This option is equivalent to running rm -rf on the output directory first')
14
15
  .option('--prettier <file>', 'The prettier config file to use for formatting typescript interfaces');
15
16
  commander_1.program.parse();
16
17
  var options = commander_1.program.opts();
17
- var input = options.in, out = options.out, componentPrefix = options.componentPrefix, prettierFile = options.prettier;
18
+ var input = options.in, out = options.out, componentPrefix = options.componentPrefix, prettierFile = options.prettier, deleteOld = options.deleteOld;
18
19
  var manager = new InterfaceManager_1.default(out, input, {
19
20
  componentPrefix: componentPrefix,
20
21
  prettierFile: prettierFile,
22
+ deleteOld: deleteOld,
21
23
  });
22
24
  manager.run().catch(function (err) {
23
25
  console.error(err);
@@ -11,6 +11,7 @@ export default class InterfaceManager {
11
11
  componentPrefixOverridesPrefix: boolean;
12
12
  builtinsPrefix: string;
13
13
  builtinsPrefixOverridesPrefix: boolean;
14
+ deleteOld: boolean;
14
15
  prettierFile: any;
15
16
  };
16
17
  constructor(outRoot: string, strapiSrcRoot: string, options?: any);
@@ -18,6 +19,7 @@ export default class InterfaceManager {
18
19
  createInterfaces(): Promise<void>;
19
20
  createBuiltinInterfaces(): void;
20
21
  injectDependencies(): void;
22
+ deleteOldFolders(): Promise<void>;
21
23
  makeFolders(): Promise<void>;
22
24
  writeInterfaces(): Promise<void>;
23
25
  writeIndexFile(): Promise<void>;
@@ -140,23 +140,44 @@ var InterfaceManager = /** @class */ (function () {
140
140
  inter.setRelations(interfacesToInject);
141
141
  });
142
142
  };
143
+ InterfaceManager.prototype.deleteOldFolders = function () {
144
+ return __awaiter(this, void 0, void 0, function () {
145
+ return __generator(this, function (_a) {
146
+ switch (_a.label) {
147
+ case 0: return [4 /*yield*/, (0, promises_1.rm)(this.OutRoot, {
148
+ force: true,
149
+ recursive: true,
150
+ })];
151
+ case 1:
152
+ _a.sent();
153
+ return [2 /*return*/];
154
+ }
155
+ });
156
+ });
157
+ };
143
158
  InterfaceManager.prototype.makeFolders = function () {
144
159
  return __awaiter(this, void 0, void 0, function () {
145
160
  var componentCategories, promises, componentCategoriesPromises, builtinsPath;
146
161
  var _this = this;
147
162
  return __generator(this, function (_a) {
148
163
  switch (_a.label) {
149
- case 0: return [4 /*yield*/, (0, schemaReader_1.getComponentCategoryFolders)(this.StrapiSrcRoot)];
164
+ case 0:
165
+ if (!this.Options.deleteOld) return [3 /*break*/, 2];
166
+ return [4 /*yield*/, this.deleteOldFolders()];
150
167
  case 1:
168
+ _a.sent();
169
+ _a.label = 2;
170
+ case 2: return [4 /*yield*/, (0, schemaReader_1.getComponentCategoryFolders)(this.StrapiSrcRoot)];
171
+ case 3:
151
172
  componentCategories = _a.sent();
152
- if (!!(0, fs_1.existsSync)(this.OutRoot)) return [3 /*break*/, 3];
173
+ if (!!(0, fs_1.existsSync)(this.OutRoot)) return [3 /*break*/, 5];
153
174
  return [4 /*yield*/, (0, promises_1.mkdir)(this.OutRoot, {
154
175
  recursive: true,
155
176
  })];
156
- case 2:
177
+ case 4:
157
178
  _a.sent();
158
- _a.label = 3;
159
- case 3:
179
+ _a.label = 5;
180
+ case 5:
160
181
  promises = [];
161
182
  componentCategoriesPromises = componentCategories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
162
183
  var path;
@@ -180,7 +201,7 @@ var InterfaceManager = /** @class */ (function () {
180
201
  promises.push((0, promises_1.mkdir)((0, posix_1.join)(this.OutRoot, 'builtins')));
181
202
  }
182
203
  return [4 /*yield*/, Promise.all(promises)];
183
- case 4:
204
+ case 6:
184
205
  _a.sent();
185
206
  return [2 /*return*/];
186
207
  }
@@ -279,6 +300,7 @@ var InterfaceManager = /** @class */ (function () {
279
300
  componentPrefixOverridesPrefix: false,
280
301
  builtinsPrefix: '',
281
302
  builtinsPrefixOverridesPrefix: false,
303
+ deleteOld: false,
282
304
  prettierFile: null,
283
305
  };
284
306
  return InterfaceManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oak-digital/types-4-strapi-2",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Typescript interface generator for Strapi 4 models",
5
5
  "bin": {
6
6
  "t4s": "./bin/index.js"