forked from strapi/strapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
228 lines (184 loc) · 7.28 KB
/
setup.js
File metadata and controls
228 lines (184 loc) · 7.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
const shell = require('shelljs');
// 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');
}
// Store installation start date.
const silent = process.env.npm_config_debug !== 'true';
const installationStartDate = new Date();
const watcher = (label, cmd, withSuccess = true) => {
if (label.length > 0) {
shell.echo(label);
}
const data = shell.exec(cmd, {
silent,
});
if (data.stderr && data.code !== 0) {
console.error(data.stderr);
process.exit(1);
}
if (label.length > 0 && withSuccess) {
shell.echo('✅ Success');
shell.echo('');
}
};
const asyncWatcher = (label, cmd, withSuccess = true, resolve) => {
if (label.length > 0) {
shell.echo(label);
}
return shell.exec(cmd, { silent, async: true }, (code, stdout, stderr) => {
if (stderr && code !== 0) {
console.error(stderr);
process.exit(1);
}
return resolve();
});
};
shell.echo('');
shell.echo('🕓 The setup process can take few minutes.');
shell.echo('');
// Remove existing binary.
shell.rm('-f', '/usr/local/bin/strapi.js');
shell.cd('packages/strapi-utils');
watcher('📦 Linking strapi-utils...', 'npm link');
shell.cd('../strapi-lint');
watcher('📦 Linking strapi-lint', 'npm link');
shell.cd('../strapi-generate');
watcher('', 'npm install ../strapi-utils');
watcher('📦 Linking strapi-generate...', 'npm link');
shell.cd('../strapi-generate-api');
watcher('📦 Linking strapi-generate-api...', 'npm link');
shell.cd('../strapi-helper-plugin');
watcher('📦 Linking strapi-helper-plugin...', 'npm link');
shell.cd('../strapi-admin');
watcher('', 'npm link strapi-helper-plugin --no-optional');
watcher('', 'npm link strapi-utils --no-optional');
shell.rm('-f', 'package-lock.json');
// 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);
shell.cd('../strapi-generate-admin');
watcher('', 'npm link strapi-admin');
watcher('📦 Linking strapi-generate-admin...', 'npm link');
shell.cd('../strapi-generate-new');
watcher('', 'npm link strapi-utils');
watcher('📦 Linking strapi-generate-new', 'npm link');
shell.cd('../strapi-hook-mongoose');
watcher('', 'npm link strapi-utils');
watcher('📦 Linking strapi-hook-mongoose...', 'npm link');
shell.cd('../strapi-hook-knex');
watcher('📦 Linking strapi-hook-knex...', 'npm link');
shell.cd('../strapi-hook-bookshelf');
watcher('', 'npm link strapi-utils');
watcher('', 'npm link strapi-hook-knex');
watcher('📦 Linking strapi-hook-bookshelf...', 'npm link');
shell.cd('../strapi');
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',
);
watcher('📦 Linking strapi...', 'npm link');
shell.cd('../strapi-plugin-graphql');
watcher('', 'npm link strapi-utils');
watcher('📦 Linking strapi-plugin-graphql...', 'npm link --no-optional', false);
// Plugin services
shell.cd('../strapi-provider-upload-local');
watcher('📦 Linking strapi-provider-upload-local...', 'npm link --no-optional', false);
shell.cd('../strapi-provider-email-sendmail');
watcher('📦 Linking strapi-provider-email-sendmail...', 'npm link --no-optional', false);
// Plugins with admin
shell.cd('../strapi-plugin-documentation');
shell.rm('-f', 'package-lock.json');
watcher('', 'npm link strapi-helper-plugin --no-optional');
watcher('📦 Linking strapi-plugin-documentation...', 'npm link --no-optional', false);
shell.cd('../strapi-plugin-email');
shell.rm('-f', 'package-lock.json');
watcher('', 'npm link strapi-helper-plugin --no-optional');
watcher('', 'npm link strapi-provider-email-sendmail --no-optional');
watcher('', 'npm link strapi-utils --no-optional');
watcher('📦 Linking strapi-plugin-email...', 'npm link --no-optional', false);
shell.cd('../strapi-plugin-users-permissions');
watcher('', 'npm link strapi-helper-plugin --no-optional');
watcher('', 'npm link strapi-utils --no-optional');
shell.rm('-f', 'package-lock.json');
watcher('📦 Linking strapi-plugin-users-permissions...', 'npm link --no-optional', false);
shell.cd('../strapi-plugin-content-manager');
watcher('', 'npm link strapi-helper-plugin --no-optional');
watcher('', 'npm link strapi-utils --no-optional');
shell.rm('-f', 'package-lock.json');
watcher('📦 Linking strapi-plugin-content-manager...', 'npm link --no-optional', false);
shell.cd('../strapi-plugin-settings-manager');
watcher('', 'npm link strapi-helper-plugin --no-optional');
shell.rm('-f', 'package-lock.json');
watcher('📦 Linking strapi-plugin-settings-manager...', 'npm link --no-optional', false);
// Plugins with admin and other plugin's dependencies
shell.cd('../strapi-plugin-upload');
watcher('', 'npm link strapi-helper-plugin --no-optional');
watcher('', 'npm link strapi-provider-upload-local --no-optional');
watcher('', 'npm link strapi-utils --no-optional');
shell.rm('-f', 'package-lock.json');
watcher('📦 Linking strapi-plugin-upload...', 'npm link --no-optional', false);
shell.cd('../strapi-plugin-content-type-builder');
watcher('', 'npm link strapi-helper-plugin --no-optional');
watcher('', 'npm link strapi-generate --no-optional');
watcher('', 'npm link strapi-generate-api --no-optional');
shell.rm('-f', 'package-lock.json');
watcher('📦 Linking strapi-plugin-content-type-builder...', 'npm link --no-optional', false);
const pluginsToBuild = [
'admin',
'content-manager',
'content-type-builder',
'documentation',
'upload',
'email',
'users-permissions',
'settings-manager',
];
const buildPlugins = async () => {
const build = pckgName => {
return new Promise(resolve => {
const name = pckgName === 'admin' ? pckgName : `plugin-${pckgName}`;
asyncWatcher(
`🏗 Building ${name}...`,
`cd ../strapi-${name} && cross-env IS_MONOREPO=true npm run build`,
false,
resolve,
);
});
};
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}...`, 'cross-env IS_MONOREPO=true 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.`,
);
};
setup();