|
|
@@ -13,6 +13,9 @@ import { bundlePlugin as bundleFn, PluginBundleOptions } from './plugin/bundle';
|
|
|
interface PluginBuildOptions {
|
|
|
coverage: boolean;
|
|
|
}
|
|
|
+interface Fixable {
|
|
|
+ fix?: boolean;
|
|
|
+}
|
|
|
|
|
|
export const bundlePlugin = useSpinner<PluginBundleOptions>('Compiling...', async options => await bundleFn(options));
|
|
|
|
|
|
@@ -60,7 +63,7 @@ const getStylesSources = () => {
|
|
|
return glob.sync(globPattern);
|
|
|
};
|
|
|
|
|
|
-const prettierCheckPlugin = useSpinner<void>('Prettier check', async () => {
|
|
|
+export const prettierCheckPlugin = useSpinner<Fixable>('Prettier check', async ({ fix }) => {
|
|
|
const prettierConfig = require(path.resolve(__dirname, '../../config/prettier.plugin.config.json'));
|
|
|
const sources = [...getStylesSources(), ...getTypescriptSources()];
|
|
|
|
|
|
@@ -72,14 +75,22 @@ const prettierCheckPlugin = useSpinner<void>('Prettier check', async () => {
|
|
|
throw new Error(err.message);
|
|
|
}
|
|
|
|
|
|
- if (
|
|
|
- !prettier.check(data.toString(), {
|
|
|
- ...prettierConfig,
|
|
|
- filepath: s,
|
|
|
- })
|
|
|
- ) {
|
|
|
- console.log('TODO eslint/prettier fix? ' + s);
|
|
|
- failed = false; //true;
|
|
|
+ const opts = {
|
|
|
+ ...prettierConfig,
|
|
|
+ filepath: s,
|
|
|
+ };
|
|
|
+ if (!prettier.check(data.toString(), opts)) {
|
|
|
+ if (fix) {
|
|
|
+ const fixed = prettier.format(data.toString(), opts);
|
|
|
+ fs.writeFile(s, fixed, err => {
|
|
|
+ if (err) {
|
|
|
+ console.log('Error fixing ' + s, err);
|
|
|
+ failed = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ failed = true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
resolve({
|
|
|
@@ -95,18 +106,19 @@ const prettierCheckPlugin = useSpinner<void>('Prettier check', async () => {
|
|
|
if (failures.length) {
|
|
|
console.log('\nFix Prettier issues in following files:');
|
|
|
failures.forEach(f => console.log(f.path));
|
|
|
+ console.log('\nRun toolkit:dev to fix errors');
|
|
|
throw new Error('Prettier failed');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// @ts-ignore
|
|
|
-export const lintPlugin = useSpinner<void>('Linting', async () => {
|
|
|
+export const lintPlugin = useSpinner<Fixable>('Linting', async ({ fix }) => {
|
|
|
let tsLintConfigPath = path.resolve(process.cwd(), 'tslint.json');
|
|
|
if (!fs.existsSync(tsLintConfigPath)) {
|
|
|
tsLintConfigPath = path.resolve(__dirname, '../../config/tslint.plugin.json');
|
|
|
}
|
|
|
const options = {
|
|
|
- fix: true, // or fail
|
|
|
+ fix: fix === true,
|
|
|
formatter: 'json',
|
|
|
};
|
|
|
|
|
|
@@ -145,9 +157,9 @@ export const lintPlugin = useSpinner<void>('Linting', async () => {
|
|
|
export const pluginBuildRunner: TaskRunner<PluginBuildOptions> = async ({ coverage }) => {
|
|
|
await clean();
|
|
|
await prepare();
|
|
|
- await prettierCheckPlugin();
|
|
|
+ await prettierCheckPlugin({ fix: false });
|
|
|
// @ts-ignore
|
|
|
- await lintPlugin();
|
|
|
+ await lintPlugin({ fix: false });
|
|
|
await testPlugin({ updateSnapshot: false, coverage });
|
|
|
await bundlePlugin({ watch: false, production: true });
|
|
|
};
|