|
| 1 | +import { execSync } from 'child_process'; |
| 2 | +import path from 'path'; |
| 3 | + |
| 4 | +import { outputFileSync, outputJsonSync, readFileSync } from 'fs-extra'; |
| 5 | +import inquirer from 'inquirer'; |
| 6 | + |
| 7 | +import eslintrcJson from '../.eslintrc.json'; |
| 8 | +import lernaJson from '../lerna.json'; |
| 9 | +import nxJson from '../nx.json'; |
| 10 | +import packageJson from '../package.json'; |
| 11 | +import tsconfigJson from '../tsconfig.base.json'; |
| 12 | +import workspaceJson from '../workspace.json'; |
| 13 | + |
| 14 | +const ROOT_PATH = path.join(__dirname, '..'); |
| 15 | +const VERSION = lernaJson.version; |
| 16 | + |
| 17 | +inquirer |
| 18 | + .prompt([ |
| 19 | + /* Pass your questions in here */ |
| 20 | + { |
| 21 | + type: 'confirm', |
| 22 | + name: 'toRun', |
| 23 | + message: 'I hope you know what you do!!!', |
| 24 | + default: false, |
| 25 | + }, |
| 26 | + ]) |
| 27 | + .then((answers) => { |
| 28 | + // Use user feedback for... whatever!! |
| 29 | + if (answers.toRun) { |
| 30 | + console.info('Updating...'); |
| 31 | + const eslintrcJsonPath = path.join(ROOT_PATH, '.eslintrc.json'); |
| 32 | + eslintrcJson.overrides.forEach((_, index) => { |
| 33 | + if (eslintrcJson.overrides[index].rules && eslintrcJson.overrides[index].rules!['@nrwl/nx/enforce-module-boundaries']) { |
| 34 | + delete eslintrcJson.overrides[index].rules!['@nrwl/nx/enforce-module-boundaries']; |
| 35 | + } |
| 36 | + }); |
| 37 | + outputJsonSync(eslintrcJsonPath, eslintrcJson); |
| 38 | + execSync(`yarn prettier ${eslintrcJsonPath} --write`); |
| 39 | + |
| 40 | + const lernaJsonPath = path.join(ROOT_PATH, 'lerna.json'); |
| 41 | + lernaJson.packages = []; |
| 42 | + lernaJson.version = '0.0.1'; |
| 43 | + outputJsonSync(lernaJsonPath, lernaJson); |
| 44 | + execSync(`yarn prettier ${lernaJsonPath} --write`); |
| 45 | + |
| 46 | + const nxJsonPath = path.join(ROOT_PATH, 'nx.json'); |
| 47 | + nxJson.defaultProject = 'platform'; |
| 48 | + outputJsonSync(nxJsonPath, nxJson); |
| 49 | + execSync(`yarn prettier ${nxJsonPath} --write`); |
| 50 | + |
| 51 | + const packageJsonPath = path.join(ROOT_PATH, 'package.json'); |
| 52 | + packageJson.devDependencies['@react-devui/hooks'] = VERSION; |
| 53 | + packageJson.devDependencies['@react-devui/icons'] = VERSION; |
| 54 | + packageJson.devDependencies['@react-devui/ui'] = VERSION; |
| 55 | + packageJson.devDependencies['@react-devui/utils'] = VERSION; |
| 56 | + outputJsonSync(packageJsonPath, packageJson); |
| 57 | + execSync(`yarn prettier ${packageJsonPath} --write`); |
| 58 | + |
| 59 | + const tsconfigJsonPath = path.join(ROOT_PATH, 'tsconfig.base.json'); |
| 60 | + tsconfigJson.compilerOptions.paths = {} as any; |
| 61 | + outputJsonSync(tsconfigJsonPath, tsconfigJson); |
| 62 | + execSync(`yarn prettier ${tsconfigJsonPath} --write`); |
| 63 | + |
| 64 | + const workspaceJsonPath = path.join(ROOT_PATH, 'workspace.json'); |
| 65 | + workspaceJson.projects = { platform: 'packages/platform' } as any; |
| 66 | + outputJsonSync(workspaceJsonPath, workspaceJson); |
| 67 | + execSync(`yarn prettier ${workspaceJsonPath} --write`); |
| 68 | + |
| 69 | + const webpackJsPath = path.join(ROOT_PATH, 'packages', 'platform', 'webpack.js'); |
| 70 | + const webpackJs = readFileSync(webpackJsPath, { encoding: 'utf8' }); |
| 71 | + outputFileSync(webpackJsPath, webpackJs.replace(/.*react-devui\/ui\/styles.*/g, '')); |
| 72 | + execSync(`yarn eslint ${webpackJsPath} --fix`); |
| 73 | + } |
| 74 | + }) |
| 75 | + .catch((error) => { |
| 76 | + if (error.isTtyError) { |
| 77 | + // Prompt couldn't be rendered in the current environment |
| 78 | + } else { |
| 79 | + // Something else went wrong |
| 80 | + } |
| 81 | + }); |
0 commit comments