talos

Форк
0
88 строк · 2.3 Кб
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-2021 The Bootstrap Authors
7
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
8
 */
9

10
'use strict'
11

12
const path = require('path')
13
const sh = require('shelljs')
14

15
const pkg = require('../package.json')
16

17
const versionShort = pkg.config.version_short
18
const distFolder = `bootstrap-${pkg.version}-examples`
19
const rootDocsDir = '_site'
20
const docsDir = `${rootDocsDir}/docs/${versionShort}/`
21

22
// these are the files we need in the examples
23
const cssFiles = [
24
  'bootstrap.min.css',
25
  'bootstrap.min.css.map'
26
]
27
const jsFiles = [
28
  'bootstrap.bundle.min.js',
29
  'bootstrap.bundle.min.js.map'
30
]
31
const imgFiles = [
32
  'bootstrap-outline.svg',
33
  'bootstrap-solid.svg'
34
]
35

36
sh.config.fatal = true
37

38
if (!sh.test('-d', rootDocsDir)) {
39
  throw new Error(`The "${rootDocsDir}" folder does not exist, did you forget building the docs?`)
40
}
41

42
// switch to the root dir
43
sh.cd(path.join(__dirname, '..'))
44

45
// remove any previously created folder/zip with the same name
46
sh.rm('-rf', [distFolder, `${distFolder}.zip`])
47

48
// create any folders so that `cp` works
49
sh.mkdir('-p', [
50
  distFolder,
51
  `${distFolder}/assets/brand/`,
52
  `${distFolder}/assets/dist/css/`,
53
  `${distFolder}/assets/dist/js/`
54
])
55

56
sh.cp('-Rf', `${docsDir}/examples/*`, distFolder)
57

58
cssFiles.forEach(file => {
59
  sh.cp('-f', `${docsDir}/dist/css/${file}`, `${distFolder}/assets/dist/css/`)
60
})
61

62
jsFiles.forEach(file => {
63
  sh.cp('-f', `${docsDir}/dist/js/${file}`, `${distFolder}/assets/dist/js/`)
64
})
65

66
imgFiles.forEach(file => {
67
  sh.cp('-f', `${docsDir}/assets/brand/${file}`, `${distFolder}/assets/brand/`)
68
})
69

70
sh.rm(`${distFolder}/index.html`)
71

72
// get all examples' HTML files
73
sh.find(`${distFolder}/**/*.html`).forEach(file => {
74
  const fileContents = sh.cat(file)
75
    .toString()
76
    .replace(new RegExp(`"/docs/${versionShort}/`, 'g'), '"../')
77
    .replace(/"..\/dist\//g, '"../assets/dist/')
78
    .replace(/(<link href="\.\.\/.*) integrity=".*>/g, '$1>')
79
    .replace(/(<script src="\.\.\/.*) integrity=".*>/g, '$1></script>')
80
    .replace(/( +)<!-- favicons(.|\n)+<style>/i, '    <style>')
81
  new sh.ShellString(fileContents).to(file)
82
})
83

84
// create the zip file
85
sh.exec(`zip -r9 "${distFolder}.zip" "${distFolder}"`)
86

87
// remove the folder we created
88
sh.rm('-rf', distFolder)
89

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.