|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/*! |
| 4 | + * Script to create the built examples zip archive; |
| 5 | + * requires the `zip` command to be present! |
| 6 | + * Copyright 2020 The Bootstrap Authors |
| 7 | + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) |
| 8 | + */ |
| 9 | + |
| 10 | +'use strict' |
| 11 | + |
| 12 | +const path = require('path') |
| 13 | +const sh = require('shelljs') |
| 14 | + |
| 15 | +const { |
| 16 | + version, version_short: versionShort |
| 17 | +} = require('../package.json') |
| 18 | + |
| 19 | +const folderName = `bootstrap-${version}-examples` |
| 20 | + |
| 21 | +sh.config.fatal = true |
| 22 | + |
| 23 | +if (!sh.test('-d', '_gh_pages')) { |
| 24 | + throw new Error('The _gh_pages folder does not exist, did you forget building the docs?') |
| 25 | +} |
| 26 | + |
| 27 | +// switch to the root dir |
| 28 | +sh.cd(path.join(__dirname, '..')) |
| 29 | + |
| 30 | +// remove any previously created folder with the same name |
| 31 | +sh.rm('-rf', folderName) |
| 32 | +sh.mkdir('-p', folderName) |
| 33 | + |
| 34 | +// copy the examples and dist folders; for the examples we use `*` |
| 35 | +// so that its content are copied to the root dist dir |
| 36 | +sh.cp('-Rf', [ |
| 37 | + `_gh_pages/docs/${versionShort}/examples/*`, |
| 38 | + `_gh_pages/docs/${versionShort}/dist/` |
| 39 | +], folderName) |
| 40 | +sh.rm(`${folderName}/index.html`) |
| 41 | + |
| 42 | +// sed-fu |
| 43 | +sh.find(`${folderName}/**/*.html`).forEach((file) => { |
| 44 | + sh.sed('-i', new RegExp(`"/docs/${versionShort}/`, 'g'), '"../', file) |
| 45 | + sh.sed('-i', /(<link href="\.\.\/.*) integrity=".*>/g, '$1>', file) |
| 46 | + sh.sed('-i', /(<script src="\.\.\/.*) integrity=".*>/g, '$1></script>', file) |
| 47 | +}) |
| 48 | + |
| 49 | +// create the zip file |
| 50 | +sh.exec(`zip -r9 "${folderName}.zip" "${folderName}"`, { |
| 51 | + fatal: true |
| 52 | +}) |
| 53 | + |
| 54 | +// remove the folder we created |
| 55 | +sh.rm('-rf', folderName) |
0 commit comments