eip-s3-deploy 2.2.1 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deploy.js +78 -3
- package/deployment.lock +1 -1
- package/package.json +1 -1
- package/test/example.html +1 -1
package/deploy.js
CHANGED
|
@@ -9,7 +9,9 @@ const handlebars = require ( 'handlebars' );
|
|
|
9
9
|
const mime = require ( 'mime' );
|
|
10
10
|
const progress = require ( 'cli-progress' );
|
|
11
11
|
|
|
12
|
-
const COMMAND_OPTIONS = [ '-f', '--force', '-ff', '--folderFilter', '-e', '--env', '-v', '--verbose' ];
|
|
12
|
+
const COMMAND_OPTIONS = [ '-f', '--force', '-ff', '--folderFilter', '-e', '--env', '-v', '--verbose', '-log', '-unattended' ];
|
|
13
|
+
const logOutputRequested = process.argv.includes ( '-log' ) || process.argv.includes ( '--log' );
|
|
14
|
+
const unattendedMode = process.argv.includes ( '-unattended' ) || process.argv.includes ( '--unattended' );
|
|
13
15
|
const forceRedeploy = process.argv.includes ( '-f' ) || process.argv.includes ( '--force' );
|
|
14
16
|
const verboseOutput = process.argv.includes ( '-v' ) || process.argv.includes ( '--verbose' );
|
|
15
17
|
|
|
@@ -58,6 +60,48 @@ const calculateMD5 = async ( filePath ) => {
|
|
|
58
60
|
return crypto.createHash ( 'md5' ).update ( content ).digest ( 'hex' );
|
|
59
61
|
};
|
|
60
62
|
|
|
63
|
+
const readline = require ( 'readline' );
|
|
64
|
+
|
|
65
|
+
const getUserConfirmation = async ( env, destinations ) => {
|
|
66
|
+
const projectName = await getProjectName (); // returns a promise now ✅
|
|
67
|
+
|
|
68
|
+
const rl = readline.createInterface ( {
|
|
69
|
+
input: process.stdin,
|
|
70
|
+
output: process.stdout
|
|
71
|
+
} );
|
|
72
|
+
|
|
73
|
+
const intro = projectName
|
|
74
|
+
? `🔒 You are about to deploy \x1b[38;5;190m${projectName}\x1b[0m to the \x1b[38;5;190m${env}\x1b[0m environment.\n`
|
|
75
|
+
: `🔒 You are about to deploy to the \x1b[38;5;190m${env}\x1b[0m environment.\n`;
|
|
76
|
+
|
|
77
|
+
const targets =
|
|
78
|
+
`\nThe project will be deployed to:\n\x1b[38;5;214m→ ${destinations.join ( ',\n→ ' )}\x1b[0m\n\n`;
|
|
79
|
+
|
|
80
|
+
return new Promise ( ( resolve ) => {
|
|
81
|
+
rl.question (
|
|
82
|
+
`\n${intro}${targets}` +
|
|
83
|
+
'Press ENTER to proceed or type anything else then ENTER to abort (or Ctrl+C): ',
|
|
84
|
+
( answer ) => {
|
|
85
|
+
rl.close ();
|
|
86
|
+
resolve ( answer.trim () === '' );
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
} );
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const getProjectName = () => {
|
|
93
|
+
const packageJsonPath = path.join ( process.cwd (), 'package.json' );
|
|
94
|
+
|
|
95
|
+
return fs.access ( packageJsonPath )
|
|
96
|
+
.then ( () => fs.readFile ( packageJsonPath, 'utf8' ) )
|
|
97
|
+
.then ( ( data ) => {
|
|
98
|
+
const packageJson = JSON.parse ( data );
|
|
99
|
+
|
|
100
|
+
return packageJson.name || 'Unknown Project';
|
|
101
|
+
} )
|
|
102
|
+
.catch ( () => null );
|
|
103
|
+
};
|
|
104
|
+
|
|
61
105
|
const deploy = async () => {
|
|
62
106
|
|
|
63
107
|
if ( process.argv.length <= 2 || process.argv.includes ( '--help' ) || process.argv.includes ( '-h' ) || process.argv.includes ( 'help' ) ) {
|
|
@@ -154,6 +198,33 @@ const deploy = async () => {
|
|
|
154
198
|
return;
|
|
155
199
|
}
|
|
156
200
|
|
|
201
|
+
if ( logOutputRequested ) {
|
|
202
|
+
const list = ( forceRedeploy ? scannedFiles : filesToUpload );
|
|
203
|
+
process.stdout.write ( '\x1b[38;5;245m\nFiles to be deployed:\x1b[0m\n' );
|
|
204
|
+
list.forEach ( f => process.stdout.write ( `${f.replace ( process.cwd (), '' )}\n` ) );
|
|
205
|
+
process.stdout.write ( '-------------------\n' );
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if ( !unattendedMode ) {
|
|
209
|
+
// ------------------------------------------------------------------
|
|
210
|
+
// Guard-rail: require explicit user confirmation
|
|
211
|
+
const okToProceed = await getUserConfirmation (
|
|
212
|
+
environment,
|
|
213
|
+
config.bucket.map ( ( b, i ) => `${b}/${config.folder[ i ] || ''}` )
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
if ( !okToProceed ) {
|
|
217
|
+
process.stdout.write ( '\x1b[38;5;196mDeployment cancelled by user.\x1b[0m\n' );
|
|
218
|
+
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
// ------------------------------------------------------------------
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
process.stdout.write ( '\x1b[38;5;214mUnattended mode enabled, proceeding with deployment...\x1b[0m\n' );
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
process.stdout.write ( '\n' );
|
|
157
228
|
const progressBar = new progress.SingleBar ( {
|
|
158
229
|
format: '\x1b[38;5;214m🚀 Deploying [\x1b[38;5;190m{bar}\x1b[0m\x1b[38;5;214m] {percentage}% | ETA: {eta}s | {value}/{total}',
|
|
159
230
|
barCompleteChar: '#',
|
|
@@ -235,7 +306,7 @@ const deploy = async () => {
|
|
|
235
306
|
environment: environment,
|
|
236
307
|
timestamp: Date.now ()
|
|
237
308
|
} ];
|
|
238
|
-
if ( deploymentReport.length > 0 ){
|
|
309
|
+
if ( deploymentReport.length > 0 && config?.deploymentReportEnabled !== false ){
|
|
239
310
|
await fetch ( 'https://tools.eip.telegraph.co.uk/v1/healthcheck/deployment', {
|
|
240
311
|
method: 'POST',
|
|
241
312
|
headers: {
|
|
@@ -243,6 +314,9 @@ const deploy = async () => {
|
|
|
243
314
|
},
|
|
244
315
|
body: JSON.stringify ( { deployments: deploymentReport } )
|
|
245
316
|
} );
|
|
317
|
+
|
|
318
|
+
process.stdout.write ( '-------------------\n' );
|
|
319
|
+
process.stdout.write ( '✅ \x1b[38;5;190mDeployment report has been sent.\x1b[0m\n' );
|
|
246
320
|
}
|
|
247
321
|
|
|
248
322
|
process.stdout.write ( '-------------------\n' );
|
|
@@ -260,12 +334,13 @@ const deploy = async () => {
|
|
|
260
334
|
const showHelp = () => {
|
|
261
335
|
console.log ( 'S3 Deploy Script' );
|
|
262
336
|
console.log ( 'Usage:' );
|
|
263
|
-
console.log ( ' s3-deploy <environment_name> [-f|--force] [-ff|--folderFilter <folder_filter>] [-e|--env <environment_name>]' );
|
|
337
|
+
console.log ( ' s3-deploy <environment_name> [-f|--force] [-ff|--folderFilter <folder_filter>] [-e|--env <environment_name>] [-log]' );
|
|
264
338
|
console.log ( 'Options:' );
|
|
265
339
|
console.log ( ' -f, --force Force redeployment of files' );
|
|
266
340
|
console.log ( ' -ff, --folderFilter Specify a single folder to deploy' );
|
|
267
341
|
console.log ( ' -e, --env Specify the environment for deployment' );
|
|
268
342
|
console.log ( ' -v, --verbose Print more output' );
|
|
343
|
+
console.log ( ' -log List every file that will be uploaded before confirmation' );
|
|
269
344
|
console.log ( 'Examples:' );
|
|
270
345
|
console.log ( ' s3-deploy test' );
|
|
271
346
|
console.log ( ' s3-deploy production --force' );
|
package/deployment.lock
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"/test/folder1/file2.txt": "d41d8cd98f00b204e9800998ecf8427e",
|
|
13
13
|
"/test/folder2/file1.txt": "d41d8cd98f00b204e9800998ecf8427e",
|
|
14
14
|
"/test/folder2/file2.txt": "d41d8cd98f00b204e9800998ecf8427e",
|
|
15
|
-
"/test/example.html": "
|
|
15
|
+
"/test/example.html": "47caf57861b1dd625f93f21871503582"
|
|
16
16
|
},
|
|
17
17
|
"prod": {
|
|
18
18
|
"/test/file1.txt": "f5b5ed0c72f4e9984c3e7a8b18c08c2b",
|
package/package.json
CHANGED
package/test/example.html
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
border-radius: 4px;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
/* PrismJS 1.29
|
|
29
|
+
/* PrismJS 1.29
|
|
30
30
|
https://prismjs.com/download.html#themes=prism-tomorrow&languages=markup+css+clike+javascript */
|
|
31
31
|
code[class*=language-],pre[class*=language-]{color:#ccc;background:0 0;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:#2d2d2d}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.block-comment,.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#999}.token.punctuation{color:#ccc}.token.attr-name,.token.deleted,.token.namespace,.token.tag{color:#e2777a}.token.function-name{color:#6196cc}.token.boolean,.token.function,.token.number{color:#f08d49}.token.class-name,.token.constant,.token.property,.token.symbol{color:#f8c555}.token.atrule,.token.builtin,.token.important,.token.keyword,.token.selector{color:#cc99cd}.token.attr-value,.token.char,.token.regex,.token.string,.token.variable{color:#7ec699}.token.entity,.token.operator,.token.url{color:#67cdcc}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}.token.inserted{color:green}
|
|
32
32
|
|