Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Netlify Webhook Codeload from different website
var shell = require('shelljs');
var fs = require('fs-extra');
var path = require('path');
console.log('WEBHOOK_BODY', process.env.WEBHOOK_BODY);
if (!shell.which('git')) {
shell.echo('Sorry, this script requires git');
shell.exit(1);
}
if (
shell.exec(
'curl https://codeload.github.com/jaredpalmer/formik/tar.gz/master | tar -xz --strip=0 formik-master/'
).code !== 0
) {
shell.echo('Error: codeload failed');
shell.exit(1);
}
shell.cd('formik-master/website');
// Use the latest version of Formik
const raw = fs.readFileSync(
path.join(__dirname, './formik-master/website/package.json'),
'utf8'
);
const pkg = JSON.parse(raw);
pkg.dependencies.formik = 'latest';
fs.writeJSONSync(
path.join(__dirname, './formik-master/website/package.json'),
pkg,
null,
2
);
// Use the latest version of Formik
const rawGatsbyConfig = fs.readFileSync(
path.join(__dirname, './formik-master/website/gatsby-config.js'),
'utf8'
);
const URL = process.env.DEPLOY_PRIME_URL
? process.env.DEPLOY_PRIME_URL
: 'https://jaredpalmer.com';
// Alter Gatsby configuration so that final site knows it is being served on a
// path '/formik'
fs.writeFileSync(
path.join(__dirname, './formik-master/website/gatsby-config.js'),
rawGatsbyConfig.replace(
`module.exports = {\n siteMetadata: {\n`,
`module.exports = {\n
pathPrefix: '/formik',
siteMetadata: {
siteUrl: '${URL}',
`
)
);
if (shell.exec('yarn').code !== 0) {
shell.echo('Error: yarn install failure');
shell.exit(1);
}
if (shell.exec('yarn deploy').code !== 0) {
shell.echo('Error: yarn build failure');
shell.exit(1);
}
if (shell.exec('mv public ../../dist').code !== 0) {
shell.echo('Error: copy build');
shell.exit(1);
}
shell.cd('..');
shell.cd('..');
if (shell.exec('mv ./dist ./public/formik').code !== 0) {
shell.echo('Error: renaming formik directory');
shell.exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.