Skip to content

Commit

Permalink
📦 NEW: WPGulp Installer
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadawais committed Sep 13, 2018
1 parent 03900de commit 9ca9ef4
Show file tree
Hide file tree
Showing 8 changed files with 720 additions and 155 deletions.
7 changes: 7 additions & 0 deletions .vscode/spellright.dict
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ rtlcss
imagemin
npm
npx
execa
fs
editorconfig
eslintignore
eslintrc
gitignore
Dotfiles
43 changes: 43 additions & 0 deletions installer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env node
/**
* Main Install WPGulp app
*
* Check the node version if above 8 then run the app.
*/

'use strict';

const chalk = require( 'chalk' );
const currentNodeVersion = process.versions.node;
const semver = currentNodeVersion.split( '.' );
const major = semver[0];

// If below Node 8.
if ( 8 > major ) {
// eslint-disable-next-line no-console
console.error(
chalk.red(
'You are running Node ' +
currentNodeVersion +
'.\n' +
'Install WPGulp requires Node 8 or higher. \n' +
'Kindly, update your version of Node.'
)
);
process.exit( 1 );
}

// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on( 'unhandledRejection', err => {
throw err;
});

/**
* Run the entire program.
*
* Runs all the functions with async/await.
*/
const run = require( './modules/run' );
run();
11 changes: 11 additions & 0 deletions installer/modules/clearConsole.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Cross platform clear console.
*
* Support for win32 and others.
*/

'use strict';

module.exports = () => {
process.stdout.write( 'win32' === process.platform ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H' );
};
10 changes: 10 additions & 0 deletions installer/modules/handleError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Error handler
*/
'use strict';

module.exports = err => {
if ( err ) {
console.log( 'ERROR: ' + err ); // eslint-disable-line no-console
}
};
43 changes: 43 additions & 0 deletions installer/modules/printNextSteps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Prints next steps.
*
* @param {string} blockName The block name.
* @param {string} blockDir The block directory.
*/

const chalk = require( 'chalk' );

/* eslint-disable no-console */
module.exports = () => {
console.log( '\n\n✅ ', chalk.black.bgGreen( ' All done! Use your code for good. \n' ) );
console.log( `Installer ${chalk.dim( '(install-wpgulp)' )} has added WPGulp files to the current directory. ` );
console.log( '\nInside this directory, you can run this command:\n' );

// Scripts.
console.log(
'\n👉 ',
' Type',
chalk.black.bgWhite( ' npm start ' ),
'\n\n',
' Use to compile and run your files.',
'\n',
' Watches for any changes and reports back any errors in your code.'
);

// Support.
console.log( '\n\n✊ ', chalk.black.bgYellow( ' Support WPGulp → \n' ) );
console.log(
'Like WPGulp? You can now support this free and open source project i.e. more updates and better maintenance: \n'
);
console.log(
` ${chalk.yellow( 'Support for one hour or more →' )} https://AhmdA.ws/CGB99`,
'\n',
` ${chalk.yellow( 'More ways to support →' )} https://AhmdA.ws/CGBSupport`
);

// Get started.
console.log( '\n\n🎯 ', chalk.black.bgGreen( ' Get Started → \n' ) );
console.log( ' I suggest that you begin by: \n' );
console.log( ` ${chalk.dim( '1.' )} Editing the ${chalk.green( 'wpgulp.config.js' )} file` );
console.log( ` ${chalk.dim( '2.' )} Running ${chalk.green( 'npm' )} start`, '\n\n' );
};
60 changes: 60 additions & 0 deletions installer/modules/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Install WPGulp
*/

const fs = require('fs');
const theCWD = process.cwd();
const theCWDArray = theCWD.split('/');
const theDir = theCWDArray[theCWDArray.length - 1];
const ora = require('ora');
const execa = require('execa');
const chalk = require('chalk');
const download = require('download');
const handleError = require('./handleError.js');
const clearConsole = require('./clearConsole.js');
const printNextSteps = require('./printNextSteps.js');

module.exports = () => {
// Init.
clearConsole();

// Files.
const filesToDownload = [
'https://raw.githubusercontent.com/ahmadawais/WPGulp/master/src/.editorconfig',
'https://raw.githubusercontent.com/ahmadawais/WPGulp/master/src/.eslintignore',
'https://raw.githubusercontent.com/ahmadawais/WPGulp/master/src/.eslintrc.js',
'https://raw.githubusercontent.com/ahmadawais/WPGulp/master/src/.gitignore',
'https://raw.githubusercontent.com/ahmadawais/WPGulp/master/src/gulpfile.babel.js',
'https://raw.githubusercontent.com/ahmadawais/WPGulp/master/src/package.json',
'https://raw.githubusercontent.com/ahmadawais/WPGulp/master/src/wpgulp.config.js'
];

// Dotfiles (if any).
const dotFiles = ['.editorconfig', '.eslintignore', '.eslintrc.js', '.gitignore'];

// Start.
console.log('\n'); // eslint-disable-line no-console
console.log(
'📦 ',
chalk.black.bgYellow(` Downloading WPGulp files in: → ${chalk.black.bgWhite(` ${theDir} `)}`),
chalk.dim(`\n In the directory: ${theCWD}\n`),
chalk.dim('This might take a couple of minutes.\n')
);

const spinner = ora({ text: '' });
spinner.start(`1. Creating WPGulp files inside → ${chalk.black.bgWhite(` ${theDir} `)}`);

// Download.
Promise.all(filesToDownload.map(x => download(x, `${theCWD}`))).then(async () => {
dotFiles.map(x => fs.rename(`${theCWD}/${x.slice(1)}`, `${theCWD}/${x}`, err => handleError(err)));
spinner.succeed();

// The npm install.
spinner.start('2. Installing npm packages...');
await execa('npm', ['install', '--silent']);
spinner.succeed();

// Done.
printNextSteps();
});
};
Loading

0 comments on commit 9ca9ef4

Please sign in to comment.