Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates may2024 #31

Merged
merged 6 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/static.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('bin/static CLI', () => {
const output = executeCommand('./bin/static new testProject');
const expectedOutput = [
"New setup initialized",
"Downloading static starter template",
"Downloading starter template",
"Finished downloading template",
"Extracting template zip file",
"Finished unzipping",
Expand All @@ -27,7 +27,7 @@ describe('bin/static CLI', () => {
});

it('should build project', () => {
const output = executeCommand('cd testProject/static-starter-main && ../../bin/static build relative');
const output = executeCommand('cd testProject && ../bin/static build relative');
console.log('Output:', output);
console.log('Current Directory:', process.cwd());
console.log('Directory Contents:', executeCommand('ls -al'));
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

27 changes: 17 additions & 10 deletions src/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,32 @@ const path = require('path');
const fsExtra = require('fs-extra');

module.exports = {
buildJSFile(build = false){
buildJSFile(build = false, buildDir = './_site'){
let esBuildFlag = "--watch";
if(build){
esBuildFlag = "--minify";
}
exec("npx esbuild ./assets/js/main.js --bundle --outfile=./_site/assets/js/main.js " + esBuildFlag, (err, stdout, stderr) => {
exec("npx esbuild ./assets/js/main.js --bundle --outfile=" + buildDir + "/assets/js/main.js " + esBuildFlag, (err, stdout, stderr) => {
if (err) {
console.error("Error compling main.js:");
console.error(err);
}
console.log(stdout);
});
},
moveImages(){
moveImages(buildDir = '_site'){

let imagesFolder = 'assets/images'
try {
if (fs.existsSync(imagesFolder)) {
this.createFolderIfNotExists("_site/assets/");
this.createFolderIfNotExists("_site/assets/images");
this.createFolderIfNotExists(buildDir + "/assets/");
this.createFolderIfNotExists(buildDir + "/assets/images");

let src=path.join(currentDirectory, '/assets/images');
let dest=path.join(currentDirectory, '/_site/assets/images');
let dest=path.join(currentDirectory, '_site/assets/images');
if(buildDir != '_site'){
dest = buildDir + '/assets/images';
}
this.copyDirSync(src, dest);
}
} catch (err) {
Expand All @@ -46,8 +49,8 @@ module.exports = {
fs.mkdirSync(folderPath, { recursive: true });
}
},
buildTailwindCSS(){
exec("npx tailwindcss -i ./assets/css/main.css -o ./_site/assets/css/main.css --minify", (err, stdout, stderr) => {
buildTailwindCSS(buildDir = './_site'){
exec("npx tailwindcss -i ./assets/css/main.css -o " + buildDir + "/assets/css/main.css --minify", (err, stdout, stderr) => {
if (err) {
console.error("Error compling tailwindcss:");
console.error(err);
Expand All @@ -56,9 +59,13 @@ module.exports = {
});

},
movePublicFoderContents(){
movePublicFolderContents(buildDir = '_site'){
const publicFolder = path.join(currentDirectory, 'public');
const siteFolder = path.join(currentDirectory, '_site');
let siteFolder = path.join(currentDirectory, '_site');

if(buildDir != '_site'){
siteFolder = buildDir;
}

try {
if (fs.existsSync(publicFolder)) {
Expand Down
30 changes: 25 additions & 5 deletions src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,39 @@ const url = 'relative';

module.exports = {
start(url='relative'){

let staticJSON = {};

const staticJsonPath = path.join(currentDirectory, 'static.json');
if (fs.existsSync(staticJsonPath)) {
const staticJsonContent = fs.readFileSync(staticJsonPath, 'utf8');
staticJSON = JSON.parse(staticJsonContent);
}

if (staticJSON.hasOwnProperty('build')) {
if(typeof(staticJSON.build.url) != 'undefined'){
url = staticJSON.build.url;
}
}

const pagesDir = path.join(currentDirectory, './pages');
const contentPagesDir = path.join(currentDirectory, './content');
const buildDir = path.join(currentDirectory, './_site');
let buildDir = path.join(currentDirectory, './_site');

if (staticJSON.hasOwnProperty('build')) {
if(typeof(staticJSON.build.directory) != 'undefined'){
buildDir = staticJSON.build.directory;
}
}

if (fs.existsSync(buildDir)) {
removeDirectory(buildDir);
}

assets.buildJSFile(true);
assets.buildTailwindCSS();
assets.moveImages();
assets.movePublicFoderContents();
assets.buildJSFile(true, buildDir);
assets.buildTailwindCSS(buildDir);
assets.moveImages(buildDir);
assets.movePublicFolderContents(buildDir);

fs.mkdirSync(buildDir, { recursive: true });
buildPages(pagesDir, buildDir, url);
Expand Down
24 changes: 15 additions & 9 deletions src/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ module.exports = {

// get available port for the Live Reload Server
this.getAvailablePort(liveReloadDefaultPort).then((liveReloadAvailablePort) => {

let staticJSON = {};

const staticJsonPath = path.join(currentDirectory, 'static.json');
if (fs.existsSync(staticJsonPath)) {
const staticJsonContent = fs.readFileSync(staticJsonPath, 'utf8');
staticJSON = JSON.parse(staticJsonContent);
}

if (staticJSON.hasOwnProperty('dev')) {
console.log(staticJSON.dev.url);
if(typeof(staticJSON.dev.url) != 'undefined'){
url = staticJSON.dev.url;
}
}

const liveReloadOptions = {
port: liveReloadAvailablePort,
Expand All @@ -47,15 +62,6 @@ module.exports = {
}, 100);
});

// TODO: Allow user to specify setting headers in the dev server via a config file
let staticJSON = {};

const staticJsonPath = path.join(currentDirectory, 'static.json');
if (fs.existsSync(staticJsonPath)) {
const staticJsonContent = fs.readFileSync(staticJsonPath, 'utf8');
staticJSON = JSON.parse(staticJsonContent);
}

app.use(function(req, res, next) {
if (staticJSON.hasOwnProperty('headers')) {
for (const header in staticJSON.headers) {
Expand Down
3 changes: 3 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ module.exports = {

page = page.replace('</head>', attrTags + '\n</head>');
page = page.replace('{content}', contentHTML);

// this will add the ability to include src partials in your markdown
page = this.parseIncludeContent(page);

return page;

Expand Down
Loading