From a2a2fcba8226447c41271e93300a3b2ba8e7d968 Mon Sep 17 00:00:00 2001 From: HF Date: Wed, 2 Dec 2020 23:22:59 +0100 Subject: [PATCH] clean up building scripts, remove obsolete stuff --- .../example-ecosystem-backup.yml | 0 {tools => deployment}/example-ecosystem.yml | 0 package-lock.json | 67 +++++++++++-- package.json | 6 +- {tools => scripts}/build.js | 0 {tools => scripts}/bundle.js | 0 scripts/clean.js | 23 +++++ scripts/copy.js | 98 ++++++++++++++++++ {tools => scripts}/minifyCss.js | 11 ++- {tools => scripts}/run.js | 0 tools/clean.js | 25 ----- tools/copy.js | 26 ----- tools/lib/cp.js | 33 ------- tools/lib/fs.js | 99 ------------------- webpack.config.client.babel.js | 6 +- webpack.config.web.babel.js | 8 +- 16 files changed, 201 insertions(+), 201 deletions(-) rename {tools => deployment}/example-ecosystem-backup.yml (100%) rename {tools => deployment}/example-ecosystem.yml (100%) rename {tools => scripts}/build.js (100%) rename {tools => scripts}/bundle.js (100%) create mode 100644 scripts/clean.js create mode 100644 scripts/copy.js rename {tools => scripts}/minifyCss.js (77%) rename {tools => scripts}/run.js (100%) delete mode 100644 tools/clean.js delete mode 100644 tools/copy.js delete mode 100644 tools/lib/cp.js delete mode 100644 tools/lib/fs.js diff --git a/tools/example-ecosystem-backup.yml b/deployment/example-ecosystem-backup.yml similarity index 100% rename from tools/example-ecosystem-backup.yml rename to deployment/example-ecosystem-backup.yml diff --git a/tools/example-ecosystem.yml b/deployment/example-ecosystem.yml similarity index 100% rename from tools/example-ecosystem.yml rename to deployment/example-ecosystem.yml diff --git a/package-lock.json b/package-lock.json index d5574859..d7f2bf4d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5883,12 +5883,10 @@ } }, "mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", - "requires": { - "minimist": "^1.2.5" - } + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "dev": true }, "mkdirp-classic": { "version": "0.5.3", @@ -5958,6 +5956,16 @@ "on-finished": "^2.3.0", "type-is": "^1.6.4", "xtend": "^4.0.0" + }, + "dependencies": { + "mkdirp": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "requires": { + "minimist": "^1.2.5" + } + } } }, "mysql2": { @@ -6112,6 +6120,14 @@ "tar": "^4.4.2" }, "dependencies": { + "mkdirp": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "requires": { + "minimist": "^1.2.5" + } + }, "rimraf": { "version": "2.7.1", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", @@ -8292,6 +8308,15 @@ "supports-color": "^5.3.0" } }, + "mkdirp": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "dev": true, + "requires": { + "minimist": "^1.2.5" + } + }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -8389,6 +8414,16 @@ "mkdirp": "^0.5.0", "safe-buffer": "^5.1.2", "yallist": "^3.0.3" + }, + "dependencies": { + "mkdirp": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "requires": { + "minimist": "^1.2.5" + } + } } }, "tar-fs": { @@ -9496,6 +9531,17 @@ "dev": true, "requires": { "mkdirp": "^0.5.1" + }, + "dependencies": { + "mkdirp": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "dev": true, + "requires": { + "minimist": "^1.2.5" + } + } } }, "write-file-atomic": { @@ -9544,6 +9590,15 @@ "supports-color": "^5.3.0" } }, + "mkdirp": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "dev": true, + "requires": { + "minimist": "^1.2.5" + } + }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", diff --git a/package.json b/package.json index 261152eb..78aa84e8 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "description": "Unlimited planet canvas for placing pixels", "main": "server.js", "scripts": { - "build": "babel-node tools/run build", - "clean": "babel-node tools/run clean", + "build": "babel-node scripts/run build", + "clean": "babel-node scripts/run clean", "webpack": "webpack --config webpack.config.web.babel.js && webpack --config webpack.config.client.babel.js", "babel-node": "cd $INIT_CWD && babel-node", "lint": "cd $INIT_CWD && eslint --ext .jsx --ext .js", @@ -127,7 +127,9 @@ "eslint-plugin-react": "^7.21.2", "flow-bin": "^0.138.0", "generate-package-json-webpack-plugin": "^2.1.1", + "glob": "^7.1.6", "json-loader": "^0.5.4", + "mkdirp": "^1.0.4", "npm-check": "^5.9.2", "react-hot-loader": "^4.13.0", "react-svg-loader": "^3.0.3", diff --git a/tools/build.js b/scripts/build.js similarity index 100% rename from tools/build.js rename to scripts/build.js diff --git a/tools/bundle.js b/scripts/bundle.js similarity index 100% rename from tools/bundle.js rename to scripts/bundle.js diff --git a/scripts/clean.js b/scripts/clean.js new file mode 100644 index 00000000..abc74458 --- /dev/null +++ b/scripts/clean.js @@ -0,0 +1,23 @@ +/* + * Cleans up the output (build) directory. + */ + +import rimraf from 'rimraf'; +import path from 'path'; + +const builddir = path.resolve(__dirname, '../build'); + + +function clean() { + return new Promise( + (resolve, reject) => rimraf(`${builddir}/*`, { + glob: { + nosort: true, + dot: true, + ignore: ['build/.git'], + }, + }, (err, result) => (err) ? reject(err) : resolve(result)), + ); +} + +export default clean; diff --git a/scripts/copy.js b/scripts/copy.js new file mode 100644 index 00000000..486f2262 --- /dev/null +++ b/scripts/copy.js @@ -0,0 +1,98 @@ +/** + * copies files to build directory + */ + +/* eslint-disable import/no-extraneous-dependencies */ + +import fs from 'fs'; +import path from 'path'; +import glob from 'glob'; +import mkdirp from 'mkdirp'; + +const builddir = path.resolve(__dirname, '../build'); +const deploydir = path.resolve(__dirname, '../deployment'); +const publicdir = path.resolve(__dirname, '../public'); +const srcdir = path.resolve(__dirname, '../src'); + +/* + * following functions are copied from + * React Starter Kit (https://www.reactstarterkit.com/) + * Copyright © 2014-present Kriasoft, LLC. All rights reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE.txt file in the root directory of this source tree. + */ + +// eslint-disable-next-line max-len +const readDir = (pattern, options) => new Promise((resolve, reject) => glob(pattern, options, (err, result) => (err ? reject(err) : resolve(result)))); + +const copyFile = (source, target) => new Promise((resolve, reject) => { + let cbCalled = false; + function done(err) { + if (!cbCalled) { + cbCalled = true; + if (err) { + reject(err); + } else { + resolve(); + } + } + } + const rd = fs.createReadStream(source); + rd.on('error', (err) => done(err)); + const wr = fs.createWriteStream(target); + wr.on('error', (err) => done(err)); + wr.on('close', (err) => done(err)); + rd.pipe(wr); +}); + +const copyDir = async (source, target) => { + const dirs = await readDir('**/*.*', { + cwd: source, + nosort: true, + dot: true, + }); + await Promise.all(dirs.map(async (dir) => { + const from = path.resolve(source, dir); + const to = path.resolve(target, dir); + mkdirp.sync(path.dirname(to)); + await copyFile(from, to); + })); +}; +/* + * ---------------------------------------------------------------------------- + */ + + + +/** + * Copies static files such as robots.txt, favicon.ico to the + * output (build) folder. + */ +async function copy() { + mkdirp.sync(`${builddir}/public/assets`); + return Promise.all([ + copyDir( + `${publicdir}`, + `${builddir}/public`, + ), + copyFile( + `${srcdir}/canvases.json`, + `${builddir}/canvases.json`, + ), + copyFile( + `${srcdir}/proxies.json`, + `${builddir}/proxies.json`, + ), + copyFile( + `${deploydir}/example-ecosystem.yml`, + `${builddir}/ecosystem.example.yml`, + ), + copyFile( + `${deploydir}/example-ecosystem-backup.yml`, + `${builddir}/ecosystem-backup.example.yml`, + ), + ]); +} + +export default copy; diff --git a/tools/minifyCss.js b/scripts/minifyCss.js similarity index 77% rename from tools/minifyCss.js rename to scripts/minifyCss.js index 3cc06e57..84f7d3e7 100644 --- a/tools/minifyCss.js +++ b/scripts/minifyCss.js @@ -4,10 +4,15 @@ */ import fs from 'fs'; +import path from 'path'; import CleanCSS from 'clean-css'; import crypto from 'crypto'; -const FOLDER = './src/styles'; +const rootdir = path.resolve(__dirname, '..'); +const assetdir = path.resolve(__dirname, '../build/public/assets'); +const builddir = path.resolve(__dirname, '../build'); + +const FOLDER = path.resolve(__dirname, '../src/styles'); const FILES = [ 'default.css', 'dark.css', @@ -39,11 +44,11 @@ async function minifyCss() { const hash = crypto.createHash('md5').update(output.styles).digest('hex'); const key = file.substr(0, file.indexOf('.')); const filename = `${key}.${hash.substr(0, 8)}.css`; - fs.writeFileSync(`./build/public/assets/${filename}`, output.styles, 'utf8'); + fs.writeFileSync(`${assetdir}/${filename}`, output.styles, 'utf8'); assets[key] = `/assets/${filename}`; }); const json = JSON.stringify(assets); - fs.writeFileSync('./build/styleassets.json', json); + fs.writeFileSync(`${builddir}/styleassets.json`, json); } export default minifyCss; diff --git a/tools/run.js b/scripts/run.js similarity index 100% rename from tools/run.js rename to scripts/run.js diff --git a/tools/clean.js b/tools/clean.js deleted file mode 100644 index a27ae1a2..00000000 --- a/tools/clean.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * React Starter Kit (https://www.reactstarterkit.com/) - * - * Copyright © 2014-present Kriasoft, LLC. All rights reserved. - * - * This source code is licensed under the MIT license found in the - * LICENSE.txt file in the root directory of this source tree. - */ - -import { cleanDir } from './lib/fs'; - -/** - * Cleans up the output (build) directory. - */ -function clean() { - return Promise.all([ - cleanDir('build/*', { - nosort: true, - dot: true, - ignore: ['build/.git'], - }), - ]); -} - -export default clean; diff --git a/tools/copy.js b/tools/copy.js deleted file mode 100644 index a9deac00..00000000 --- a/tools/copy.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - */ - -import path from 'path'; -import { writeFile, copyFile, makeDir, copyDir, cleanDir } from './lib/fs'; -import pkg from '../package.json'; - -/** - * Copies static files such as robots.txt, favicon.ico to the - * output (build) folder. - */ -async function copy() { - await makeDir('build'); - await Promise.all([ - makeDir('build/log'), - copyFile('LICENSE', 'build/LICENSE'), - copyDir('public', 'build/public'), - copyFile('src/canvases.json', 'build/canvases.json'), - copyFile('src/proxies.json', 'build/proxies.json'), - copyFile('tools/example-ecosystem.yml', 'build/ecosystem.example.yml'), - copyFile('tools/example-ecosystem-backup.yml', 'build/ecosystem-backup.example.yml'), - ]); - await makeDir('build/public/assets'); -} - -export default copy; diff --git a/tools/lib/cp.js b/tools/lib/cp.js deleted file mode 100644 index 8fa99685..00000000 --- a/tools/lib/cp.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - * React Starter Kit (https://www.reactstarterkit.com/) - * - * Copyright © 2014-present Kriasoft, LLC. All rights reserved. - * - * This source code is licensed under the MIT license found in the - * LICENSE.txt file in the root directory of this source tree. - */ - -import cp from 'child_process'; - -export const spawn = (command, args, options) => new Promise((resolve, reject) => { - cp.spawn(command, args, options).on('close', (code) => { - if (code === 0) { - resolve(); - } else { - reject(new Error(`${command} ${args.join(' ')} => ${code} (error)`)); - } - }); -}); - -export const exec = (command, options) => new Promise((resolve, reject) => { - cp.exec(command, options, (err, stdout, stderr) => { - if (err) { - reject(err); - return; - } - - resolve({ stdout, stderr }); - }); -}); - -export default { spawn, exec }; diff --git a/tools/lib/fs.js b/tools/lib/fs.js deleted file mode 100644 index 0e956e27..00000000 --- a/tools/lib/fs.js +++ /dev/null @@ -1,99 +0,0 @@ -/** - * React Starter Kit (https://www.reactstarterkit.com/) - * - * Copyright © 2014-present Kriasoft, LLC. All rights reserved. - * - * This source code is licensed under the MIT license found in the - * LICENSE.txt file in the root directory of this source tree. - */ - -import fs from 'fs'; -import path from 'path'; -import glob from 'glob'; -import mkdirp from 'mkdirp'; -import rimraf from 'rimraf'; - -export const readFile = file => new Promise((resolve, reject) => { - fs.readFile(file, 'utf8', (err, data) => (err ? reject(err) : resolve(data))); -}); - -export const writeFile = (file, contents) => new Promise((resolve, reject) => { - fs.writeFile(file, contents, 'utf8', err => (err ? reject(err) : resolve())); -}); - -export const renameFile = (source, target) => new Promise((resolve, reject) => { - fs.rename(source, target, err => (err ? reject(err) : resolve())); -}); - -export const copyFile = (source, target) => new Promise((resolve, reject) => { - let cbCalled = false; - function done(err) { - if (!cbCalled) { - cbCalled = true; - if (err) { - reject(err); - } else { - resolve(); - } - } - } - - const rd = fs.createReadStream(source); - rd.on('error', err => done(err)); - const wr = fs.createWriteStream(target); - wr.on('error', err => done(err)); - wr.on('close', err => done(err)); - rd.pipe(wr); -}); - -export const readDir = (pattern, options) => new Promise((resolve, reject) => - glob(pattern, options, (err, result) => (err ? reject(err) : resolve(result))), -); - -export const makeDir = name => new Promise((resolve, reject) => { - mkdirp(name, err => (err ? reject(err) : resolve())); -}); - -export const moveDir = async (source, target) => { - const dirs = await readDir('**/*.*', { - cwd: source, - nosort: true, - dot: true, - }); - await Promise.all(dirs.map(async (dir) => { - const from = path.resolve(source, dir); - const to = path.resolve(target, dir); - await makeDir(path.dirname(to)); - await renameFile(from, to); - })); -}; - -export const copyDir = async (source, target) => { - const dirs = await readDir('**/*.*', { - cwd: source, - nosort: true, - dot: true, - }); - await Promise.all(dirs.map(async (dir) => { - const from = path.resolve(source, dir); - const to = path.resolve(target, dir); - await makeDir(path.dirname(to)); - await copyFile(from, to); - })); -}; - -export const cleanDir = (pattern, options) => new Promise((resolve, reject) => - rimraf(pattern, { glob: options }, (err, result) => (err ? reject(err) : resolve(result))), -); - -export default { - readFile, - writeFile, - renameFile, - copyFile, - readDir, - makeDir, - copyDir, - moveDir, - cleanDir, -}; diff --git a/webpack.config.client.babel.js b/webpack.config.client.babel.js index ff094fc0..42c3b513 100644 --- a/webpack.config.client.babel.js +++ b/webpack.config.client.babel.js @@ -9,7 +9,7 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; import pkg from './package.json'; const isDebug = process.argv.includes('--debug'); -const isVerbose = process.argv.includes('--verbose'); +const VERBOSE = false; const isAnalyze = process.argv.includes('--analyze') || process.argv.includes('--analyse'); @@ -47,7 +47,7 @@ export default { output: { path: path.resolve(__dirname, './build/public/assets'), publicPath: '/assets/', - pathinfo: isVerbose, + pathinfo: VERBOSE, filename: isDebug ? '[name].js' : '[name].[chunkhash:8].js', chunkFilename: isDebug ? '[name].chunk.js' : '[name].[chunkhash:8].js', }, @@ -162,7 +162,7 @@ export default { test: /[\\/]node_modules[\\/]three[\\/]/, name: 'three', chunks: 'all', - } + }, }, }, }, diff --git a/webpack.config.web.babel.js b/webpack.config.web.babel.js index 17114a57..9ce3d1d4 100644 --- a/webpack.config.web.babel.js +++ b/webpack.config.web.babel.js @@ -9,7 +9,7 @@ import GeneratePackageJsonPlugin from 'generate-package-json-webpack-plugin'; import pkg from './package.json'; const isDebug = process.argv.includes('--debug'); -const isVerbose = process.argv.includes('--verbose'); +const VERBOSE = false; const basePackageValues = { name: pkg.name, @@ -54,7 +54,7 @@ export default { }, output: { - pathinfo: isVerbose, + pathinfo: VERBOSE, path: path.resolve(__dirname, './build'), libraryTarget: 'commonjs2', }, @@ -97,7 +97,7 @@ export default { loader: 'css-loader', options: { importLoaders: 1, - sourceMap: isDebug, + sourceMap: false, modules: false, }, }, @@ -121,7 +121,7 @@ export default { }), // create package.json for deployment new GeneratePackageJsonPlugin(basePackageValues, { - debug: true, + debug: VERBOSE, sourcePackageFilenames: [ path.resolve(__dirname, './package.json'), ],