|
1 |
| -import {CliConfig} from '../models/config'; |
| 1 | +import * as fs from 'fs'; |
| 2 | +import { CliConfig } from '../models/config'; |
| 3 | +import { oneLine } from 'common-tags'; |
2 | 4 |
|
3 | 5 | const SilentError = require('silent-error');
|
| 6 | +const chalk = require('chalk'); |
4 | 7 | const Command = require('../ember-cli/lib/models/command');
|
5 | 8 |
|
6 |
| - |
7 | 9 | export interface SetOptions {
|
8 | 10 | global?: boolean;
|
9 | 11 | }
|
@@ -67,13 +69,38 @@ const SetCommand = Command.extend({
|
67 | 69 | default: value = parseValue(rawValue, jsonPath);
|
68 | 70 | }
|
69 | 71 |
|
| 72 | + if (jsonPath.indexOf('prefix') > 0) { |
| 73 | + // update tslint if prefix is updated |
| 74 | + updateLintForPrefix(this.project.root + '/tslint.json', value); |
| 75 | + } |
| 76 | + |
70 | 77 | config.set(jsonPath, value);
|
71 | 78 | config.save();
|
72 | 79 | resolve();
|
73 | 80 | });
|
74 | 81 | }
|
75 | 82 | });
|
76 | 83 |
|
| 84 | +function updateLintForPrefix(filePath: string, prefix: string): void { |
| 85 | + const tsLint = JSON.parse(fs.readFileSync(filePath, 'utf8')); |
| 86 | + const componentLint = tsLint.rules['component-selector'][2]; |
| 87 | + if (componentLint instanceof Array) { |
| 88 | + tsLint.rules['component-selector'][2].push(prefix); |
| 89 | + } else { |
| 90 | + tsLint.rules['component-selector'][2] = prefix; |
| 91 | + } |
| 92 | + |
| 93 | + const directiveLint = tsLint.rules['directive-selector'][2]; |
| 94 | + if (directiveLint instanceof Array) { |
| 95 | + tsLint.rules['directive-selector'][2].push(prefix); |
| 96 | + } else { |
| 97 | + tsLint.rules['directive-selector'][2] = prefix; |
| 98 | + } |
| 99 | + fs.writeFileSync(filePath, JSON.stringify(tsLint, null, 2)); |
| 100 | + console.log(chalk.yellow(oneLine`we have updated tslint to match prefix, |
| 101 | + you may want to fix linting errors.`)); |
| 102 | +} |
| 103 | + |
77 | 104 | function parseValue(rawValue: string, path: string) {
|
78 | 105 | try {
|
79 | 106 | return JSON.parse(rawValue);
|
|
0 commit comments