UNPKG

931 BJavaScriptView Raw
1/* eslint-env node */
2const chalk = require('chalk');
3const path = require('path');
4
5const readFile = require('./utils/read-file');
6const toStatefulTransform = require('./transforms/to-stateful');
7const validateFilePath = require('./utils/validate-file-path');
8const writeFile = require('./utils/write-file');
9
10module.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};