build: build for netify

This commit is contained in:
Anh Hồng 2022-02-23 08:50:29 +07:00
parent e987b9b6ab
commit c2881e1956
2 changed files with 34 additions and 4 deletions

View file

@ -1,5 +1,9 @@
var { execSync } = require('child_process');
var { writeFileSync, readdirSync, readFileSync } = require('fs');
var {
writeFileSync, readdirSync, readFileSync,
existsSync, statSync, mkdirSync, copyFileSync,
} = require('fs');
var path = require('path');
var glob = require('glob');
var _ = require('underscore');
@ -48,6 +52,22 @@ const lintStrings = (done) => {
var destDir = './build/';
var copyRecursiveSync = (src, dest) => {
var exists = existsSync(src);
var stats = exists && statSync(src);
var isDirectory = exists && stats.isDirectory();
if (isDirectory) {
mkdirSync(dest);
readdirSync(src).forEach((childItemName) => {
copyRecursiveSync(
path.join(src, childItemName),
path.join(dest, childItemName));
});
} else {
copyFileSync(src, dest);
}
};
var buildIndex = function(done) {
log('Building index...');
@ -72,8 +92,11 @@ var buildIndex = function(done) {
}
log('Found hashed style file: ' + styleFile);
var buildDir = process.env.CI ? '.' : 'build';
// output these filenames to our index template
var outputIndex = indexTemplate({
buildDir,
jsFile,
styleFile,
});
@ -86,7 +109,14 @@ var buildIndex = function(done) {
removeComments: true,
});
}
if (process.env.CI) {
writeFileSync('build/index.html', outputIndex);
copyRecursiveSync('assets', 'build/assets');
copyRecursiveSync('lib', 'build/lib');
} else {
writeFileSync('index.html', outputIndex);
}
done();
};

View file

@ -14,7 +14,7 @@
<meta property="og:description" content="An interactive Git visualization tool to educate and challenge!"/>
<meta http-equiv="content-language" content="en">
<link rel="stylesheet" href="build/{{styleFile}}" type="text/css" charset="utf-8">
<link rel="stylesheet" href="{{buildDir}}/{{styleFile}}" type="text/css" charset="utf-8">
<link rel="icon" href="assets/favicon.ico" type="image/x-icon">
@ -357,7 +357,7 @@
For a much easier time perusing the source, see the individual files at:
https://github.com/pcottle/learnGitBranching
-->
<script defer src="build/{{jsFile}}"></script>
<script defer src="{{buildDir}}/{{jsFile}}"></script>
</head>
<body>
<!-- lol noscript. I did not write 9k+ lines of JS just for you to bounce off my website -->