generator-folklore 2.2.55 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/lib/generators/app/index.js +2 -2
  2. package/lib/generators/babel/index.js +2 -4
  3. package/lib/generators/browserslist/index.js +36 -0
  4. package/lib/generators/browserslist/templates/browserslistrc +9 -0
  5. package/lib/generators/build/index.js +45 -243
  6. package/lib/generators/docs/index.js +4 -8
  7. package/lib/generators/eslint/index.js +2 -10
  8. package/lib/generators/eslint/templates/eslintrc +29 -3
  9. package/lib/generators/js/index.js +2 -6
  10. package/lib/generators/laravel/index.js +2 -2
  11. package/lib/generators/laravel-panneau/index.js +1 -3
  12. package/lib/generators/lerna-repository/index.js +1 -3
  13. package/lib/generators/npm-package/index.js +2 -6
  14. package/lib/generators/prettier/index.js +35 -0
  15. package/lib/generators/{eslint → prettier}/templates/prettierrc.json +0 -0
  16. package/lib/generators/react-package/index.js +2 -6
  17. package/lib/generators/storybook/index.js +1 -3
  18. package/lib/generators/stylelint/index.js +2 -4
  19. package/lib/generators/stylelint/templates/stylelintrc +6 -2
  20. package/lib/generators/test/index.js +1 -3
  21. package/package.json +9 -9
  22. package/lib/generators/build/templates/config.js +0 -78
  23. package/lib/generators/build/templates/env.js +0 -90
  24. package/lib/generators/build/templates/paths.js +0 -92
  25. package/lib/generators/build/templates/polyfills.js +0 -25
  26. package/lib/generators/build/templates/postcss.config.js +0 -12
  27. package/lib/generators/build/templates/scripts/build.js +0 -158
  28. package/lib/generators/build/templates/scripts/imagemin.js +0 -59
  29. package/lib/generators/build/templates/scripts/modernizr.js +0 -22
  30. package/lib/generators/build/templates/scripts/server.js +0 -176
  31. package/lib/generators/build/templates/utils/getConfigValue.js +0 -5
  32. package/lib/generators/build/templates/utils/getLocalIdent.js +0 -11
  33. package/lib/generators/build/templates/webpack.config.dev.js +0 -394
  34. package/lib/generators/build/templates/webpack.config.prod.js +0 -571
  35. package/lib/generators/build/templates/webpackDevServer.config.js +0 -109
@@ -44,14 +44,12 @@ module.exports = class StylelintGenerator extends _generator.default {
44
44
  };
45
45
  }
46
46
 
47
- install() {
47
+ async install() {
48
48
  if (this.options['skip-install']) {
49
49
  return;
50
50
  }
51
51
 
52
- this.npmInstall(['stylelint', 'stylelint-config-property-sort-order-smacss', 'stylelint-config-recommended', 'stylelint-config-sass-guidelines', 'stylelint-scss'], {
53
- 'save-dev': true
54
- });
52
+ await this.addDevDependencies(['stylelint', 'stylelint-config-standard-scss', 'stylelint-config-idiomatic-order', 'stylelint-config-prettier']);
55
53
  }
56
54
 
57
55
  };
