Skip to content

Commit

Permalink
static files copying as an option
Browse files Browse the repository at this point in the history
  • Loading branch information
juliancwirko committed Aug 22, 2021
1 parent 0ef1f72 commit 0e82ab5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "harold-scripts",
"version": "0.7.0",
"version": "0.8.0",
"description": "Harold JS Scripts for Create Harold App",
"author": "Julian Ćwirko (julian.io)",
"engines": {
Expand Down
1 change: 1 addition & 0 deletions scripts/build/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
: 'build',
stylesDirName: 'styles',
jsonDataDirName: 'jsonData',
staticsDirName: 'statics',
hostDirName:
loaded && loaded.config && loaded.config.hostDirName
? loaded.config.hostDirName
Expand Down
11 changes: 11 additions & 0 deletions scripts/build/copy-statics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fse = require('fs-extra');
const config = require('./constants');

module.exports = () => {
if (fse.pathExistsSync(`${config.srcDirName}/${config.staticsDirName}`)) {
fse.copySync(
`${config.srcDirName}/${config.staticsDirName}`,
`${config.publicDirName}`
);
}
};
4 changes: 4 additions & 0 deletions scripts/build/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const prepareDirectories = require('./prepare-dirs');
const copyAssets = require('./copy-assets');
const copyJSONData = require('./copy-json-data');
const copyStatics = require('./copy-statics');
const build = require('./build');

// Prepare directories
Expand All @@ -14,3 +15,6 @@ build();

// Copy JSON data
copyJSONData();

// Copy statics
copyStatics();
11 changes: 11 additions & 0 deletions scripts/start/listener-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const build = require('../build/build');
const copyAssets = require('../build/copy-assets');
const copyJSONData = require('../build/copy-json-data');
const config = require('../build/constants');
const copyStatics = require('../build/copy-statics');

// Operations for file changes listener
module.exports = (event, path) => {
Expand All @@ -14,6 +15,16 @@ module.exports = (event, path) => {
if (path.includes(`${config.srcDirName}/${config.postsDirName}`)) {
copyJSONData();
}
if (path.includes(`${config.srcDirName}/${config.staticsDirName}`)) {
copyStatics();
if (event === 'unlink') {
const publicPath = path.replace(
`${config.srcDirName}/${config.staticsDirName}`,
config.publicDirName
);
fse.removeSync(publicPath);
}
}
if (
path.includes(`${config.srcDirName}/${config.pagesDirName}`) &&
event === 'unlink'
Expand Down

0 comments on commit 0e82ab5

Please sign in to comment.