1 |
|
2 | const chalk = require('chalk');
|
3 | const path = require('path');
|
4 |
|
5 | const readFile = require('./utils/read-file');
|
6 | const toStatefulTransform = require('./transforms/to-stateful');
|
7 | const validateFilePath = require('./utils/validate-file-path');
|
8 | const writeFile = require('./utils/write-file');
|
9 |
|
10 | module.exports = function({ eslintConfig, filePath }) {
|
11 | return new Promise((resolve, reject) => {
|
12 | try {
|
13 | validateFilePath(filePath);
|
14 |
|
15 | const componentName = path.basename(filePath, '.jsx');
|
16 | const fileContent = readFile(filePath);
|
17 |
|
18 | const newFileContent = toStatefulTransform(
|
19 | fileContent,
|
20 | componentName,
|
21 | eslintConfig
|
22 | );
|
23 |
|
24 | writeFile(filePath, newFileContent);
|
25 |
|
26 | resolve({
|
27 | messages: [
|
28 | { emoji: '🤖', text: `${chalk.green(`Beep boop, I'm done!`)}` }
|
29 | ]
|
30 | });
|
31 | } catch (error) {
|
32 | reject(error.message);
|
33 | }
|
34 | });
|
35 | };
|