diff --git a/package.json b/package.json
index e90fc95..05f1068 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,8 @@
},
"repository": "frontend/toolbox-utils",
"author": {
- "url": "https://github.com/frontend"
+ "url": "https://github.com/frontend",
+ "name": "Frontend Team"
},
"babel": {
"presets": [
@@ -80,7 +81,6 @@
"jquery": "^3.4.1",
"latest-version": "^5.1.0",
"merge-stream": "^1.0.1",
- "node-fetch": "^2.5.0",
"postcss-reporter": "^6.0.1",
"postcss-scss": "^2.0.0",
"stylelint": "^10.0.1",
diff --git a/tasks/prepare.js b/tasks/prepare.js
index c76cf41..56e9cee 100644
--- a/tasks/prepare.js
+++ b/tasks/prepare.js
@@ -7,7 +7,6 @@ const $ = require('gulp-load-plugins')();
const config = require('./config');
const fs = require('fs-extra');
const dirTree = require('./helpers').dirTree;
-const fetch = require('node-fetch');
const yaml = require('yamljs');
const pkg = require('./../package.json');
@@ -15,41 +14,42 @@ const cssBundles = config.bundles !== undefined && config.bundles.scss !== undef
const jsBundles = config.bundles !== undefined && config.bundles.js !== undefined;
const prepare = async (done) => {
- // Check if user is online
- const isOnline = await axios
- .get('https://google.com', { timeout: 3000 })
- .then(res => true)
- .catch(err => false);
+ let cdn;
+
+ // Get CDN from jsdeliver.
+ cdn = await axios
+ .get('https://cdn.jsdelivr.net/gh/frontend/toolbox-reader/package.json')
+ .then(res => {
+ const minor = res.data.version.split('.').splice(0, 2).join('.');
+ return `https://cdn.jsdelivr.net/gh/frontend/toolbox-reader@${minor}/build/static`;
+ })
+ .catch((err) => {
+ if (err.response) {
+ log.error(`⚠️ Got "${err.response.status} ${err.response.statusText}" status while fetching toolbox-reader online.`);
+ } else {
+ log.error(`⚠️ Could not fetch toolbox-reader online. Will try to use the offline mode.`);
+ }
+ });
// Define cdn path
const localCdn = `${homedir()}/.toolbox`;
- let cdn;
if (config.reader_path) {
cdn = config.reader_path;
} else {
- if (isOnline) {
- cdn = await axios
- .get('https://cdn.jsdelivr.net/gh/frontend/toolbox-reader/package.json')
- .then(res => {
- const minor = res.data.version.split('.').splice(0, 2).join('.');
- return `https://cdn.jsdelivr.net/gh/frontend/toolbox-reader@${minor}/build/static`;
- })
- .catch(err => log.error(err));
+ if (cdn) {
// Download Toolbox Reader bundles for future offline usage
download(`${cdn}/css/main.css`, `${localCdn}/`);
download(`${cdn}/js/main.js`, `${localCdn}/`);
- } else {
- // Retrieve local Toolbox Reader bundles
- cdn = 'toolbox';
- fs.pathExists(`${localCdn}/main.css`, (err, exists) => {
- if (err || !exists) log.error('You don\'t have any local Toolbox Reader bundles to use... Please connecte yourlsef before retrying.')
- const copyToDir = `${config.project}/${config.dest}toolbox`;
- fs.ensureDirSync(copyToDir)
- fs.copy(`${localCdn}/main.css`, `${copyToDir}/main.css`);
- fs.copy(`${localCdn}/main.js`, `${copyToDir}/main.js`);
- })
}
+
+ fs.pathExists(`${localCdn}/main.css`, (err, exists) => {
+ if (err || !exists) log.error('Unable to find a Toolbox Reader bundle locally. Make sure you are online and try again.');
+ const copyToDir = `${config.project}/${config.dest}toolbox`;
+ fs.ensureDirSync(copyToDir);
+ fs.copy(`${localCdn}/main.css`, `${copyToDir}/css/main.css`);
+ fs.copy(`${localCdn}/main.js`, `${copyToDir}/js/main.js`);
+ });
}
// Get local colors and data
@@ -113,7 +113,7 @@ const prepare = async (done) => {
window.builder = "${pkg.version}";
${ config.theme ? `window.theme = ${JSON.stringify(config.theme)};` : '' }
-
+
${config.vendors.css ? '' : ''}
${ cssBundles
? config.bundles.scss
@@ -142,10 +142,10 @@ const prepare = async (done) => {
`).appendTo('body');
}
- $(` \n`).appendTo('body');
+ $(' \n').appendTo('body');
}))
.pipe($.rename('index.html'))
.pipe(gulp.dest(config.dest, {cwd: config.project}));
-}
+};
module.exports = prepare;
diff --git a/yarn.lock b/yarn.lock
index 15d50e3..51854d6 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -6317,10 +6317,6 @@ nice-try@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.4.tgz#d93962f6c52f2c1558c0fbda6d512819f1efe1c4"
-node-fetch@^2.5.0:
- version "2.5.0"
- resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.5.0.tgz#8028c49fc1191bba56a07adc6e2a954644a48501"
-
node-forge@0.7.5:
version "0.7.5"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.7.5.tgz#6c152c345ce11c52f465c2abd957e8639cd674df"