@@ -1,8 +1,12 @@
1
1
  {
2
- "extends": ["stylelint-config-sass-guidelines", "stylelint-config-property-sort-order-smacss"],
2
+ "extends": [
3
+ "stylelint-config-standard-scss",
4
+ "stylelint-config-idiomatic-order",
5
+ "stylelint-config-prettier"
6
+ ],
3
7
  "rules": {
4
8
  "indentation": 4,
5
- "order/properties-alphabetical-order": null,<% if (camelCase) {%>
9
+ "alpha-value-notation": "number",<% if (camelCase) {%>
6
10
  "selector-class-pattern": [
7
11
  "^[a-z][a-z0-9A-Z]+$",
8
12
  {
@@ -67,9 +67,7 @@ module.exports = class TestGenerator extends _generator.default {
67
67
  return;
68
68
  }
69
69
 
70
- this.npmInstall(['babel-jest@latest', 'enzyme@latest', 'enzyme-adapter-react-16@latest', 'eslint-plugin-jest@latest', 'jest@latest', 'jsdom@latest', 'react-test-renderer@latest', 'sinon@latest'], {
71
- 'save-dev': true
72
- });
70
+ this.addDevDependencies(['babel-jest@latest', 'enzyme@latest', 'enzyme-adapter-react-16@latest', 'eslint-plugin-jest@latest', 'jest@latest', 'jsdom@latest', 'react-test-renderer@latest', 'sinon@latest']);
73
71
  }
74
72
 
75
73
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generator-folklore",
3
- "version": "2.2.55",
3
+ "version": "3.0.0",
4
4
  "description": "Yeoman generator for projects at Folklore",
5
5
  "keywords": [
6
6
  "yeoman-generator"
@@ -29,15 +29,15 @@
29
29
  },
30
30
  "homepage": "https://github.com/folkloreinc/folklore-js/tree/master/packages/generator-folklore#readme",
31
31
  "dependencies": {
32
- "chalk": "^2.1.0",
33
- "change-case": "^3.0.1",
34
- "glob": "^7.1.2",
35
- "immutable": "^3.8.1",
32
+ "chalk": "^4.0.0",
33
+ "change-case": "^4.1.2",
34
+ "glob": "^7.2.0",
35
+ "immutable": "^4.0.0",
36
36
  "is-utf8": "^0.2.1",
37
- "lodash": "^4.17.4",
38
- "password-generator": "^2.0.2",
39
- "yeoman-generator": "^2.0.3",
37
+ "lodash": "^4.17.21",
38
+ "password-generator": "^2.3.2",
39
+ "yeoman-generator": "^5.6.1",
40
40
  "yeoman-remote": "^1.0.1"
41
41
  },
42
- "gitHead": "9f8a1f532529131d760cadf521b80fd3d9590209"
42
+ "gitHead": "4ee114645b7773667513e04f1b67e881d720add8"
43
43
  }
@@ -1,78 +0,0 @@
1
- /* eslint-disable no-console, global-require */
2
- /* eslint-disable import/no-extraneous-dependencies, import/no-dynamic-require, import/order */
3
- module.exports = {
4
- /**
5
- * Webpack
6
- */
7
- webpack: {
8
- filename: <% if (hasHtml) { %>() => 'js/main-[hash:8].js'<% } else { %>() => 'js/main.js'<% } %>,
9
- chunkFilename: () => 'js/[name]-[hash:8].chunk.js',
10
- publicPath: '/',
11
-
12
- cssRegex: /\.global\.css$/,
13
- cssModuleRegex: /\.css$/,
14
- sassRegex: /\.global\.(scss|sass)$/,
15
- sassModuleRegex: /\.(scss|sass)$/,
16
-
17
- cssFilename: <% if (hasHtml) { %>() => 'css/[name]-[contenthash:8].css'<% } else { %>() => 'css/[name].css'<% } %>,
18
- cssChunkFilename: () => 'css/[name]-[contenthash:8].chunk.css',
19
- cssLocalIdent: '[name]-[local]',
20
-
21
- imageFilename: () => 'img/[name]-[hash:8].[ext]',
22
- imagePublicPath: '/',
23
-
24
- mediaFilename: () => 'medias/[name]-[hash:8].[ext]',
25
- mediaPublicPath: '/',
26
-
27
- fontFilename: () => 'fonts/[name]-[hash:8].[ext]',
28
- },
29
- <% if (hasServer) { %>
30
- /**
31
- * Webpack Dev Server
32
- */
33
- webpackDevServer: {
34
- <% if (hasServerProxy) {
35
- %> browserHost: '<%= serverBrowserHost %>',
36
- proxy: '<%= serverProxyHost %>',
37
- https: false,<% } %>
38
- },<% } %>
39
-
40
- /**
41
- * PostCSS
42
- */
43
- postcss: {
44
- ident: 'postcss',
45
- plugins: [
46
- require('postcss-flexbugs-fixes'),
47
- require('postcss-preset-env')({
48
- autoprefixer: {
49
- flexbox: 'no-2009',
50
- },
51
- stage: 3,
52
- }),
53
- ],
54
- },
55
-
56
- <% if (hasImagemin) {
57
- %> /**
58
- * Imagemin
59
- */
60
- imagemin: {
61
- files: [<% (imageminFiles || []).forEach((file) => {
62
- %> '<%= file %>',
63
- <% }) %> ],
64
- output: '<%= imageminOutputPath %>',
65
-
66
- pngquant: {
67
- quality: '65-80',
68
- },
69
-
70
- svgo: {
71
- plugins: [
72
- {
73
- removeViewBox: false,
74
- },
75
- ],
76
- },
77
- },<% } %>
78
- };
@@ -1,90 +0,0 @@
1
- /* eslint-disable import/no-extraneous-dependencies, global-require */
2
- const fs = require('fs');
3
- const path = require('path');
4
- const paths = require('./paths');
5
-
6
- // Make sure that including paths.js after env.js will read .env variables.
7
- delete require.cache[require.resolve('./paths')];
8
-
9
- const { NODE_ENV } = process.env;
10
- if (!NODE_ENV) {
11
- throw new Error('The NODE_ENV environment variable is required but was not specified.');
12
- }
13
-
14
- // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
15
- const dotenvFiles = [
16
- `${paths.dotenv}.${NODE_ENV}.local`,
17
- `${paths.dotenv}.${NODE_ENV}`,
18
- // Don't include `.env.local` for `test` environment
19
- // since normally you expect tests to produce the same
20
- // results for everyone
21
- NODE_ENV !== 'test' && `${paths.dotenv}.local`,
22
- paths.dotenv,
23
- ].filter(Boolean);
24
-
25
- // Load environment variables from .env* files. Suppress warnings using silent
26
- // if this file is missing. dotenv will never modify any environment variables
27
- // that have already been set. Variable expansion is supported in .env files.
28
- // https://github.com/motdotla/dotenv
29
- // https://github.com/motdotla/dotenv-expand
30
- dotenvFiles.forEach((dotenvFile) => {
31
- if (fs.existsSync(dotenvFile)) {
32
- require('dotenv-expand')(
33
- require('dotenv').config({
34
- path: dotenvFile,
35
- }),
36
- );
37
- }
38
- });
39
-
40
- // We support resolving modules according to `NODE_PATH`.
41
- // This lets you use absolute paths in imports inside large monorepos:
42
- // https://github.com/facebook/create-react-app/issues/253.
43
- // It works similar to `NODE_PATH` in Node itself:
44
- // https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
45
- // Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
46
- // Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
47
- // https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
48
- // We also resolve them to make sure all tools using them work consistently.
49
- const appDirectory = fs.realpathSync(process.cwd());
50
- process.env.NODE_PATH = (process.env.NODE_PATH || '')
51
- .split(path.delimiter)
52
- .filter(folder => folder && !path.isAbsolute(folder))
53
- .map(folder => path.resolve(appDirectory, folder))
54
- .join(path.delimiter);
55
-
56
- // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
57
- // injected into the application via DefinePlugin in Webpack configuration.
58
- const REACT_APP = /^REACT_APP_/i;
59
-
60
- function getClientEnvironment(publicUrl) {
61
- const raw = Object.keys(process.env)
62
- .filter(key => REACT_APP.test(key))
63
- .reduce(
64
- (env, key) => ({
65
- ...env,
66
- [key]: process.env[key],
67
- }),
68
- {
69
- // Useful for determining whether we’re running in production mode.
70
- // Most importantly, it switches React into the correct mode.
71
- NODE_ENV: process.env.NODE_ENV || 'development',
72
- // Useful for resolving the correct path to static assets in `public`.
73
- // For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
74
- // This should only be used as an escape hatch. Normally you would put
75
- // images into the `src` and `import` them in code to get their paths.
76
- PUBLIC_URL: publicUrl,
77
- },
78
- );
79
- // Stringify all values so we can feed into Webpack DefinePlugin
80
- const stringified = {
81
- 'process.env': Object.keys(raw).reduce((env, key) => ({
82
- ...env,
83
- [key]: JSON.stringify(raw[key]),
84
- }), {}),
85
- };
86
-
87
- return { raw, stringified };
88
- }
89
-
90
- module.exports = getClientEnvironment;
@@ -1,92 +0,0 @@
1
- /* eslint-disable no-console, global-require */
2
- /* eslint-disable import/no-extraneous-dependencies, import/no-dynamic-require, import/order */
3
- const path = require('path');
4
- const fs = require('fs');
5
- const url = require('url');
6
-
7
- // Make sure any symlinks in the project folder are resolved:
8
- // https://github.com/facebook/create-react-app/issues/637
9
- const appDirectory = fs.realpathSync(process.cwd());
10
- const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
11
-
12
- const envPublicUrl = process.env.PUBLIC_URL;
13
-
14
- function ensureSlash(inputPath, needsSlash) {
15
- const hasSlash = inputPath.endsWith('/');
16
- if (hasSlash && !needsSlash) {
17
- return inputPath.substr(0, inputPath.length - 1);
18
- }
19
- if (!hasSlash && needsSlash) {
20
- return `${inputPath}/`;
21
- }
22
- return inputPath;
23
- }
24
-
25
- const getPublicUrl = appPackageJson => envPublicUrl || require(appPackageJson).homepage;
26
-
27
- // We use `PUBLIC_URL` environment variable or "homepage" field to infer
28
- // "public path" at which the app is served.
29
- // Webpack needs to know it to put the right <script> hrefs into HTML even in
30
- // single-page apps that may serve index.html for nested URLs like /todos/42.
31
- // We can't use a relative path in HTML because we don't want to load something
32
- // like /todos/42/static/js/bundle.7289d.js. We have to know the root.
33
- function getServedPath(appPackageJson) {
34
- const publicUrl = getPublicUrl(appPackageJson);
35
- const servedUrl = envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
36
- return ensureSlash(servedUrl, true);
37
- }
38
-
39
- const moduleFileExtensions = [
40
- 'web.mjs',
41
- 'mjs',
42
- 'web.js',
43
- 'js',
44
- 'web.ts',
45
- 'ts',
46
- 'web.tsx',
47
- 'tsx',
48
- 'json',
49
- 'web.jsx',
50
- 'jsx',
51
- ];
52
-
53
- // Resolve file paths in the same order as webpack
54
- const resolveModule = (resolveFn, filePath) => {
55
- if (fs.existsSync(resolveFn(filePath))) {
56
- return resolveFn(filePath);
57
- }
58
- const extension = moduleFileExtensions.find(ext => fs.existsSync(resolveFn(`${filePath}.${ext}`)));
59
-
60
- if (extension) {
61
- return resolveFn(`${filePath}.${extension}`);
62
- }
63
-
64
- return resolveFn(`${filePath}.js`);
65
- };
66
-
67
- // config after eject: we're in ./config/
68
- module.exports = {
69
- dotenv: resolveApp('.env'),
70
- appPath: resolveApp('.'),
71
- appBuild: resolveApp('<%= buildPath %>'),
72
- appPublic: resolveApp('<%= publicPath %>'),
73
- appIndexJs: resolveModule(resolveApp, '<%= entryPath %>'),<% if (htmlPath !== null) { %>
74
- appHtml: resolveApp('<%= htmlPath %>'),<% } %>
75
- appPackageJson: resolveApp('package.json'),
76
- appNodeModules: resolveApp('node_modules'),
77
- appSrc: resolveApp('<%= srcPath %>'),
78
- testsSetup: resolveModule(resolveApp, 'tests/setupTests'),
79
- publicUrl: getPublicUrl(resolveApp('package.json')),
80
- servedPath: getServedPath(resolveApp('package.json')),
81
- copyPaths: [<% (copyPaths || []).forEach((dir) => { %>
82
- resolveApp('<%= dir %>'),<% }) %>
83
- ],
84
- emptyPaths: [<% (emptyPaths || []).forEach((dir) => {%>
85
- resolveApp('<%= dir %>'),<% }) %>
86
- ],
87
- watchPaths: [<% (watchPaths || []).forEach((dir) => { %>
88
- resolveApp('<%= dir %>'),<% }) %>
89
- ],
90
- };
91
-
92
- module.exports.moduleFileExtensions = moduleFileExtensions;
@@ -1,25 +0,0 @@
1
- /* eslint-disable import/no-extraneous-dependencies, global-require */
2
- if (typeof Promise === 'undefined') {
3
- // Rejection tracking prevents a common issue where React gets into an
4
- // inconsistent state due to an error, but it gets swallowed by a Promise,
5
- // and the user has no idea what causes React's erratic future behavior.
6
- require('promise/lib/rejection-tracking').enable();
7
- window.Promise = require('promise/lib/es6-extensions.js');
8
- }
9
-
10
- // fetch() polyfill for making API calls.
11
- require('whatwg-fetch');
12
-
13
- require('core-js/es6/map');
14
- require('core-js/es6/set');
15
- require('raf/polyfill');
16
-
17
- // Object.assign() is commonly used with React.
18
- // It will use the native implementation if it's present and isn't buggy.
19
- Object.assign = require('object-assign');
20
-
21
- // In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet.
22
- // We don't polyfill it in the browser--this is user's responsibility.
23
- if (process.env.NODE_ENV === 'test') {
24
- require('raf').polyfill(global);
25
- }
@@ -1,12 +0,0 @@
1
- const config = require('./config');
2
-
3
- module.exports = ({ options }) =>
4
- Object.assign(
5
- {},
6
- config.postcss,
7
- (
8
- typeof options.env !== 'undefined' &&
9
- typeof config.postcss.env !== 'undefined' &&
10
- typeof config.postcss.env[options.env] !== 'undefined'
11
- ) ? config.postcss.env[options.env] : null,
12
- );
@@ -1,158 +0,0 @@
1
- /* eslint-disable no-console, global-require */
2
- /* eslint-disable import/no-extraneous-dependencies, import/no-dynamic-require, import/order */
3
- const program = require('commander');
4
-
5
- program
6
- .version('0.1.0')
7
- .option(
8
- '-c, --config [value]',
9
- 'Webpack configuration',
10
- (val, configs) => (configs === null ? [val] : [...configs, val]),
11
- null,
12
- )
13
- .parse(process.argv);
14
-
15
- // Do this as the first thing so that any code reading it knows the right env.
16
- process.env.BABEL_ENV = 'production';
17
- process.env.NODE_ENV = 'production';
18
-
19
- // Makes the script crash on unhandled rejections instead of silently
20
- // ignoring them. In the future, promise rejections that are not handled will
21
- // terminate the Node.js process with a non-zero exit code.
22
- process.on('unhandledRejection', (err) => {
23
- throw err;
24
- });
25
-
26
- // Ensure environment variables are read.
27
- require('../env');
28
-
29
- const path = require('path');
30
- const chalk = require('chalk');
31
- const glob = require('glob');
32
- const fs = require('fs-extra');
33
- const webpack = require('webpack');
34
- const defaultWebpackConfig = require('../webpack.config.prod');
35
- const paths = require('../paths');
36
- const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
37
- const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
38
- const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
39
- const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
40
- const printBuildError = require('react-dev-utils/printBuildError');
41
-
42
- const { measureFileSizesBeforeBuild, printFileSizesAfterBuild } = FileSizeReporter;
43
- const useYarn = fs.existsSync(paths.yarnLockFile);
44
-
45
- // These sizes are pretty large. We'll warn for bundles exceeding them.
46
- const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
47
- const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
48
-
49
- const webpackConfigs = program.config !== null
50
- ? program.config.map(configPath => require(path.join(process.env.PWD, configPath)))
51
- : [defaultWebpackConfig];
52
-
53
- // Warn and crash if required files are missing
54
- const entries = webpackConfigs.reduce(
55
- (allEntries, webpackConfig) => [...allEntries, ...webpackConfig.entry],
56
- [],
57
- );
58
- if (!checkRequiredFiles(entries)) {
59
- process.exit(1);
60
- }
61
-
62
- // Create the production build and print the deployment instructions.
63
- function build(webpackConfig, previousFileSizes) {
64
- console.log('Creating an optimized production build...');
65
- const compiler = webpack(webpackConfig);
66
- return new Promise((resolve, reject) => {
67
- compiler.run((err, stats) => {
68
- if (err) {
69
- return reject(err);
70
- }
71
- const messages = formatWebpackMessages(stats.toJson({}, true));
72
- if (messages.errors.length) {
73
- // Only keep the first error. Others are often indicative
74
- // of the same problem, but confuse the reader with noise.
75
- if (messages.errors.length > 1) {
76
- messages.errors.length = 1;
77
- }
78
- return reject(new Error(messages.errors.join('\n\n')));
79
- }
80
- if (
81
- process.env.CI &&
82
- (typeof process.env.CI !== 'string' || process.env.CI.toLowerCase() !== 'false') &&
83
- messages.warnings.length
84
- ) {
85
- console.log(chalk.yellow('\nTreating warnings as errors because process.env.CI = true.\n' +
86
- 'Most CI servers set it automatically.\n'));
87
- return reject(new Error(messages.warnings.join('\n\n')));
88
- }
89
- return resolve({
90
- webpackConfig,
91
- buildPath: webpackConfig.output.path,
92
- stats,
93
- previousFileSizes,
94
- warnings: messages.warnings,
95
- });
96
- });
97
- });
98
- }
99
-
100
- // First, read the current file sizes in build directory.
101
- // This lets us display how much they changed later.
102
- Promise.all(webpackConfigs.map(conf => measureFileSizesBeforeBuild(conf.output.path)))
103
- .then((previousSizes) => {
104
- // Merge with the public folder
105
- paths.emptyPaths.forEach((dir) => {
106
- glob.sync(dir).forEach((file) => {
107
- fs.removeSync(file);
108
- });
109
- });
110
-
111
- // prettier-ignore
112
- return webpackConfigs.reduce(
113
- (lastPromise, webpackConfig, index) => lastPromise.then(responses => (
114
- build(webpackConfig, previousSizes[index]).then(response => [
115
- ...responses,
116
- response,
117
- ])
118
- )),
119
- Promise.resolve([]),
120
- );
121
- })
122
- .then(
123
- (builds) => {
124
- builds.forEach(({
125
- webpackConfig, stats, buildPath, previousFileSizes, warnings,
126
- }) => {
127
- if (warnings.length) {
128
- console.log(chalk.yellow('Compiled with warnings.\n'));
129
- console.log(warnings.join('\n\n'));
130
- console.log(`\nSearch for the ${chalk.underline(chalk.yellow('keywords'))} to learn more about each warning.`);
131
- console.log(`To ignore, add ${chalk.cyan('// eslint-disable-next-line')} to the line before.\n`);
132
- } else {
133
- console.log(chalk.green('Compiled successfully.\n'));
134
- }
135
-
136
- console.log('File sizes after gzip:\n');
137
- console.log(buildPath);
138
- printFileSizesAfterBuild(
139
- stats,
140
- previousFileSizes,
141
- buildPath,
142
- WARN_AFTER_BUNDLE_GZIP_SIZE,
143
- WARN_AFTER_CHUNK_GZIP_SIZE,
144
- );
145
-
146
- const appPackage = require(paths.appPackageJson);
147
- const { publicUrl } = paths;
148
- const { publicPath } = webpackConfig.output;
149
- const buildFolder = path.relative(process.cwd(), buildPath);
150
- printHostingInstructions(appPackage, publicUrl, publicPath, buildFolder, useYarn);
151
- });
152
- },
153
- (err) => {
154
- console.log(chalk.red('Failed to compile.\n'));
155
- printBuildError(err);
156
- process.exit(1);
157
- },
158
- );
@@ -1,59 +0,0 @@
1
- #!/usr/bin/env node
2
- /* eslint-disable import/no-extraneous-dependencies */
3
- const imagemin = require('imagemin');
4
- const imageminMozjpeg = require('imagemin-mozjpeg');
5
- const imageminPngquant = require('imagemin-pngquant');
6
- const imageminSvgo = require('imagemin-svgo');
7
- const glob = require('glob');
8
- const path = require('path');
9
- const fs = require('fs');
10
- const chalk = require('chalk');
11
- const prettyBytes = require('pretty-bytes');
12
- const imageminConfig = require('./config').imagemin;
13
-
14
- function minifyImage(srcPath, output) {
15
- const stats = fs.statSync(srcPath);
16
- const originalSize = stats.size;
17
-
18
- imagemin([srcPath], output, {
19
- plugins: [
20
- imageminMozjpeg(),
21
- imageminPngquant(imageminConfig.pngquant),
22
- imageminSvgo(imageminConfig.svgo),
23
- ],
24
- }).then((files) => {
25
- let saved;
26
- let optimizedSize;
27
- let percent;
28
- let savedMsg;
29
- let msg;
30
- const fl = files.length;
31
- for (let i = 0; i < fl; i += 1) {
32
- optimizedSize = files[i].data.length;
33
- saved = originalSize - optimizedSize;
34
- percent = originalSize > 0 ? (saved / originalSize) * 100 : 0;
35
- savedMsg = `saved ${prettyBytes(saved)} - ${percent.toFixed(1).replace(/\.0$/, '')}%`;
36
- msg = saved > 0 ? savedMsg : 'already optimized';
37
- // eslint-disable-next-line no-console
38
- console.log(`${chalk.green('✔')} ${srcPath} ${chalk.yellow('>')} ${files[i].path} - ${msg}`);
39
- }
40
- });
41
- }
42
-
43
- const processFile = fileGlob => (
44
- (er, files) => {
45
- const basePath = fileGlob.substr(0, fileGlob.indexOf('*'));
46
- let srcPath;
47
- let relativePath;
48
- const fl = files.length;
49
- for (let i = 0; i < fl; i += 1) {
50
- srcPath = files[i];
51
- relativePath = srcPath.replace(basePath, '');
52
- minifyImage(srcPath, path.join(imageminConfig.output, path.dirname(relativePath)));
53
- }
54
- }
55
- );
56
-
57
- for (let i = 0, fl = imageminConfig.files.length; i < fl; i += 1) {
58
- glob(imageminConfig.files[i], {}, processFile(imageminConfig.files[i]));
59
- }
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env node
2
- /* eslint-disable import/no-extraneous-dependencies */
3
- const program = require('commander');
4
- const modernizr = require('customizr');
5
- const config = require('./config').modernizr || {};
6
-
7
- program
8
- .option('-d, --dist', 'Production build')
9
- .parse(process.argv);
10
-
11
- let settings = {
12
- ...config,
13
- };
14
- if (program.dist) {
15
- settings.dest = '<%= outputPath %>';
16
- settings.uglify = true;
17
- settings.cache = false;
18
- }
19
-
20
- modernizr(settings, () => {
21
-
22
- });