create-powerapps-project 0.16.6 → 0.17.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/CHANGELOG.json CHANGED
@@ -2,7 +2,22 @@
2
2
  "name": "create-powerapps-project",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 16 Feb 2022 00:36:07 GMT",
5
+ "date": "Thu, 17 Feb 2022 01:02:44 GMT",
6
+ "tag": "create-powerapps-project_v0.17.0",
7
+ "version": "0.17.0",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "author": "derek.finlinson@journeyteam.com",
12
+ "package": "create-powerapps-project",
13
+ "commit": "205f5973d29c92d19c7e2f5154e01a784c2fe58b",
14
+ "comment": "Switch to wrapping plop"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Wed, 16 Feb 2022 00:36:25 GMT",
6
21
  "tag": "create-powerapps-project_v0.16.6",
7
22
  "version": "0.16.6",
8
23
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,17 +1,25 @@
1
1
  # Change Log - create-powerapps-project
2
2
 
3
- This log was last generated on Wed, 16 Feb 2022 00:36:07 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 17 Feb 2022 01:02:44 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## 0.16.6
7
+ ## 0.17.0
8
8
 
9
- Wed, 16 Feb 2022 00:36:07 GMT
9
+ Thu, 17 Feb 2022 01:02:44 GMT
10
10
 
11
- ### Patches
11
+ ### Minor changes
12
12
 
13
- - Re-add sn.exe; React PCF updates (derek.finlinson@journeyteam.com)
13
+ - Switch to wrapping plop (derek.finlinson@journeyteam.com)
14
14
 
15
+ ## 0.16.6
16
+
17
+ Wed, 16 Feb 2022 00:36:25 GMT
18
+
19
+ ### Patches
20
+
21
+ - Re-add sn.exe; React PCF updates (derek.finlinson@journeyteam.com)
22
+
15
23
  ## 0.16.5
16
24
 
17
25
  Mon, 14 Feb 2022 23:29:54 GMT
package/lib/getEnvInfo.js CHANGED
@@ -23,7 +23,6 @@ const initialize = async () => {
23
23
  if (envInfoCache.Binaries.npm) {
24
24
  envInfoCache.Binaries.npm.path = expandHome(envInfoCache.Binaries.npm.path);
25
25
  }
26
- return envInfoCache;
27
26
  };
28
27
  exports.initialize = initialize;
29
28
  const expandHome = (pathString) => {
package/lib/index.js CHANGED
@@ -4,20 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- const commander_1 = require("commander");
8
- const createDataverseProject_1 = __importDefault(require("./createDataverseProject"));
9
- // eslint-disable-next-line @typescript-eslint/no-var-requires
10
- const packageJson = require('../package');
11
- const program = new commander_1.Command(packageJson.name);
12
- program
13
- .version(packageJson.version)
14
- .description('Create new Dataverse project')
15
- .usage('[type]')
16
- .argument('[type]', 'Type of project to generate')
17
- .action(type => {
18
- (0, createDataverseProject_1.default)(type);
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const plop_1 = require("plop");
9
+ plop_1.Plop.launch({
10
+ cwd: process.cwd(),
11
+ configPath: node_path_1.default.join(__dirname, 'plopfile.js')
12
+ }, env => {
13
+ const options = {
14
+ ...env,
15
+ dest: process.cwd() // this will make the destination path to be based on the cwd when calling the wrapper
16
+ };
17
+ return (0, plop_1.run)(options, undefined, true);
19
18
  });
20
- program.parse(process.argv);
21
- if (!process.argv.slice(1).length) {
22
- program.outputHelp();
23
- }
package/lib/nuget.js CHANGED
@@ -37,12 +37,10 @@ const install = (project, sdkVersion, xrmVersion) => {
37
37
  stdio: 'inherit'
38
38
  });
39
39
  // Install nuget packages
40
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
41
40
  (0, child_process_1.spawnSync)('dotnet', ['add', 'package', 'Microsoft.CrmSdk.Workflow', '-v', sdkVersion, '-n'], {
42
41
  cwd: process.cwd(),
43
42
  stdio: 'inherit'
44
43
  });
45
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
46
44
  (0, child_process_1.spawnSync)('dotnet', ['add', 'package', 'JourneyTeam.Xrm', '-v', xrmVersion, '-n'], {
47
45
  cwd: process.cwd(),
48
46
  stdio: 'inherit'
package/lib/plopfile.js CHANGED
@@ -1,4 +1,23 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
23
  };
@@ -6,10 +25,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
25
  const path_1 = __importDefault(require("path"));
7
26
  const child_process_1 = require("child_process");
8
27
  const fs_1 = __importDefault(require("fs"));
28
+ const nuget = __importStar(require("./nuget"));
29
+ const pkg = __importStar(require("./packageManager"));
30
+ const getEnvInfo_1 = require("./getEnvInfo");
9
31
  const didSucceed = (code) => `${code}` === '0';
10
32
  /* eslint-disable @typescript-eslint/no-explicit-any */
11
33
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
12
34
  exports.default = (plop) => {
35
+ void (0, getEnvInfo_1.initialize)();
13
36
  plop.setActionType('signAssembly', (answers) => {
14
37
  const keyPath = path_1.default.resolve(process.cwd(), `${answers.name}.snk`);
15
38
  return new Promise((resolve, reject) => {
@@ -22,9 +45,12 @@ exports.default = (plop) => {
22
45
  resolve('signed assembly');
23
46
  }
24
47
  else {
25
- reject('Failed to sign assembly');
48
+ reject('failed to sign assembly');
26
49
  }
27
50
  });
51
+ sign.on('error', () => {
52
+ reject('failed to sign assembly');
53
+ });
28
54
  });
29
55
  });
30
56
  plop.setActionType('runPcf', (answers) => {
@@ -46,6 +72,9 @@ exports.default = (plop) => {
46
72
  reject('Ensure the Power Platform CLI is installed. Command must be run from within VS Code if using the Power Platform Extension');
47
73
  }
48
74
  });
75
+ pac.on('error', () => {
76
+ reject('Ensure the Power Platform CLI is installed. Command must be run from within VS Code if using the Power Platform Extension');
77
+ });
49
78
  });
