Skip to content

Commit

Permalink
chore: 🔧 improved cleaning script
Browse files Browse the repository at this point in the history
Can-Sahin committed May 17, 2020
1 parent c776cdd commit a3d05f8
Showing 2 changed files with 33 additions and 5 deletions.
33 changes: 30 additions & 3 deletions internals/scripts/clean.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import shell from 'shelljs';
import path from 'path';
import chalk from 'chalk';
import replace from 'replace-in-file';
import fs from 'fs';
const packageJson = require('../../package.json');

interface Options {}

process.chdir(path.join(__dirname, '../..'));

export function cleanExampleApp(opts: Options = {}) {
export function cleanAndSetup(opts: Options = {}) {
if (!shell.test('-e', 'internals/startingTemplate')) {
shell.echo('The example app has already deleted.');
shell.exit(1);
@@ -25,9 +28,33 @@ export function cleanExampleApp(opts: Options = {}) {

shell.exec('npm run prettify -- src/*', { silent: true });

shell.echo(chalk.green('Example App removed. Happy Coding!!!'));
cleanPackageJsonFile();

shell.echo(
chalk.green('Example app removed and setup completed. Happy Coding!!!'),
);
}

function cleanPackageJsonFile() {
delete packageJson['eslintConfig'];
delete packageJson['dependencies']['replace-in-file'];
delete packageJson['scripts']['cleanAndSetup'];

fs.writeFileSync('./package.json', JSON.stringify(packageJson));
shell.exec('npm run prettify -- package.json', { silent: true });

try {
// Remove explanation from husky to enable it
replace.sync({
files: 'package.json',
from: /"husky\((.*?)\)"/g,
to: '"husky"',
});
} catch (error) {
console.error('Couldnt clean husky:', error);
}
}

(function () {
cleanExampleApp();
cleanAndSetup();
})();
5 changes: 3 additions & 2 deletions template.json
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
"*.{ts,tsx,js,jsx}": ["npm run eslint -- --fix"],
"*.{md,json}": ["prettier --write"]
},
"husky": {
"husky(remove-everything-in-these-parentheses.See-the-issue-#29)": {
"hooks": {
"pre-commit": "npm run checkTs && lint-staged"
}
@@ -93,7 +93,8 @@
"plop": "2.6.0",
"serve": "11.3.0",
"shelljs": "0.8.3",
"husky": "4.2.3"
"husky": "4.2.3",
"replace-in-file": "6.0.0"
}
}
}

0 comments on commit a3d05f8

Please sign in to comment.