-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
6,542 additions
and
3,830 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,84 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict' | ||
|
||
/*! | ||
* Script to update version number references in the project. | ||
* Copyright 2017 The Bootstrap Authors | ||
* Copyright 2017 Twitter, Inc. | ||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) | ||
* Copyright 2017-2021 The Bootstrap Authors | ||
* Copyright 2017-2021 Twitter, Inc. | ||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) | ||
*/ | ||
|
||
/* global Set */ | ||
'use strict' | ||
|
||
const fs = require('fs') | ||
const fs = require('fs').promises | ||
const path = require('path') | ||
const sh = require('shelljs') | ||
sh.config.fatal = true | ||
const sed = sh.sed | ||
const globby = require('globby') | ||
|
||
const VERBOSE = process.argv.includes('--verbose') | ||
const DRY_RUN = process.argv.includes('--dry') || process.argv.includes('--dry-run') | ||
|
||
// These are the filetypes we only care about replacing the version | ||
const GLOB = [ | ||
'**/*.{css,html,js,json,md,scss,txt,yml}' | ||
] | ||
const GLOBBY_OPTIONS = { | ||
cwd: path.join(__dirname, '..'), | ||
gitignore: true | ||
} | ||
const EXCLUDED_FILES = [ | ||
'CHANGELOG.md' | ||
] | ||
|
||
// Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37 | ||
RegExp.quote = (string) => string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&') | ||
RegExp.quoteReplacement = (string) => string.replace(/[$]/g, '$$') | ||
function regExpQuote(string) { | ||
return string.replace(/[$()*+-.?[\\\]^{|}]/g, '\\$&') | ||
} | ||
|
||
function regExpQuoteReplacement(string) { | ||
return string.replace(/\$/g, '$$') | ||
} | ||
|
||
const DRY_RUN = false | ||
async function replaceRecursively(file, oldVersion, newVersion) { | ||
const originalString = await fs.readFile(file, 'utf8') | ||
const newString = originalString.replace( | ||
new RegExp(regExpQuote(oldVersion), 'g'), regExpQuoteReplacement(newVersion) | ||
) | ||
|
||
function walkAsync(directory, excludedDirectories, fileCallback, errback) { | ||
if (excludedDirectories.has(path.parse(directory).base)) { | ||
// No need to move any further if the strings are identical | ||
if (originalString === newString) { | ||
return | ||
} | ||
fs.readdir(directory, (err, names) => { | ||
if (err) { | ||
errback(err) | ||
return | ||
} | ||
names.forEach((name) => { | ||
const filepath = path.join(directory, name) | ||
fs.lstat(filepath, (err, stats) => { | ||
if (err) { | ||
process.nextTick(errback, err) | ||
return | ||
} | ||
if (stats.isSymbolicLink()) { | ||
return | ||
} | ||
else if (stats.isDirectory()) { | ||
process.nextTick(walkAsync, filepath, excludedDirectories, fileCallback, errback) | ||
} | ||
else if (stats.isFile()) { | ||
process.nextTick(fileCallback, filepath) | ||
} | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
function replaceRecursively(directory, excludedDirectories, allowedExtensions, original, replacement) { | ||
original = new RegExp(RegExp.quote(original), 'g') | ||
replacement = RegExp.quoteReplacement(replacement) | ||
const updateFile = !DRY_RUN ? (filepath) => { | ||
if (allowedExtensions.has(path.parse(filepath).ext)) { | ||
sed('-i', original, replacement, filepath) | ||
} | ||
} : (filepath) => { | ||
if (allowedExtensions.has(path.parse(filepath).ext)) { | ||
console.log(`FILE: ${filepath}`) | ||
} | ||
else { | ||
console.log(`EXCLUDED:${filepath}`) | ||
} | ||
if (VERBOSE) { | ||
console.log(`FILE: ${file}`) | ||
} | ||
walkAsync(directory, excludedDirectories, updateFile, (err) => { | ||
console.error('ERROR while traversing directory!:') | ||
console.error(err) | ||
process.exit(1) | ||
}) | ||
|
||
if (DRY_RUN) { | ||
return | ||
} | ||
|
||
await fs.writeFile(file, newString, 'utf8') | ||
} | ||
|
||
function main(args) { | ||
if (args.length !== 2) { | ||
console.error('USAGE: change-version old_version new_version') | ||
async function main(args) { | ||
const [oldVersion, newVersion] = args | ||
|
||
if (!oldVersion || !newVersion) { | ||
console.error('USAGE: change-version old_version new_version [--verbose] [--dry[-run]]') | ||
console.error('Got arguments:', args) | ||
process.exit(1) | ||
} | ||
const oldVersion = args[0] | ||
const newVersion = args[1] | ||
const EXCLUDED_DIRS = new Set([ | ||
'.git', | ||
'node_modules', | ||
'vendor' | ||
]) | ||
const INCLUDED_EXTENSIONS = new Set([ | ||
// This extension whitelist is how we avoid modifying binary files | ||
'', | ||
'.css', | ||
'.html', | ||
'.js', | ||
'.json', | ||
'.md', | ||
'.scss', | ||
'.txt', | ||
'.yml' | ||
]) | ||
replaceRecursively('.', EXCLUDED_DIRS, INCLUDED_EXTENSIONS, oldVersion, newVersion) | ||
|
||
// Strip any leading `v` from arguments because otherwise we will end up with duplicate `v`s | ||
[oldVersion, newVersion].map(arg => arg.startsWith('v') ? arg.slice(1) : arg) | ||
|
||
try { | ||
const files = await globby(GLOB, GLOBBY_OPTIONS, EXCLUDED_FILES) | ||
|
||
await Promise.all(files.map(file => replaceRecursively(file, oldVersion, newVersion))) | ||
} catch (error) { | ||
console.error(error) | ||
process.exit(1) | ||
} | ||
} | ||
|
||
main(process.argv.slice(2)) |
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
extends ../../_layout/default.pug | ||
|
||
block view | ||
.card | ||
.card-header | ||
strong Contents | ||
span.small.ms-1 What’s included | ||
.card-body | ||
p Within the download you’ll find the following directories and files, logically grouping common assets and providing both compiled and minified variations. You’ll see something like this: | ||
pre.hljs | ||
code | ||
| free-bootstrap-admin-template/ | ||
| ├── build/ | ||
| ├── src/ | ||
| │ ├── assets/ | ||
| │ │ ├── brand/ | ||
| │ │ ├── favicon/ | ||
| │ │ ├── icons/ | ||
| │ │ ├── img/ | ||
| │ ├── js/ | ||
| │ ├── pug/ | ||
| │ │ ├── _layout/ | ||
| │ │ ├── _partial/ | ||
| │ │ ├── base/ | ||
| │ │ ├── buttons/ | ||
| │ │ ├── icons/ | ||
| │ │ ├── notifications/ | ||
| │ │ ├── ... | ||
| │ │ ├── index.pug | ||
| │ │ └── ... | ||
| │ ├── scss/ | ||
| │ ├── vendors/ | ||
| │ └── views/ | ||
| │ ├── base/ | ||
| │ ├── buttons/ | ||
| │ ├── css/ | ||
| │ ├── icons/ | ||
| │ ├── notifications/ | ||
| │ ├── ... | ||
| │ ├── index.html | ||
| │ └── ... | ||
| └── package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
extends ../../_layout/default.pug | ||
|
||
block view | ||
.card | ||
.card-header | ||
strong Installation | ||
.card-body | ||
h2 Installation | ||
h3 Clone repo | ||
pre.hljs.language-bash | ||
code | ||
| # clone the repo | ||
| $ git clone https://github.com/coreui/coreui-free-bootstrap-admin-template.git my-project | ||
| | ||
| # go into app's directory | ||
| $ cd my-project | ||
| | ||
| # install app's dependencies | ||
| $ npm install | ||
|
||
h2 Usage | ||
pre.hljs.language-bash | ||
code | ||
| # serve with hot reload at localhost:3000. | ||
| $ npm run serve | ||
| | ||
| # build for production with minification | ||
| $ npm run build | ||
|
Oops, something went wrong.