| 
									
										
										
										
											2017-03-14 12:25:39 +01:00
										 |  |  | const shell = require('shelljs'); | 
					
						
							| 
									
										
										
										
											2018-04-17 10:30:30 +02:00
										 |  |  | // Check npm version
 | 
					
						
							|  |  |  | const npm = shell.exec('npm -v').stdout; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (parseFloat(npm) < 5) { | 
					
						
							|  |  |  |   throw new Error('[ERROR: Strapi] You need npm version @>=5'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const nodeVersion = shell.exec('node -v').stdout.replace('v', ''); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (parseFloat(nodeVersion) < 8.6) { | 
					
						
							|  |  |  |   throw new Error('[ERROR: Strapi] You need to use node version @>=9'); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-14 12:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 22:21:08 +02:00
										 |  |  | // Store installation start date.
 | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | const silent = process.env.npm_config_debug !== 'true'; | 
					
						
							| 
									
										
										
										
											2017-08-09 22:21:08 +02:00
										 |  |  | const installationStartDate = new Date(); | 
					
						
							| 
									
										
										
										
											2018-04-17 11:43:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-09 17:09:54 +01:00
										 |  |  | const watcher = (label, cmd, withSuccess = true) => { | 
					
						
							|  |  |  |   if (label.length > 0) { | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  |     shell.echo(label); | 
					
						
							| 
									
										
										
										
											2018-01-09 17:09:54 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const data = shell.exec(cmd, { | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  |     silent | 
					
						
							| 
									
										
										
										
											2018-01-09 17:09:54 +01:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (data.stderr && data.code !== 0) { | 
					
						
							|  |  |  |     console.error(data.stderr); | 
					
						
							|  |  |  |     process.exit(1); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (label.length > 0 && withSuccess) { | 
					
						
							|  |  |  |     shell.echo('✅  Success'); | 
					
						
							|  |  |  |     shell.echo(''); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-04-17 10:30:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-09 17:09:54 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 11:51:16 +02:00
										 |  |  | const asyncWatcher = (label, cmd, withSuccess = true, resolve) => { | 
					
						
							| 
									
										
										
										
											2018-04-17 11:43:47 +02:00
										 |  |  |   if (label.length > 0) { | 
					
						
							|  |  |  |     shell.echo(label); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 11:51:16 +02:00
										 |  |  |   return shell.exec(cmd, { silent, async: true }, (code, stdout, stderr) => { | 
					
						
							|  |  |  |     if (stderr && code !== 0) { | 
					
						
							|  |  |  |       console.error(stderr); | 
					
						
							| 
									
										
										
										
											2018-04-17 11:43:47 +02:00
										 |  |  |       process.exit(1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 11:51:16 +02:00
										 |  |  |     return resolve(); | 
					
						
							| 
									
										
										
										
											2018-04-17 11:43:47 +02:00
										 |  |  |   }); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-09 17:09:54 +01:00
										 |  |  | shell.echo(''); | 
					
						
							|  |  |  | shell.echo('🕓  The setup process can take few minutes.'); | 
					
						
							|  |  |  | shell.echo(''); | 
					
						
							| 
									
										
										
										
											2017-08-09 22:21:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-14 12:25:39 +01:00
										 |  |  | // Remove existing binary.
 | 
					
						
							|  |  |  | shell.rm('-f', '/usr/local/bin/strapi.js'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-17 16:48:09 +02:00
										 |  |  | shell.cd('packages/strapi-utils'); | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | watcher('📦  Linking strapi-utils...', 'npm link'); | 
					
						
							| 
									
										
										
										
											2017-08-09 22:09:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-17 16:48:09 +02:00
										 |  |  | shell.cd('../strapi-generate'); | 
					
						
							| 
									
										
										
										
											2018-01-09 17:09:54 +01:00
										 |  |  | watcher('', 'npm install ../strapi-utils'); | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | watcher('📦  Linking strapi-generate...', 'npm link'); | 
					
						
							| 
									
										
										
										
											2017-08-09 22:09:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-30 19:30:06 +02:00
										 |  |  | shell.cd('../strapi-generate-api'); | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | watcher('📦  Linking strapi-generate-api...', 'npm link'); | 
					
						
							| 
									
										
										
										
											2017-09-30 19:30:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-22 18:29:02 +02:00
										 |  |  | shell.cd('../strapi-helper-plugin'); | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | watcher('📦  Linking strapi-helper-plugin...', 'npm link'); | 
					
						
							| 
									
										
										
										
											2017-08-22 18:29:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-17 16:48:09 +02:00
										 |  |  | shell.cd('../strapi-admin'); | 
					
						
							| 
									
										
										
										
											2018-01-10 15:38:28 +01:00
										 |  |  | watcher('', 'npm install ../strapi-helper-plugin --no-optional'); | 
					
						
							|  |  |  | watcher('', 'npm install ../strapi-utils --no-optional'); | 
					
						
							| 
									
										
										
										
											2017-08-22 18:29:02 +02:00
										 |  |  | shell.rm('-f', 'package-lock.json'); | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Without these line Travis failed.
 | 
					
						
							|  |  |  | if (shell.test('-e', 'admin/src/config/plugins.json') === false) { | 
					
						
							|  |  |  |   shell.config.silent = silent; | 
					
						
							|  |  |  |   shell.cd('admin/src/config/'); | 
					
						
							|  |  |  |   shell.ShellString('[]').to('plugins.json'); | 
					
						
							|  |  |  |   shell.cd('../../../'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | watcher('📦  Linking strapi-admin', 'npm link --no-optional', false); | 
					
						
							| 
									
										
										
										
											2017-08-09 22:09:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-17 16:48:09 +02:00
										 |  |  | shell.cd('../strapi-generate-admin'); | 
					
						
							| 
									
										
										
										
											2018-01-09 17:09:54 +01:00
										 |  |  | watcher('', 'npm install ../strapi-admin'); | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | watcher('📦  Linking strapi-generate-admin...', 'npm link'); | 
					
						
							| 
									
										
										
										
											2017-08-09 22:09:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-17 16:48:09 +02:00
										 |  |  | shell.cd('../strapi-generate-new'); | 
					
						
							| 
									
										
										
										
											2018-01-09 17:09:54 +01:00
										 |  |  | watcher('', 'npm install ../strapi-utils'); | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | watcher('📦  Linking strapi-generate-new', 'npm link'); | 
					
						
							| 
									
										
										
										
											2017-08-09 22:09:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-17 16:48:09 +02:00
										 |  |  | shell.cd('../strapi-mongoose'); | 
					
						
							| 
									
										
										
										
											2018-01-09 17:09:54 +01:00
										 |  |  | watcher('', 'npm install ../strapi-utils'); | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | watcher('📦  Linking strapi-mongoose...', 'npm link'); | 
					
						
							| 
									
										
										
										
											2017-08-09 22:09:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-02 18:33:12 +02:00
										 |  |  | shell.cd('../strapi-knex'); | 
					
						
							|  |  |  | watcher('📦  Linking strapi-knex...', 'npm link'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | shell.cd('../strapi-bookshelf'); | 
					
						
							|  |  |  | watcher('', 'npm install ../strapi-utils'); | 
					
						
							|  |  |  | watcher('', 'npm install ../strapi-knex'); | 
					
						
							|  |  |  | watcher('📦  Linking strapi-bookshelf...', 'npm link'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-17 16:48:09 +02:00
										 |  |  | shell.cd('../strapi'); | 
					
						
							| 
									
										
										
										
											2018-01-09 17:09:54 +01:00
										 |  |  | watcher('', 'npm install ../strapi-generate ../strapi-generate-admin ../strapi-generate-api ../strapi-generate-new ../strapi-generate-plugin ../strapi-generate-policy ../strapi-generate-service ../strapi-utils'); | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | watcher('📦  Linking strapi...', 'npm link'); | 
					
						
							| 
									
										
										
										
											2017-08-09 22:09:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 10:30:30 +02:00
										 |  |  | // Upload plugins
 | 
					
						
							|  |  |  | shell.cd('../strapi-upload-local'); | 
					
						
							|  |  |  | watcher('📦  Linking strapi-upload-local...', 'npm link --no-optional', false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Plugins with admin
 | 
					
						
							| 
									
										
										
										
											2017-11-20 15:10:40 +01:00
										 |  |  | shell.cd('../strapi-plugin-email'); | 
					
						
							|  |  |  | shell.rm('-f', 'package-lock.json'); | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | watcher('📦  Linking strapi-plugin-email...', 'npm link --no-optional', false); | 
					
						
							| 
									
										
										
										
											2017-11-20 15:10:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 10:11:16 +01:00
										 |  |  | shell.cd('../strapi-plugin-users-permissions'); | 
					
						
							| 
									
										
										
										
											2018-01-10 15:38:28 +01:00
										 |  |  | watcher('', 'npm install ../strapi-helper-plugin --no-optional'); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:11:16 +01:00
										 |  |  | shell.rm('-f', 'package-lock.json'); | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | watcher('📦  Linking strapi-plugin-users-permissions...', 'npm link --no-optional', false); | 
					
						
							| 
									
										
										
										
											2017-11-14 10:11:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 22:09:41 +02:00
										 |  |  | shell.cd('../strapi-plugin-content-manager'); | 
					
						
							| 
									
										
										
										
											2018-01-10 15:38:28 +01:00
										 |  |  | watcher('', 'npm install ../strapi-helper-plugin --no-optional'); | 
					
						
							| 
									
										
										
										
											2017-08-09 22:09:41 +02:00
										 |  |  | shell.rm('-f', 'package-lock.json'); | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | watcher('📦  Linking strapi-plugin-content-manager...', 'npm link --no-optional', false); | 
					
						
							| 
									
										
										
										
											2017-08-09 22:09:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | shell.cd('../strapi-plugin-settings-manager'); | 
					
						
							| 
									
										
										
										
											2018-01-10 15:38:28 +01:00
										 |  |  | watcher('', 'npm install ../strapi-helper-plugin --no-optional'); | 
					
						
							| 
									
										
										
										
											2017-08-09 22:09:41 +02:00
										 |  |  | shell.rm('-f', 'package-lock.json'); | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | watcher('📦  Linking strapi-plugin-settings-manager...', 'npm link --no-optional', false); | 
					
						
							| 
									
										
										
										
											2018-02-08 12:01:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-20 15:57:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 10:30:30 +02:00
										 |  |  | // Plugins with admin and other plugin's dependencies
 | 
					
						
							| 
									
										
										
										
											2018-02-23 15:14:21 +01:00
										 |  |  | shell.cd('../strapi-plugin-upload'); | 
					
						
							|  |  |  | watcher('', 'npm install ../strapi-helper-plugin --no-optional'); | 
					
						
							| 
									
										
										
										
											2018-02-23 15:35:46 +01:00
										 |  |  | watcher('', 'npm install ../strapi-upload-local --no-optional'); | 
					
						
							| 
									
										
										
										
											2018-02-23 15:14:21 +01:00
										 |  |  | shell.rm('-f', 'package-lock.json'); | 
					
						
							|  |  |  | watcher('📦  Linking strapi-plugin-upload...', 'npm link --no-optional', false); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 13:48:22 +02:00
										 |  |  | shell.cd('../strapi-plugin-content-type-builder'); | 
					
						
							| 
									
										
										
										
											2018-01-10 15:38:28 +01:00
										 |  |  | watcher('', 'npm install ../strapi-helper-plugin --no-optional'); | 
					
						
							|  |  |  | watcher('', 'npm install ../strapi-generate --no-optional'); | 
					
						
							|  |  |  | watcher('', 'npm install ../strapi-generate-api --no-optional'); | 
					
						
							| 
									
										
										
										
											2017-09-08 13:48:22 +02:00
										 |  |  | shell.rm('-f', 'package-lock.json'); | 
					
						
							| 
									
										
										
										
											2018-01-19 14:50:34 +01:00
										 |  |  | watcher('📦  Linking strapi-plugin-content-type-builder...', 'npm link --no-optional', false); | 
					
						
							| 
									
										
										
										
											2018-04-17 10:30:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 14:09:59 +02:00
										 |  |  | const pluginsToBuild = ['admin', 'content-manager', 'content-type-builder', 'upload', 'users-permissions', 'settings-manager']; | 
					
						
							| 
									
										
										
										
											2018-04-17 10:30:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 11:43:47 +02:00
										 |  |  | const buildPlugins = async () => { | 
					
						
							|  |  |  |   const build = (pckgName) => { | 
					
						
							| 
									
										
										
										
											2018-04-18 11:51:16 +02:00
										 |  |  |     return new Promise(resolve => { | 
					
						
							| 
									
										
										
										
											2018-04-17 11:43:47 +02:00
										 |  |  |       const name = pckgName === 'admin' ? pckgName: `plugin-${pckgName}`; | 
					
						
							| 
									
										
										
										
											2018-04-18 11:51:16 +02:00
										 |  |  |       asyncWatcher(`🏗  Building ${name}...`, `cd ../strapi-${name} && npm run build`, false, resolve); | 
					
						
							| 
									
										
										
										
											2018-04-17 11:43:47 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return Promise.all(pluginsToBuild.map(plugin => build(plugin))); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const setup = async () => { | 
					
						
							|  |  |  |   if (process.env.npm_config_build) { | 
					
						
							|  |  |  |     if (process.platform === 'darwin') { // Allow async build for darwin platform
 | 
					
						
							|  |  |  |       await buildPlugins(); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       pluginsToBuild.map(name => { | 
					
						
							|  |  |  |         const pluginName = name === 'admin' ? name : `plugin-${name}`; | 
					
						
							|  |  |  |         shell.cd(`../strapi-${pluginName}`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return watcher(`🏗  Building ${pluginName}...`, 'npm run build'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Log installation duration.
 | 
					
						
							|  |  |  |   const installationEndDate = new Date(); | 
					
						
							|  |  |  |   const duration = (installationEndDate.getTime() - installationStartDate.getTime()) / 1000; | 
					
						
							|  |  |  |   shell.echo('✅  Strapi has been succesfully installed.'); | 
					
						
							|  |  |  |   shell.echo(`⏳  The installation took ${Math.floor(duration / 60) > 0 ? `${Math.floor(duration / 60)} minutes and ` : ''}${Math.floor(duration % 60)} seconds.`); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-09-08 13:48:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 14:09:59 +02:00
										 |  |  | setup(); |