50
79
  });
51
80
  plop.setActionType('addGenScript', async () => {
@@ -56,7 +85,52 @@ exports.default = (plop) => {
56
85
  await fs_1.default.promises.writeFile(packagePath, JSON.stringify(packageJson, null, 4), 'utf8');
57
86
  return 'added plop script to package.json';
58
87
  });
88
+ plop.setActionType('nugetInstall', async (answers) => {
89
+ const xrmVersions = await nuget.getNugetPackageVersions('JourneyTeam.Xrm');
90
+ const xrmVersion = xrmVersions.shift();
91
+ nuget.install(answers.name, answers.sdkVersion, xrmVersion);
92
+ return 'installed nuget packages';
93
+ });
94
+ plop.setActionType('npmInstall', (_answers, config) => {
95
+ if (config?.projectType) {
96
+ pkg.install(process.cwd(), config.projectType);
97
+ }
98
+ return 'installed npm packages';
99
+ });
100
+ const connectionQuestions = [
101
+ {
102
+ type: 'input',
103
+ name: 'server',
104
+ message: 'enter dataverse url (https://org.crm.dynamics.com):'
105
+ },
106
+ {
107
+ type: 'input',
108
+ name: 'tenant',
109
+ message: 'enter azure ad tenant (org.onmicrosoft.com):',
110
+ default: 'common'
111
+ },
112
+ {
113
+ type: 'input',
114
+ name: 'solution',
115
+ message: 'dataverse solution unique name:'
116
+ }
117
+ ];
59
118
  plop.setGenerator('webresource', {
119
+ description: 'generate dataverse web resource project',
120
+ prompts: [
121
+ {
122
+ type: 'input',
123
+ name: 'name',
124
+ message: 'project name',
125
+ default: path_1.default.basename(process.cwd())
126
+ },
127
+ {
128
+ type: 'input',
129
+ name: 'namespace',
130
+ message: 'namespace for form and ribbon scripts:'
131
+ },
132
+ ...connectionQuestions
133
+ ],
60
134
  actions: [
61
135
  {
62
136
  type: 'addMany',
@@ -64,10 +138,44 @@ exports.default = (plop) => {
64
138
  base: '../plop-templates/webresource',
65
139
  destination: process.cwd(),
66
140
  force: true
141
+ },
142
+ {
143
+ type: 'npmInstall',
144
+ projectType: 'webresource',
145
+ skip: (answers) => {
146
+ return !answers.react;
147
+ }
67
148
  }
68
149
  ]
69
150
  });
70
151
  plop.setGenerator('pcf', {
152
+ description: 'generate dataverse pcf project',
153
+ prompts: [
154
+ {
155
+ type: 'list',
156
+ name: 'template',
157
+ message: 'template',
158
+ choices: [
159
+ { name: 'field', value: 'field' },
160
+ { name: 'dataset', value: 'dataset' }
161
+ ]
162
+ },
163
+ {
164
+ type: 'input',
165
+ name: 'namespace',
166
+ message: 'namespace'
167
+ },
168
+ {
169
+ type: 'input',
170
+ name: 'name',
171
+ message: 'name'
172
+ },
173
+ {
174
+ type: 'confirm',
175
+ name: 'react',
176
+ message: 'use react?'
177
+ }
178
+ ],
71
179
  actions: [
72
180
  {
73
181
  type: 'runPcf'
@@ -101,7 +209,8 @@ exports.default = (plop) => {
101
209
  }
102
210
  },
103
211
  {
104
- type: 'updateTsConfig',
212
+ type: 'npmInstall',
213
+ projectType: 'pcf',
105
214
  skip: (answers) => {
106
215
  return !answers.react;
107
216
  }
@@ -109,6 +218,40 @@ exports.default = (plop) => {
109
218
  ]
110
219
  });
111
220
  plop.setGenerator('assembly', {
221
+ description: 'generate dataverse assembly project',
222
+ prompts: [
223
+ {
224
+ type: 'list',
225
+ name: 'sdkVersion',
226
+ message: 'select sdk version',
227
+ choices: async () => {
228
+ const versions = await nuget.getNugetPackageVersions('Microsoft.CrmSdk.Workflow');
229
+ return versions.map(v => ({ name: v, value: v }));
230
+ }
231
+ },
232
+ {
233
+ type: 'input',
234
+ name: 'name',
235
+ message: 'default C# namespace (Company.Crm.Plugins):'
236
+ },
237
+ {
238
+ type: 'list',
239
+ name: 'isolation',
240
+ message: 'select isolation mode',
241
+ default: 2,
242
+ choices: [
243
+ {
244
+ name: 'sandbox',
245
+ value: 2
246
+ },
247
+ {
248
+ name: 'none',
249
+ value: 1
250
+ }
251
+ ]
252
+ },
253
+ ...connectionQuestions,
254
+ ],
112
255
  actions: [
113
256
  {
114
257
  type: 'add',
@@ -132,6 +275,13 @@ exports.default = (plop) => {
132
275
  },
133
276
  {
134
277
  type: 'signAssembly'
278
+ },
279
+ {
280
+ type: 'nugetInstall'
281
+ },
282
+ {
283
+ type: 'npmInstall',
284
+ projectType: 'assembly'
135
285
  }
136
286
  ]
137
287
  });
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "create-powerapps-project",
3
3
  "description": "💧 plop generator for Dataverse development",
4
- "version": "0.16.6",
4
+ "version": "0.17.0",
5
5
  "license": "MIT",
6
+ "type": "commonjs",
6
7
  "main": "lib/index.js",
7
8
  "bin": {
8
9
  "create-powerapps-project": "lib/index.js"
@@ -22,15 +23,11 @@
22
23
  "clean": "rimraf lib"
23
24
  },
24
25
  "dependencies": {
25
- "commander": "^8.3.0",
26
26
  "envinfo": "^7.8.1",
27
- "kleur": "^4.1.4",
28
- "node-plop": "^0.26.3",
29
- "prompts": "^2.4.2"
27
+ "plop": "^2.7.6"
30
28
  },
31
29
  "devDependencies": {
32
30
  "@types/envinfo": "^7.8.1",
33
- "@types/node": "^14.14.21",
34
- "@types/prompts": "^2.0.14"
31
+ "@types/node": "^14.14.21"
35
32
  }
36
33
  }
@@ -2,6 +2,7 @@
2
2
  "version": "1.0.0",
3
3
  "name": "{{kebabCase name}}",
4
4
  "private": true,
5
+ "type": "commonjs",
5
6
  "scripts": {
6
7
  "gen": "plop",
7
8
  "deploy": "dataverse-utils deploy assembly"
@@ -45,7 +45,7 @@ export class {{name}} implements ComponentFramework.StandardControl<IInputs, IOu
45
45
  };
46
46
 
47
47
  ReactDOM.render(
48
- React.createElement(App, AppProps),
48
+ React.createElement(App, this.props),
49
49
  this.container
50
50
  );
51
51
  }
@@ -2,6 +2,7 @@
2
2
  "version": "1.0.0",
3
3
  "name": "{{kebabCase name}}",
4
4
  "private": true,
5
+ "type": "commonjs",
5
6
  "scripts": {
6
7
  "build": "webpack --mode=production",
7
8
  "start": "webpack --mode=development --watch",
@@ -1,220 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.done = void 0;
26
- const prompts_1 = __importDefault(require("prompts"));
27
- const nuget_1 = require("./nuget");
28
- const path_1 = __importDefault(require("path"));
29
- const plop_1 = require("./plop");
30
- const pkg = __importStar(require("./packageManager"));
31
- const getEnvInfo_1 = require("./getEnvInfo");
32
- const logger_1 = require("./logger");
33
- exports.default = async (type) => {
34
- await (0, getEnvInfo_1.initialize)();
35
- const name = path_1.default.basename(process.cwd());
36
- if (!type || (type !== 'webresource' && type !== 'assembly' && type !== 'pcf')) {
37
- const invalid = type !== undefined && type !== 'webresource' && type !== 'assembly' && type !== 'pcf';
38
- const invalidMessage = invalid ? `${type} is not a valid project type.` : '';
39
- const { promptType } = await (0, prompts_1.default)({
40
- type: 'select',
41
- name: 'promptType',
42
- message: `${invalidMessage} Select dataverse project to create?`,
43
- choices: [
44
- { title: 'web resource', value: 'webresource' },
45
- { title: 'plugin or workflow activity', value: 'assembly' },
46
- { title: 'powerapps component framework control', value: 'pcf' }
47
- ]
48
- });
49
- type = promptType;
50
- }
51
- const questions = await getAnswers(type);
52
- const config = (await (0, prompts_1.default)(questions));
53
- if (type === 'assembly') {
54
- const xrmVersions = await (0, nuget_1.getNugetPackageVersions)('JourneyTeam.Xrm');
55
- config.xrmVersion = xrmVersions.shift();
56
- }
57
- else if (type === 'webresource') {
58
- config.name = name;
59
- }
60
- const generator = await (0, plop_1.getGenerator)(type, name);
61
- logger_1.logger.info(`run powerapps-project-${type} code generator`);
62
- try {
63
- await (0, plop_1.runGenerator)(generator, config);
64
- }
65
- catch (ex) {
66
- logger_1.logger.error(ex.message);
67
- return;
68
- }
69
- logger_1.logger.info('initialize project');
70
- if (type !== 'pcf' || config.react) {
71
- pkg.install(process.cwd(), type);
72
- }
73
- if (type === 'assembly') {
74
- logger_1.logger.info('add nuget packages');
75
- (0, nuget_1.install)(config.name, config.sdkVersion, config.xrmVersion);
76
- }
77
- (0, exports.done)(type);
78
- };
79
- const getAnswers = async (type) => {
80
- let questions = [];
81
- if (type === 'pcf') {
82
- questions = [
83
- {
84
- type: 'select',
85
- name: 'template',
86
- message: 'template',
87
- choices: [
88
- { title: 'field', value: 'field' },
89
- { title: 'dataset', value: 'dataset' }
90
- ]
91
- },
92
- {
93
- type: 'text',
94
- name: 'namespace',
95
- message: 'namespace'
96
- },
97
- {
98
- type: 'text',
99
- name: 'name',
100
- message: 'name'
101
- },
102
- {
103
- type: 'confirm',
104
- name: 'react',
105
- message: 'install react?'
106
- }
107
- ];
108
- return questions;
109
- }
110
- if (type === 'webresource') {
111
- questions.push({
112
- type: 'text',
113
- name: 'namespace',
114
- message: 'namespace for form and ribbon scripts:'
115
- });
116
- }
117
- else {
118
- const versions = await (0, nuget_1.getNugetPackageVersions)('Microsoft.CrmSdk.Workflow');
119
- questions = [
120
- {
121
- type: 'select',
122
- name: 'sdkVersion',
123
- message: 'select sdk version',
124
- choices: versions.map(v => ({ title: v, value: v }))
125
- },
126
- {
127
- type: 'text',
128
- name: 'name',
129
- message: 'default namespace'
130
- },
131
- {
132
- type: 'select',
133
- name: 'isolation',
134
- message: 'select isolation mode',
135
- initial: 0,
136
- choices: [
137
- {
138
- title: 'sandbox',
139
- value: 2
140
- },
141
- {
142
- title: 'none',
143
- value: 1
144
- }
145
- ]
146
- }
147
- ];
148
- }
149
- questions = [
150
- ...questions,
151
- {
152
- type: 'text',
153
- name: 'server',
154
- message: 'enter dataverse url (https://org.crm.dynamics.com):'
155
- },
156
- {
157
- type: 'text',
158
- name: 'tenant',
159
- message: 'enter azure ad tenant (org.onmicrosoft.com):'
160
- },
161
- {
162
- type: 'text',
163
- name: 'solution',
164
- message: 'dataverse solution unique name:'
165
- }
166
- ];
167
- return questions;
168
- };
169
- const done = (type) => {
170
- if (process.env.JEST_WORKER_ID !== undefined) {
171
- return;
172
- }
173
- let message;
174
- if (type === 'pcf') {
175
- message = `
176
-
177
- ${logger_1.icons.done} ${type} project created!
178
-
179
- keep your build tools up-to-date by updating these two devDependencies:
180
- ${logger_1.icons.info} powerapps-project-${type}
181
-
182
- build your project in watch mode with this command:
183
- ${logger_1.icons.info} npm start watch
184
- build your project in production mode with this command:
185
- ${logger_1.icons.info} npm run build
186
-
187
- run code generator with this command:
188
- ${logger_1.icons.info} npm run gen
189
-
190
- `;
191
- }
192
- else {
193
- message = `
194
-
195
- ${logger_1.icons.done} ${type} project created!
196
-
197
- keep your build tools up-to-date by updating these two devDependencies:
198
- ${logger_1.icons.info} dataverse-utils
199
- ${logger_1.icons.info} powerapps-project-${type}
200
-
201
- ${type === 'webresource' ?
202
- `build your project in watch mode with this command:
203
- ${logger_1.icons.info} ${pkg.getYarn() ? 'yarn' : 'npm run'} start
204
- build your project in production mode with this command:
205
- ${logger_1.icons.info} ${pkg.getYarn() ? 'yarn' : 'npm run'} build
206
- generate table definition files with this command:
207
- ${logger_1.icons.info} ${pkg.getYarn() ? 'yarn' : 'npm run'} generate` :
208
- `build your project with this command:
209
- dotnet build
210
- deploy your project with this command:
211
- ${logger_1.icons.info} ${pkg.getYarn() ? 'yarn' : 'npm run'} deploy`}
212
-
213
- run code generator with this command:
214
- ${logger_1.icons.info} ${pkg.getYarn() ? 'yarn' : 'npm run'} gen
215
-
216
- `;
217
- }
218
- console.info(message);
219
- };
220
- exports.done = done;
package/lib/logger.js DELETED
@@ -1,36 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.logger = exports.icons = void 0;
7
- const kleur_1 = __importDefault(require("kleur"));
8
- const isTest = process.env.JEST_WORKER_ID !== undefined;
9
- exports.icons = {
10
- done: kleur_1.default.green('◉'),
11
- info: kleur_1.default.cyan('◎'),
12
- error: kleur_1.default.red('⨂'),
13
- warn: kleur_1.default.yellow('⨁')
14
- };
15
- exports.logger = {
16
- info(...args) {
17
- if (!isTest) {
18
- console.info(exports.icons.info, ...args);
19
- }
20
- },
21
- warn(...args) {
22
- if (!isTest) {
23
- console.warn(exports.icons.warn, ...args);
24
- }
25
- },
26
- error(...args) {
27
- if (!isTest) {
28
- console.error(exports.icons.error, ...args);
29
- }
30
- },
31
- done(...args) {
32
- if (!isTest) {
33
- console.info(exports.icons.done, ...args);
34
- }
35
- },
36
- };
package/lib/plop.js DELETED
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.runGenerator = exports.getGenerator = void 0;
7
- const node_plop_1 = __importDefault(require("node-plop"));
8
- const path_1 = __importDefault(require("path"));
9
- const logger_1 = require("./logger");
10
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
- const getGenerator = async (type, name) => {
12
- let plopFile = path_1.default.resolve(__dirname, 'plopfile.js');
13
- if (process.env.JEST_WORKER_ID !== undefined) {
14
- plopFile = path_1.default.resolve(__dirname, 'plopfile.ts');
15
- }
16
- const plop = (0, node_plop_1.default)(plopFile, { destBasePath: name, force: false });
17
- const generator = plop.getGenerator(type);
18
- return generator;
19
- };
20
- exports.getGenerator = getGenerator;
21
- const runGenerator = async (generator, args) => {
22
- const results = await generator.runActions(args, {
23
- onComment: (comment) => {
24
- logger_1.logger.info(comment);
25
- }
26
- });
27
- if (results.failures && results.failures.length > 0) {
28
- throw new Error(results.failures[0].error);
29
- }
30
- // do something after the actions have run
31
- for (const change of results.changes) {
32
- if (change.path) {
33
- logger_1.logger.done(change.path);
34
- }
35
- }
36
- };
37
- exports.runGenerator = runGenerator;