diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 8471047..0000000 --- a/.eslintignore +++ /dev/null @@ -1,4 +0,0 @@ -# ESLint: Ignore files. -**/*.min.js -**/node_modules/** -**/vendor/** diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 13cd5e4..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * ESLINT: Linting FTW - */ -module.exports = { - env: { - browser: true, - commonjs: true, - es6: true, - node: true - }, - extends: ['eslint:recommended', 'wordpress'], - parserOptions: { - sourceType: 'module' - }, - rules: { - indent: ['error', 'tab'], - 'linebreak-style': ['error', 'unix'], - quotes: ['error', 'single'], - semi: ['error', 'always'] - } -}; diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..a34cd74 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,10 @@ +{ + "trailingComma": "none", + "bracketSpacing": false, + "arrowParens": "avoid", + "singleQuote": true, + "printWidth": 120, + "useTabs": true, + "tabWidth": 4, + "semi": true +} diff --git a/WPGulp/.eslintrc.js b/WPGulp/.eslintrc.js index 64127b8..9542947 100644 --- a/WPGulp/.eslintrc.js +++ b/WPGulp/.eslintrc.js @@ -10,9 +10,14 @@ module.exports = { sourceType: 'module' }, rules: { + // Disable weird WP spacing rules. + // 'space-before-function-paren': 'off', + // 'space-in-parens': 'off', + // 'array-bracket-spacing': 'off', // Disable weird WP spacing rules. indent: ['error', 'tab'], - 'linebreak-style': ['error', 'unix'], + semi: ['error', 'always'], quotes: ['error', 'single'], - semi: ['error', 'always'] + 'linebreak-style': ['error', 'unix'] } }; +``; diff --git a/WPGulp/gulpfile.babel.js b/WPGulp/gulpfile.babel.js index af8dc77..737da8c 100755 --- a/WPGulp/gulpfile.babel.js +++ b/WPGulp/gulpfile.babel.js @@ -114,7 +114,7 @@ const reload = done => { */ gulp.task('styles', () => { return gulp - .src(config.styleSRC, { allowEmpty: true }) + .src(config.styleSRC, {allowEmpty: true}) .pipe(plumber(errorHandler)) .pipe(sourcemaps.init()) .pipe( @@ -125,22 +125,27 @@ gulp.task('styles', () => { }) ) .on('error', sass.logError) - .pipe(sourcemaps.write({ includeContent: false })) - .pipe(sourcemaps.init({ loadMaps: true })) + .pipe(sourcemaps.write({includeContent: false})) + .pipe(sourcemaps.init({loadMaps: true})) .pipe(autoprefixer(config.BROWSERS_LIST)) .pipe(sourcemaps.write('./')) .pipe(lineec()) // Consistent Line Endings for non UNIX systems. .pipe(gulp.dest(config.styleDestination)) .pipe(filter('**/*.css')) // Filtering stream to only css files. - .pipe(mmq({ log: true })) // Merge Media Queries only for .min.css version. + .pipe(mmq({log: true})) // Merge Media Queries only for .min.css version. .pipe(browserSync.stream()) // Reloads style.css if that is enqueued. - .pipe(rename({ suffix: '.min' })) - .pipe(minifycss({ maxLineLen: 10 })) + .pipe(rename({suffix: '.min'})) + .pipe(minifycss({maxLineLen: 10})) .pipe(lineec()) // Consistent Line Endings for non UNIX systems. .pipe(gulp.dest(config.styleDestination)) .pipe(filter('**/*.css')) // Filtering stream to only css files. .pipe(browserSync.stream()) // Reloads style.min.css if that is enqueued. - .pipe(notify({ message: '\n\n✅ ===> STYLES — completed!\n', onLast: true })); + .pipe( + notify({ + message: '\n\n✅ ===> STYLES — completed!\n', + onLast: true + }) + ); }); /** @@ -160,7 +165,7 @@ gulp.task('styles', () => { */ gulp.task('stylesRTL', () => { return gulp - .src(config.styleSRC, { allowEmpty: true }) + .src(config.styleSRC, {allowEmpty: true}) .pipe(plumber(errorHandler)) .pipe(sourcemaps.init()) .pipe( @@ -171,24 +176,29 @@ gulp.task('stylesRTL', () => { }) ) .on('error', sass.logError) - .pipe(sourcemaps.write({ includeContent: false })) - .pipe(sourcemaps.init({ loadMaps: true })) + .pipe(sourcemaps.write({includeContent: false})) + .pipe(sourcemaps.init({loadMaps: true})) .pipe(autoprefixer(config.BROWSERS_LIST)) .pipe(lineec()) // Consistent Line Endings for non UNIX systems. - .pipe(rename({ suffix: '-rtl' })) // Append "-rtl" to the filename. + .pipe(rename({suffix: '-rtl'})) // Append "-rtl" to the filename. .pipe(rtlcss()) // Convert to RTL. .pipe(sourcemaps.write('./')) // Output sourcemap for style-rtl.css. .pipe(gulp.dest(config.styleDestination)) .pipe(filter('**/*.css')) // Filtering stream to only css files. .pipe(browserSync.stream()) // Reloads style.css or style-rtl.css, if that is enqueued. - .pipe(mmq({ log: true })) // Merge Media Queries only for .min.css version. - .pipe(rename({ suffix: '.min' })) - .pipe(minifycss({ maxLineLen: 10 })) + .pipe(mmq({log: true})) // Merge Media Queries only for .min.css version. + .pipe(rename({suffix: '.min'})) + .pipe(minifycss({maxLineLen: 10})) .pipe(lineec()) // Consistent Line Endings for non UNIX systems. .pipe(gulp.dest(config.styleDestination)) .pipe(filter('**/*.css')) // Filtering stream to only css files. .pipe(browserSync.stream()) // Reloads style.css or style-rtl.css, if that is enqueued. - .pipe(notify({ message: '\n\n✅ ===> STYLES RTL — completed!\n', onLast: true })); + .pipe( + notify({ + message: '\n\n✅ ===> STYLES RTL — completed!\n', + onLast: true + }) + ); }); /** @@ -204,7 +214,7 @@ gulp.task('stylesRTL', () => { */ gulp.task('vendorsJS', () => { return gulp - .src(config.jsVendorSRC, { since: gulp.lastRun('vendorsJS') }) // Only run on changed files. + .src(config.jsVendorSRC, {since: gulp.lastRun('vendorsJS')}) // Only run on changed files. .pipe(plumber(errorHandler)) .pipe( babel({ @@ -212,7 +222,7 @@ gulp.task('vendorsJS', () => { [ '@babel/preset-env', // Preset to compile your modern JS to ES5. { - targets: { browsers: config.BROWSERS_LIST } // Target browser list to support. + targets: {browsers: config.BROWSERS_LIST} // Target browser list to support. } ] ] @@ -231,7 +241,12 @@ gulp.task('vendorsJS', () => { .pipe(uglify()) .pipe(lineec()) // Consistent Line Endings for non UNIX systems. .pipe(gulp.dest(config.jsVendorDestination)) - .pipe(notify({ message: '\n\n✅ ===> VENDOR JS — completed!\n', onLast: true })); + .pipe( + notify({ + message: '\n\n✅ ===> VENDOR JS — completed!\n', + onLast: true + }) + ); }); /** @@ -247,7 +262,7 @@ gulp.task('vendorsJS', () => { */ gulp.task('customJS', () => { return gulp - .src(config.jsCustomSRC, { since: gulp.lastRun('customJS') }) // Only run on changed files. + .src(config.jsCustomSRC, {since: gulp.lastRun('customJS')}) // Only run on changed files. .pipe(plumber(errorHandler)) .pipe( babel({ @@ -255,7 +270,7 @@ gulp.task('customJS', () => { [ '@babel/preset-env', // Preset to compile your modern JS to ES5. { - targets: { browsers: config.BROWSERS_LIST } // Target browser list to support. + targets: {browsers: config.BROWSERS_LIST} // Target browser list to support. } ] ] @@ -274,7 +289,12 @@ gulp.task('customJS', () => { .pipe(uglify()) .pipe(lineec()) // Consistent Line Endings for non UNIX systems. .pipe(gulp.dest(config.jsCustomDestination)) - .pipe(notify({ message: '\n\n✅ ===> CUSTOM JS — completed!\n', onLast: true })); + .pipe( + notify({ + message: '\n\n✅ ===> CUSTOM JS — completed!\n', + onLast: true + }) + ); }); /** @@ -299,17 +319,22 @@ gulp.task('images', () => { .pipe( cache( imagemin([ - imagemin.gifsicle({ interlaced: true }), - imagemin.jpegtran({ progressive: true }), - imagemin.optipng({ optimizationLevel: 3 }), // 0-7 low-high. + imagemin.gifsicle({interlaced: true}), + imagemin.mozjpeg({quality: 90, progressive: true}), + imagemin.optipng({optimizationLevel: 3}), // 0-7 low-high. imagemin.svgo({ - plugins: [{ removeViewBox: true }, { cleanupIDs: false }] + plugins: [{removeViewBox: true}, {cleanupIDs: false}] }) ]) ) ) .pipe(gulp.dest(config.imgDST)) - .pipe(notify({ message: '\n\n✅ ===> IMAGES — completed!\n', onLast: true })); + .pipe( + notify({ + message: '\n\n✅ ===> IMAGES — completed!\n', + onLast: true + }) + ); }); /** @@ -318,7 +343,7 @@ gulp.task('images', () => { * Deletes the images cache. By running the next "images" task, * each image will be regenerated. */ -gulp.task('clearCache', function(done) { +gulp.task('clearCache', function (done) { return cache.clearAll(done); }); @@ -345,7 +370,12 @@ gulp.task('translate', () => { }) ) .pipe(gulp.dest(config.translationDestination + '/' + config.translationFile)) - .pipe(notify({ message: '\n\n✅ ===> TRANSLATE — completed!\n', onLast: true })); + .pipe( + notify({ + message: '\n\n✅ ===> TRANSLATE — completed!\n', + onLast: true + }) + ); }); /** diff --git a/WPGulp/package.json b/WPGulp/package.json index 3c1338b..48b379d 100644 --- a/WPGulp/package.json +++ b/WPGulp/package.json @@ -7,33 +7,36 @@ "devDependencies": { "@babel/core": "^7.0.0", "@babel/register": "^7.0.0", + "@babel/preset-env": "^7.12.1", "beepbeep": "^1.2.2", "browser-sync": "^2.11.1", - "eslint": "^5.5.0", + "eslint": "^7.12.0", "eslint-config-wordpress": "^2.0.0", "gulp": "^4.0.0", - "gulp-autoprefixer": "^6.0.0", + "gulp-autoprefixer": "^7.0.1", "gulp-babel": "^8.0.0", "gulp-cache": "^1.0.2", "gulp-concat": "^2.5.2", - "gulp-filter": "^5.1.0", - "gulp-imagemin": "^4.1.0", + "gulp-filter": "^6.0.0", + "gulp-imagemin": "^7.1.0", "gulp-line-ending-corrector": "^1.0.1", "gulp-merge-media-queries": "^0.2.1", "gulp-notify": "^3.0.0", "gulp-plumber": "^1.2.0", "gulp-remember": "^1.0.1", - "gulp-rename": "^1.2.0", + "gulp-rename": "^2.0.0", "gulp-rtlcss": "^1.2.0", "gulp-sass": "^4.0.1", "gulp-sort": "^2.0.0", "gulp-sourcemaps": "^2.6.2", "gulp-uglify": "^3.0.0", "gulp-uglifycss": "^1.0.6", - "gulp-wp-pot": "^2.0.7" + "gulp-wp-pot": "^2.0.7", + "gulp-zip": "^5.0.2" }, "scripts": { "start": "gulp", + "zip": "gulp zip", "styles": "gulp styles", "images": "gulp images", "js-custom": "gulp customJS", diff --git a/WPGulp/wpgulp.config.js b/WPGulp/wpgulp.config.js index 3d13d26..8ff197c 100644 --- a/WPGulp/wpgulp.config.js +++ b/WPGulp/wpgulp.config.js @@ -7,63 +7,166 @@ * @package WPGulp */ -module.exports = { +// Project options. + +// Local project URL of your already running WordPress site. +// > Could be something like wpgulp.local or localhost:3000 +// > depending upon your local WordPress setup. +const projectURL = 'local.dv'; + +// Theme/Plugin URL. Leave it like it is; since our gulpfile.js lives in the root folder. +const productURL = './'; +const browserAutoOpen = false; +const injectChanges = true; + +// >>>>> Style options. +// Path to main .scss file. +const styleSRC = './assets/css/style.scss'; + +// Path to place the compiled CSS file. Default set to root folder. +const styleDestination = './'; + +// Available options → 'compact' or 'compressed' or 'nested' or 'expanded' +const outputStyle = 'compact'; +const errLogToConsole = true; +const precision = 10; + +// JS Vendor options. + +// Path to JS vendor folder. +const jsVendorSRC = './assets/js/vendor/*.js'; + +// Path to place the compiled JS vendors file. +const jsVendorDestination = './assets/js/'; + +// Compiled JS vendors file name. Default set to vendors i.e. vendors.js. +const jsVendorFile = 'vendor'; + +// JS Custom options. + +// Path to JS custom scripts folder. +const jsCustomSRC = './assets/js/custom/*.js'; + +// Path to place the compiled JS custom scripts file. +const jsCustomDestination = './assets/js/'; + +// Compiled JS custom file name. Default set to custom i.e. custom.js. +const jsCustomFile = 'custom'; + +// Images options. + +// Source folder of images which should be optimized and watched. +// > You can also specify types e.g. raw/**.{png,jpg,gif} in the glob. +const imgSRC = './assets/img/raw/**/*'; + +// Destination folder of optimized images. +// > Must be different from the imagesSRC folder. +const imgDST = './assets/img/'; - // Project options. - projectURL: 'wpgulp.local', // Local project URL of your already running WordPress site. Could be something like wpgulp.local or localhost:3000 depending upon your local WordPress setup. - productURL: './', // Theme/Plugin URL. Leave it like it is, since our gulpfile.js lives in the root folder. - browserAutoOpen: false, - injectChanges: true, - - // Style options. - styleSRC: './assets/css/style.scss', // Path to main .scss file. - styleDestination: './', // Path to place the compiled CSS file. Default set to root folder. - outputStyle: 'compact', // Available options → 'compact' or 'compressed' or 'nested' or 'expanded' - errLogToConsole: true, - precision: 10, - - // JS Vendor options. - jsVendorSRC: './assets/js/vendor/*.js', // Path to JS vendor folder. - jsVendorDestination: './assets/js/', // Path to place the compiled JS vendors file. - jsVendorFile: 'vendor', // Compiled JS vendors file name. Default set to vendors i.e. vendors.js. - - // JS Custom options. - jsCustomSRC: './assets/js/custom/*.js', // Path to JS custom scripts folder. - jsCustomDestination: './assets/js/', // Path to place the compiled JS custom scripts file. - jsCustomFile: 'custom', // Compiled JS custom file name. Default set to custom i.e. custom.js. - - // Images options. - imgSRC: './assets/img/raw/**/*', // Source folder of images which should be optimized and watched. You can also specify types e.g. raw/**.{png,jpg,gif} in the glob. - imgDST: './assets/img/', // Destination folder of optimized images. Must be different from the imagesSRC folder. - - // Watch files paths. - watchStyles: './assets/css/**/*.scss', // Path to all *.scss files inside css folder and inside them. - watchJsVendor: './assets/js/vendor/*.js', // Path to all vendor JS files. - watchJsCustom: './assets/js/custom/*.js', // Path to all custom JS files. - watchPhp: './**/*.php', // Path to all PHP files. - - // Translation options. - textDomain: 'WPGULP', // Your textdomain here. - translationFile: 'WPGULP.pot', // Name of the translation file. - translationDestination: './languages', // Where to save the translation files. - packageName: 'WPGULP', // Package name. - bugReport: 'https://AhmadAwais.com/contact/', // Where can users report bugs. - lastTranslator: 'Ahmad Awais ', // Last translator Email ID. - team: 'AhmadAwais ', // Team's Email ID. - - // Browsers you care about for autoprefixing. Browserlist https://github.com/ai/browserslist - // The following list is set as per WordPress requirements. Though, Feel free to change. - BROWSERS_LIST: [ - 'last 2 version', - '> 1%', - 'ie >= 11', - 'last 1 Android versions', - 'last 1 ChromeAndroid versions', - 'last 2 Chrome versions', - 'last 2 Firefox versions', - 'last 2 Safari versions', - 'last 2 iOS versions', - 'last 2 Edge versions', - 'last 2 Opera versions' - ] +// >>>>> Watch files paths. +// Path to all *.scss files inside css folder and inside them. +const watchStyles = './assets/css/**/*.scss'; + +// Path to all vendor JS files. +const watchJsVendor = './assets/js/vendor/*.js'; + +// Path to all custom JS files. +const watchJsCustom = './assets/js/custom/*.js'; + +// Path to all PHP files. +const watchPhp = './**/*.php'; + +// >>>>> Zip file config. +// Must have.zip at the end. +const zipName = 'theme.zip'; + +// Must be a folder outside of the zip folder. +const zipDestination = './../'; // Default: Parent folder. +const zipIncludeGlob = ['./**/*']; // Default: Include all files/folders in current directory. + +// Default ignored files and folders for the zip file. +const zipIgnoreGlob = [ + '!./{node_modules,node_modules/**/*}', + '!./.git', + '!./.svn', + '!./gulpfile.babel.js', + '!./wpgulp.config.js', + '!./.eslintrc.js', + '!./.eslintignore', + '!./.editorconfig', + '!./phpcs.xml.dist', + '!./vscode', + '!./package.json', + '!./package-lock.json', + '!./assets/css/**/*', + '!./assets/css', + '!./assets/img/raw/**/*', + '!./assets/img/raw', + `!${imgSRC}`, + `!${styleSRC}`, + `!${jsCustomSRC}`, + `!${jsVendorSRC}` +]; + +// >>>>> Translation options. +// Your text domain here. +const textDomain = 'WPGULP'; + +// Name of the translation file. +const translationFile = 'WPGULP.pot'; + +// Where to save the translation files. +const translationDestination = './languages'; + +// Package name. +const packageName = 'WPGULP'; + +// Where can users report bugs. +const bugReport = 'https://AhmadAwais.com/contact/'; + +// Last translator Email ID. +const lastTranslator = 'Ahmad Awais '; + +// Team's Email ID. +const team = 'AhmadAwais '; + +// Browsers you care about for auto-prefixing. Browserlist https://github.com/ai/browserslist +// The following list is set as per WordPress requirements. Though; Feel free to change. +const BROWSERS_LIST = ['last 2 version', '> 1%']; + +// Export. +module.exports = { + projectURL, + productURL, + browserAutoOpen, + injectChanges, + styleSRC, + styleDestination, + outputStyle, + errLogToConsole, + precision, + jsVendorSRC, + jsVendorDestination, + jsVendorFile, + jsCustomSRC, + jsCustomDestination, + jsCustomFile, + imgSRC, + imgDST, + watchStyles, + watchJsVendor, + watchJsCustom, + watchPhp, + zipName, + zipDestination, + zipIncludeGlob, + zipIgnoreGlob, + textDomain, + translationFile, + translationDestination, + packageName, + bugReport, + lastTranslator, + team, + BROWSERS_LIST }; diff --git a/installer/index.js b/installer/index.js old mode 100644 new mode 100755 index 900c853..d9990f5 --- a/installer/index.js +++ b/installer/index.js @@ -1,43 +1,63 @@ #!/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(); + +const fs = require('fs'); +const ora = require('ora'); +const execa = require('execa'); +const {yellow: y, green: g, dim: d} = require('chalk'); +const download = require('download'); +const clear = require('clear-any-console'); +const checkNode = require('cli-check-node'); +const handleError = require('./utils/handleError'); +const printNextSteps = require('./utils/printNextSteps'); +const unhandledError = require('cli-handle-unhandled'); + +const spinner = ora({text: ''}); + +(async () => { + clear(); + unhandledError(); + checkNode('10'); + + const CWD = process.cwd(); + const CWDArray = CWD.split('/'); + const installDir = CWDArray[CWDArray.length - 1]; + + // Files. + const filesToDownload = [ + `https://raw.githubusercontent.com/ahmadawais/WPGulp/master/WPGulp/.editorconfig`, + `https://raw.githubusercontent.com/ahmadawais/WPGulp/master/WPGulp/.eslintignore`, + `https://raw.githubusercontent.com/ahmadawais/WPGulp/master/WPGulp/.eslintrc.js`, + `https://raw.githubusercontent.com/ahmadawais/WPGulp/master/WPGulp/.gitignore`, + `https://raw.githubusercontent.com/ahmadawais/WPGulp/master/WPGulp/gulpfile.babel.js`, + `https://raw.githubusercontent.com/ahmadawais/WPGulp/master/WPGulp/package.json`, + `https://raw.githubusercontent.com/ahmadawais/WPGulp/master/WPGulp/wpgulp.config.js` + ]; + + // Dotfiles (if any). + const dotFiles = [`.editorconfig`, `.eslintignore`, `.eslintrc.js`, `.gitignore`]; + + // Start. + console.log(); + console.log(g(`Installing WPGulp in directory:`), d(installDir)); + console.log(d(`This might take a couple of minutes.\n`)); + + spinner.start(`${y(`DOWNLOADING`)} WPGulp files…`); + + // Download. + Promise.all(filesToDownload.map(x => download(x, `${CWD}`))).then(async () => { + dotFiles.map(dotFile => + fs.rename( + `${CWD}/${dotFile.slice(1)}`, // e.g. gitignore without a (.) prefix. + `${CWD}/${dotFile}`, // Add the (.) preferred + err => handleError(err) + ) + ); + spinner.succeed(`${g(`DOWNLOADED`)} WPGulp files`); + + spinner.start(`${y(`INSTALLING`)} npm packages…`); + await execa(`npm`, [`install`]); + spinner.succeed(`${g(`INSTALLED`)} npm packages`); + + printNextSteps(); + }); +})(); diff --git a/installer/modules/printNextSteps.js b/installer/modules/printNextSteps.js deleted file mode 100644 index 8cde9dd..0000000 --- a/installer/modules/printNextSteps.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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 has added WPGulp files to the current directory. ', - '\nInside this directory, you can run this command:' - ); - - // 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✊ ', 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/WPG99`, - '\n', - ` ${chalk.yellow( 'More ways to support →' )} https://AhmdA.ws/WPGSupport` - ); - - // 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' ); -}; diff --git a/installer/modules/run.js b/installer/modules/run.js deleted file mode 100644 index a551407..0000000 --- a/installer/modules/run.js +++ /dev/null @@ -1,57 +0,0 @@ -const fs = require('fs'); -const ora = require('ora'); -const execa = require('execa'); -const chalk = require('chalk'); -const download = require('download'); -const clear = require('clear-any-console'); -const handleError = require('./handleError'); -const printNextSteps = require('./printNextSteps'); - -module.exports = () => { - // Init. - clear(); - - const theCWD = process.cwd(); - const theCWDArray = theCWD.split('/'); - const theDir = theCWDArray[theCWDArray.length - 1]; - - // Files. - const filesToDownload = [ - `https://raw.githubusercontent.com/ahmadawais/WPGulp/master/WPGulp/.editorconfig`, - `https://raw.githubusercontent.com/ahmadawais/WPGulp/master/WPGulp/.eslintignore`, - `https://raw.githubusercontent.com/ahmadawais/WPGulp/master/WPGulp/.eslintrc.js`, - `https://raw.githubusercontent.com/ahmadawais/WPGulp/master/WPGulp/.gitignore`, - `https://raw.githubusercontent.com/ahmadawais/WPGulp/master/WPGulp/gulpfile.babel.js`, - `https://raw.githubusercontent.com/ahmadawais/WPGulp/master/WPGulp/package.json`, - `https://raw.githubusercontent.com/ahmadawais/WPGulp/master/WPGulp/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.bgGreen(` ${theDir} `)}\n`), - 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`]); - spinner.succeed(); - - // Done. - printNextSteps(); - }); -}; diff --git a/installer/modules/handleError.js b/installer/utils/handleError.js similarity index 100% rename from installer/modules/handleError.js rename to installer/utils/handleError.js diff --git a/installer/utils/printNextSteps.js b/installer/utils/printNextSteps.js new file mode 100644 index 0000000..caa342d --- /dev/null +++ b/installer/utils/printNextSteps.js @@ -0,0 +1,38 @@ +const sym = require('log-symbols'); +const {green: g, yellow: y, cyan: c, dim: d} = require('chalk'); + +module.exports = () => { + console.log(sym.success, g(`ALL DONE! Use your code for good.`)); + console.log(d(`WPGulp files are downloaded to the current directory.`)); + console.log(d(`Inside this directory, you can run the following command`)); + + // Scripts. + console.log(); + console.log(sym.info, g(`npm start`)); + console.log(d(`Use during development`)); + console.log(d(`It watches for any changes in your files`)); + + console.log(); + console.log(sym.info, `For more commands, read the docs at:`); + console.log(g(`https://github.com/ahmadawais/WPGulp`)); + // Support. + console.log(); + console.log(sym.warning, y(`SUPPORT`), `WPGulp:`); + console.log(); + console.log(`Learn to build Automation CLI Command Line Tools:`); + console.log(y(`https://NodeCLI.com`)); + console.log(); + console.log(`Become a VSCode Power Use to save hours every week:`); + console.log(y(`https://VSCode.pro`)); + console.log(); + console.log(`Follow the author of WPGulp:`); + console.log(y(`https://twitter.com/MrAhmadAwais`)); + + // Get started. + console.log(); + console.log(sym.info, g(`Get Started`)); + console.log(d(`I suggest that you begin by:`)); + console.log(`1. Editing the ${c(`wpgulp.config.js`)} file`); + console.log(`2. And then running ${g(`npm start`)}`); + console.log(); +}; diff --git a/package-lock.json b/package-lock.json index 3c1e837..ba98513 100644 --- a/package-lock.json +++ b/package-lock.json @@ -264,6 +264,114 @@ "resolved": "https://registry.npmjs.org/clear-any-console/-/clear-any-console-1.16.2.tgz", "integrity": "sha512-OL/7wZpNy9x0GBSzz3poWja84Nr7iaH8aYNsJ5Uet2BVLj6Lm1zvWpZN/yH46Vv3ae7YfHmLLMmfHj911fshJg==" }, + "cli-check-node": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/cli-check-node/-/cli-check-node-1.3.4.tgz", + "integrity": "sha512-iLGgQXm82iP8eH3R67qbOWs5qqUOLmNnMy5Lzl/RybcMh3y+H2zWU5POzuQ6oDUOdz4XWuxcFhP75szqd6frLg==", + "requires": { + "chalk": "^3.0.0", + "log-symbols": "^3.0.0" + }, + "dependencies": { + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "requires": { + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + }, + "log-symbols": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-3.0.0.tgz", + "integrity": "sha512-dSkNGuI7iG3mfvDzUuYZyvk5dD9ocYCYzNU6CYDE6+Xqd+gwme6Z00NS3dUh8mq/73HaEtT7m6W+yUPtU6BZnQ==", + "requires": { + "chalk": "^2.4.2" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "requires": { + "has-flag": "^4.0.0" + } + } + } + }, "cli-cursor": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", @@ -272,6 +380,122 @@ "restore-cursor": "^2.0.0" } }, + "cli-handle-error": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/cli-handle-error/-/cli-handle-error-4.4.0.tgz", + "integrity": "sha512-RyBCnKlc7xVr79cKb9RfBq+4fjwQeX8HKeNzIPnI/W+DWWIUUKh2ur576DpwJ3kZt2UGHlIAOF7N9txy+mgZsA==", + "requires": { + "chalk": "^3.0.0", + "log-symbols": "^3.0.0" + }, + "dependencies": { + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "requires": { + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + }, + "log-symbols": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-3.0.0.tgz", + "integrity": "sha512-dSkNGuI7iG3mfvDzUuYZyvk5dD9ocYCYzNU6CYDE6+Xqd+gwme6Z00NS3dUh8mq/73HaEtT7m6W+yUPtU6BZnQ==", + "requires": { + "chalk": "^2.4.2" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "requires": { + "has-flag": "^4.0.0" + } + } + } + }, + "cli-handle-unhandled": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/cli-handle-unhandled/-/cli-handle-unhandled-1.1.1.tgz", + "integrity": "sha512-Em91mJvU7VdgT2MxQpyY633vW1tDzRjPDbii6ZjEBHHLLh0xDoVkFt/wjvi9nSvJcz9rJmvtJSK8KL/hvF0Stg==", + "requires": { + "cli-handle-error": "^4.1.0" + } + }, "cli-spinners": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-1.3.1.tgz", @@ -1151,11 +1375,56 @@ "dev": true }, "log-symbols": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz", - "integrity": "sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.0.0.tgz", + "integrity": "sha512-FN8JBzLx6CzeMrB0tg6pqlGU1wCrXW+ZXGH481kfsBqer0hToTIiHdjH4Mq8xJUbvATujKCvaREGWpGUionraA==", "requires": { - "chalk": "^2.0.1" + "chalk": "^4.0.0" + }, + "dependencies": { + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "requires": { + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", + "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "requires": { + "has-flag": "^4.0.0" + } + } } }, "lowercase-keys": { @@ -1330,6 +1599,16 @@ "log-symbols": "^2.2.0", "strip-ansi": "^4.0.0", "wcwidth": "^1.0.1" + }, + "dependencies": { + "log-symbols": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz", + "integrity": "sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg==", + "requires": { + "chalk": "^2.0.1" + } + } } }, "os-tmpdir": { diff --git a/package.json b/package.json index 292a3e9..b37d9b3 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,11 @@ "dependencies": { "chalk": "^2.4.1", "clear-any-console": "^1.16.2", + "cli-check-node": "^1.3.4", + "cli-handle-unhandled": "^1.1.1", "download": "^7.1.0", "execa": "^1.0.0", + "log-symbols": "^4.0.0", "ora": "^3.0.0" }, "devDependencies": { diff --git a/readme.md b/readme.md index f59da5e..93ae263 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@
-

📟 — Learn to build CLI DevTools, like WPGulp with me at NodeCLI.com.

+

📟 Learn to build CLI DevTools, like WPGulp with me at NodeCLI.com.

WPGulp WordPress Gulp @@ -221,7 +221,6 @@ without wasting a 1,000 hours][n] →

[![Node CLI](https://img.shields.io/badge/-NodeCLI.com%20%E2%86%92-gray.svg?colorB=488640&style=flat)][n] - [![Awais on Twitter](https://raw.githubusercontent.com/ahmadawais/stuff/master/sponsor/sponsor.jpg)](https://github.com/AhmadAwais/sponsor) ### 🙌 [THEDEVCOUPLE PARTNERS](https://TheDevCouple.com/partners)