eip-s3-deploy 2.2.1 → 2.2.2

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 CHANGED
@@ -9,7 +9,8 @@ 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' ];
13
+ const logOutputRequested = process.argv.includes ( '-log' ) || process.argv.includes ( '--log' );
13
14
  const forceRedeploy = process.argv.includes ( '-f' ) || process.argv.includes ( '--force' );
14
15
  const verboseOutput = process.argv.includes ( '-v' ) || process.argv.includes ( '--verbose' );
15
16
 
@@ -58,6 +59,48 @@ const calculateMD5 = async ( filePath ) => {
58
59
  return crypto.createHash ( 'md5' ).update ( content ).digest ( 'hex' );
59
60
  };
60
61
 
62
+ const readline = require ( 'readline' );
63
+
64
+ const getUserConfirmation = async ( env, destinations ) => {
65
+ const projectName = await getProjectName (); // returns a promise now ✅
66
+
67
+ const rl = readline.createInterface ( {
68
+ input: process.stdin,
69
+ output: process.stdout
70
+ } );
71
+
72
+ const intro = projectName
73
+ ? `🔒 You are about to deploy \x1b[38;5;190m${projectName}\x1b[0m to the \x1b[38;5;190m${env}\x1b[0m environment.\n`
74
+ : `🔒 You are about to deploy to the \x1b[38;5;190m${env}\x1b[0m environment.\n`;
75
+
76
+ const targets =
77
+ `\nThe project will be deployed to:\n\x1b[38;5;214m→ ${destinations.join ( ',\n→ ' )}\x1b[0m\n\n`;
78
+
79
+ return new Promise ( ( resolve ) => {
80
+ rl.question (
81
+ `\n${intro}${targets}` +
82
+ 'Press ENTER to proceed or type anything else then ENTER to abort (or Ctrl+C): ',
83
+ ( answer ) => {
84
+ rl.close ();
85
+ resolve ( answer.trim () === '' );
86
+ }
87
+ );
88
+ } );
89
+ };
90
+
91
+ const getProjectName = () => {
92
+ const packageJsonPath = path.join ( process.cwd (), 'package.json' );
93
+
94
+ return fs.access ( packageJsonPath )
95
+ .then ( () => fs.readFile ( packageJsonPath, 'utf8' ) )
96
+ .then ( ( data ) => {
97
+ const packageJson = JSON.parse ( data );
98
+
99
+ return packageJson.name || 'Unknown Project';
100
+ } )
101
+ .catch ( () => null );
102
+ };
103
+
61
104
  const deploy = async () => {
62
105
 
63
106
  if ( process.argv.length <= 2 || process.argv.includes ( '--help' ) || process.argv.includes ( '-h' ) || process.argv.includes ( 'help' ) ) {
@@ -154,6 +197,28 @@ const deploy = async () => {
154
197
  return;
155
198
  }
156
199
 
200
+ if ( logOutputRequested ) {
201
+ const list = ( forceRedeploy ? scannedFiles : filesToUpload );
202
+ process.stdout.write ( '\x1b[38;5;245m\nFiles to be deployed:\x1b[0m\n' );
203
+ list.forEach ( f => process.stdout.write ( `${f.replace ( process.cwd (), '' )}\n` ) );
204
+ process.stdout.write ( '-------------------\n' );
205
+ }
206
+
207
+ // ------------------------------------------------------------------
208
+ // Guard-rail: require explicit user confirmation
209
+ const okToProceed = await getUserConfirmation (
210
+ environment,
211
+ config.bucket.map ( ( b, i ) => `${b}/${config.folder[ i ] || ''}` )
212
+ );
213
+
214
+ if ( !okToProceed ) {
215
+ process.stdout.write ( '\x1b[38;5;196mDeployment cancelled by user.\x1b[0m\n' );
216
+
217
+ return;
218
+ }
219
+ // ------------------------------------------------------------------
220
+
221
+ process.stdout.write ( '\n' );
157
222
  const progressBar = new progress.SingleBar ( {
158
223
  format: '\x1b[38;5;214m🚀 Deploying [\x1b[38;5;190m{bar}\x1b[0m\x1b[38;5;214m] {percentage}% | ETA: {eta}s | {value}/{total}',
159
224
  barCompleteChar: '#',
@@ -235,7 +300,7 @@ const deploy = async () => {
235
300
  environment: environment,
236
301
  timestamp: Date.now ()
237
302
  } ];
238
- if ( deploymentReport.length > 0 ){
303
+ if ( deploymentReport.length > 0 && config?.deploymentReportEnabled !== false ){
239
304
  await fetch ( 'https://tools.eip.telegraph.co.uk/v1/healthcheck/deployment', {
240
305
  method: 'POST',
241
306
  headers: {
@@ -243,6 +308,9 @@ const deploy = async () => {
243
308
  },
244
309
  body: JSON.stringify ( { deployments: deploymentReport } )
245
310
  } );
311
+
312
+ process.stdout.write ( '-------------------\n' );
313
+ process.stdout.write ( '✅ \x1b[38;5;190mDeployment report has been sent.\x1b[0m\n' );
246
314
  }
247
315
 
248
316
  process.stdout.write ( '-------------------\n' );
@@ -260,12 +328,13 @@ const deploy = async () => {
260
328
  const showHelp = () => {
261
329
  console.log ( 'S3 Deploy Script' );
262
330
  console.log ( 'Usage:' );
263
- console.log ( ' s3-deploy <environment_name> [-f|--force] [-ff|--folderFilter <folder_filter>] [-e|--env <environment_name>]' );
331
+ console.log ( ' s3-deploy <environment_name> [-f|--force] [-ff|--folderFilter <folder_filter>] [-e|--env <environment_name>] [-log]' );
264
332
  console.log ( 'Options:' );
265
333
  console.log ( ' -f, --force Force redeployment of files' );
266
334
  console.log ( ' -ff, --folderFilter Specify a single folder to deploy' );
267
335
  console.log ( ' -e, --env Specify the environment for deployment' );
268
336
  console.log ( ' -v, --verbose Print more output' );
337
+ console.log ( ' -log List every file that will be uploaded before confirmation' );
269
338
  console.log ( 'Examples:' );
270
339
  console.log ( ' s3-deploy test' );
271
340
  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": "d3ee67eb6e0f33d59c944fb4786359f3"
15
+ "/test/example.html": "47caf57861b1dd625f93f21871503582"
16
16
  },
17
17
  "prod": {
18
18
  "/test/file1.txt": "f5b5ed0c72f4e9984c3e7a8b18c08c2b",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eip-s3-deploy",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Deploy static websites to S3 - all files will be public",
5
5
  "main": "deploy.js",
6
6
  "bin": {
package/test/example.html CHANGED
@@ -26,7 +26,7 @@
26
26
  border-radius: 4px;
27
27
  }
28
28
 
29
- /* PrismJS 1.29.0
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