Merge duplicate code and add verbose option on setup command

This commit is contained in:
Aurelsicoko 2018-01-16 16:18:33 +01:00
parent adb11a0b8b
commit 83e0ffd323
7 changed files with 30 additions and 42 deletions

View File

@ -29,7 +29,7 @@ cd /path/to/the/project
npm run setup
```
> Note: The `build` folders are ignored (.gitignore). If you're cloning your git repository on your server, you need to run this command on your server.
> Note: To display the build logs use the --verbose option `npm run setup --verbose`.
#### #3 - Launch the server

View File

@ -6,29 +6,6 @@
*/
/* eslint-disable */
// Retrieve remote and backend URLs.
const remoteURL = (() => {
if (window.location.port === '4000') {
return 'http://localhost:4000/admin';
}
// Relative URL (ex: /dashboard)
if (process.env.REMOTE_URL[0] === '/') {
return (window.location.origin + process.env.REMOTE_URL).replace(/\/$/, '');
}
return process.env.REMOTE_URL.replace(/\/$/, '');
})();
const backendURL = (process.env.BACKEND_URL === '/' ? window.location.origin : process.env.BACKEND_URL);
// Retrieve development URL to avoid to re-build.
const $body = document.getElementsByTagName('body')[0];
const devFrontURL = $body.getAttribute('front') ? window.location.origin + $body.getAttribute('front').replace(/\/$/, '') : null;
const devBackendURL = $body.getAttribute('back') ? window.location.origin + $body.getAttribute('back').replace(/\/$/, '') : null;
$body.removeAttribute('front');
$body.removeAttribute('back');
import './public-path';
import 'babel-polyfill';
@ -62,7 +39,7 @@ const plugins = (() => {
/* eslint-enable */
// Create redux store with history
const basename = (devFrontURL || remoteURL).replace(window.location.origin, '');
const basename = strapi.remoteURL.replace(window.location.origin, '');
const history = createHistory({
basename,
});
@ -105,7 +82,7 @@ window.onload = function onLoad() {
// Don't inject plugins in development mode.
if (window.location.port !== '4000') {
fetch(`${devFrontURL || remoteURL}/config/plugins.json`)
fetch(`${strapi.remoteURL}/config/plugins.json`)
.then(response => {
return response.json();
})
@ -114,12 +91,14 @@ if (window.location.port !== '4000') {
store.dispatch(unsetHasUserPlugin());
}
const $body = document.getElementsByTagName('body')[0];
(plugins || []).forEach(plugin => {
const script = document.createElement('script');
script.type = 'text/javascript';
script.onerror = function (oError) {
const source = new URL(oError.target.src);
const url = new URL(`${devFrontURL || remoteURL}`);
const url = new URL(`${strapi.remoteURL}`);
if (!source || !url) {
throw new Error(`Impossible to load: ${oError.target.src}`);
@ -202,8 +181,6 @@ const displayNotification = (message, status) => {
*/
window.strapi = Object.assign(window.strapi || {}, {
remoteURL: devFrontURL || remoteURL,
backendURL: devBackendURL || backendURL,
mode: process.env.MODE || 'host',
registerPlugin,
notification: {

View File

@ -1,4 +1,4 @@
// Retrieve URLs.
// Retrieve remote and backend URLs.
const remoteURL = (() => {
if (window.location.port === '4000') {
return 'http://localhost:4000/admin';
@ -11,9 +11,19 @@ const remoteURL = (() => {
return process.env.REMOTE_URL.replace(/\/$/, '');
})();
const backendURL = (process.env.BACKEND_URL === '/' ? window.location.origin : process.env.BACKEND_URL);
// Retrieve development URL to avoid to re-build.
const $body = document.getElementsByTagName('body')[0];
const devFrontURL = $body.getAttribute('front') ? window.location.origin + $body.getAttribute('front').replace(/\/$/, '') : null;
const devBackendURL = $body.getAttribute('back') ? window.location.origin + $body.getAttribute('back').replace(/\/$/, '') : null;
__webpack_public_path__ = window.location.port === '4000' ? `${window.location.origin}/` : `${(devFrontURL || remoteURL).replace(window.location.origin, '')}/`;
$body.removeAttribute('front');
$body.removeAttribute('back');
window.strapi = {
remoteURL: devFrontURL || remoteURL,
backendURL: devBackendURL || backendURL,
};
__webpack_public_path__ = window.location.port === '4000' ? `${window.location.origin}/` : `${(strapi.remoteURL).replace(window.location.origin, '')}/`;

View File

@ -48,4 +48,4 @@
"npm": ">= 3.0.0"
},
"license": "MIT"
}
}

View File

@ -10,6 +10,7 @@ shell.echo('📦 Installing packages...');
const pwd = shell.pwd();
const silent = !(process.env.npm_config_verbose === 'true');
const isDevelopmentMode = path.resolve(pwd.stdout).indexOf('strapi-admin') !== -1;
const appPath = isDevelopmentMode ? path.resolve(process.env.PWD, '..') : path.resolve(pwd.stdout, '..');
@ -19,28 +20,28 @@ shell.rm('-rf', path.resolve(appPath, 'admin', 'package-lock.json'));
// Install the project dependencies.
shell.exec(`cd ${appPath} && npm install --ignore-scripts`, {
silent: true
silent
});
// Install the administration dependencies.
shell.exec(`cd ${path.resolve(appPath, 'admin')} && npm install`, {
silent: true
silent
});
if (isDevelopmentMode) {
shell.exec(`cd ${path.resolve(appPath, 'admin')} && npm link strapi-helper-plugin && npm link strapi-utils`, {
silent: true
silent
});
} else {
shell.exec(`cd ${path.resolve(appPath, 'admin', 'node_modules', 'strapi-helper-plugin')} && npm install`, {
silent: true
silent
});
}
shell.echo('🏗 Building...');
const build = shell.exec(`cd ${path.resolve(appPath, 'admin')} && APP_PATH=${appPath} npm run build`, {
silent: false
silent
});
if (build.stderr && build.code !== 0) {
@ -58,15 +59,15 @@ if (process.env.npm_config_plugins === 'true') {
shell.echo(`🔸 Plugin - ${_.upperFirst(plugin)}`);
shell.echo('📦 Installing packages...');
shell.exec(`cd ${path.resolve(plugins, plugin)} && npm install`, {
silent: true
silent
});
shell.exec(`cd ${path.resolve(plugins, plugin, 'node_modules', 'strapi-helper-plugin')} && npm install`, {
silent: true
silent
});
shell.echo('🏗 Building...');
const build = shell.exec(`cd ${path.resolve(plugins, plugin)} && APP_PATH=${appPath} npm run build`, {
silent: true
silent
});
if (build.stderr && build.code !== 0) {

View File

@ -48,4 +48,4 @@
"npm": ">= 5.3.0"
},
"license": "MIT"
}
}

File diff suppressed because one or more lines are too long