let parser = require('@architect/parser'); let fs = require('fs'); const INDEX_HTML = 'public/index.html'; const env = process.env.ARC_DEPLOY || 'staging'; const region = process.env.AWS_REGION; const isOGS3 = region === 'us-east-1'; const S3domain = isOGS3 ? `https://s3.amazonaws.com/` : `https://s3-${region}.amazonaws.com/`; // 0. read bucket info from arc file let arc = parser(fs.readFileSync('.arc').toString()); let bucket = arc.static[(env === 'production' ? 1 : 0)][1]; // 1. based on env assemble proper js and css url (100% stolen from // arc-repos/arc-functions/src/http/helpers/_static.js let url = S3domain + bucket; // 2. read public/index.html let html = fs.readFileSync(INDEX_HTML).toString(); // 3. interpolate // munge css html = html.replace(/stylesheet" href="(.*\.css)"/i, 'stylesheet" href="' + url + '/$1"'); // munge js html = html.replace(/script src="(.*\.js)"/i, 'script src="' + url + '/$1"'); // 4. dump to stdout console.log('\nOverwriting URLs in public/index.html...'); fs.writeFileSync(INDEX_HTML, html, 'utf-8'); console.log('... done.');