Skip to content

Commit

Permalink
v bump and tiny refactor of ignore files flow
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhdaware committed May 18, 2020
1 parent 2c6dcf1 commit 3ffbf39
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 101 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.2.11
- Building all `.abell` files inside `theme` folder. (Thanks to [@akash-joshi](https://github.com/akash-joshi) for PR [#12](https://github.com/abelljs/abell/pull/12))
- **BREAKING CHANGE**
Dropping option of `templateExtension` from `abell.config.js`
- Tiny Refactor og ignoring files flow.


## 0.2.10
- **MAJOR UPDATE: Website Performance Improvements**
All links from content's template will be prefetched on the index page.
Expand Down
2 changes: 1 addition & 1 deletion demo/theme/index.abell
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<body>
{{
const a = 10;
const b = 5;
const b = 1;
}}
<header>Addition of numbers: {{ a + b }}</header>
<h1>{{ globalMeta.siteName }}</h1>
Expand Down
29 changes: 0 additions & 29 deletions demo/theme/test.abell

This file was deleted.

29 changes: 0 additions & 29 deletions demo/theme/test/test.abell

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "abell",
"version": "0.2.10",
"version": "0.2.11",
"description": "Abell is a static blog generator that generates blog in Vanilla JavaScript",
"funding": {
"type": "patreon",
Expand Down
36 changes: 17 additions & 19 deletions src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,50 +37,48 @@ function build(programInfo) {

const abellFiles = getAbellFiles(
programInfo.abellConfigs.sourcePath,
programInfo.templateExtension
'.abell'
);

// Refresh dist
rmdirRecursiveSync(programInfo.abellConfigs.destinationPath);
fs.mkdirSync(programInfo.abellConfigs.destinationPath);

const ignoreCopying = [
path.join(programInfo.abellConfigs.sourcePath, '[$slug]'),
path.join(programInfo.abellConfigs.sourcePath, 'components'),
...programInfo.abellConfigs.ignoreInBuild
.map(relativePath =>
.map(relativePath =>
path.join(programInfo.abellConfigs.sourcePath, relativePath)
)
),
...abellFiles.map(withoutExtension => withoutExtension + '.abell')
];

if (ignoreCopying.length > 2 && programInfo.logs === 'complete') {
console.log(`Not included in Build: ${ignoreCopying.slice(2).join(',')}`);
}
// Copy everything from src to dist except the ones mentioned in ignoreCopying.
copyFolderSync(
programInfo.abellConfigs.sourcePath,
programInfo.abellConfigs.destinationPath,
ignoreCopying
);


// Delete all .abell files from dist folder
for (const file of abellFiles) {
fs.unlinkSync(
path.join(programInfo.abellConfigs.destinationPath, `${file}.abell`)
);
}

// GENERATE CONTENT HTML FILES
// GENERATE CONTENT's HTML FILES
for (const contentSlug of programInfo.contentDirectories) {
generateContentFile(contentSlug, programInfo);
if (programInfo.logs == 'complete') console.log(`...Built ${contentSlug}`);
}

// GENERATE OTHER HTML FILES FROM ABELL
for (const file of abellFiles) {
generateHTMLFile(file, programInfo);
if (programInfo.logs == 'complete') console.log(`...Built ${file}.html`);
const relativePath = path.relative(programInfo.abellConfigs.sourcePath, file);
if (relativePath.includes('[$slug]')) {
continue;
}

// e.g generateHTMLFile('index', programInfo) will build theme/index.abell to dist/index.html
generateHTMLFile(relativePath, programInfo);

if (programInfo.logs == 'complete') {
console.log(`...Built ${relativePath}.html`);
}
}

if (programInfo.logs == 'minimum') {
Expand Down Expand Up @@ -156,7 +154,7 @@ function serve(programInfo) {
.split('/')[0];

if (
filePath.endsWith('index' + programInfo.templateExtension) &&
filePath.endsWith('index.abell') &&
directoryName === '[$slug]'
) {
// Content template changed
Expand Down
7 changes: 3 additions & 4 deletions src/content-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function getBaseProgramInfo() {
const contentTemplatePath = path.join(
abellConfigs.sourcePath,
'[$slug]',
'index' + (abellConfigs.templateExtension || '.abell')
'index.abell'
);
const contentTemplate = fs.readFileSync(contentTemplatePath, 'utf-8');

Expand All @@ -111,8 +111,7 @@ function getBaseProgramInfo() {
$contentObj,
globalMeta: abellConfigs.globalMeta
},
logs: 'minimum',
templateExtension: abellConfigs.templateExtension || '.abell'
logs: 'minimum'
};

return programInfo;
Expand Down Expand Up @@ -169,7 +168,7 @@ function importAndRender(mdPath, contentPath, variables) {
*/
function generateHTMLFile(filepath, programInfo) {
let pageTemplate = fs.readFileSync(
path.join(programInfo.abellConfigs.sourcePath, filepath + programInfo.templateExtension),
path.join(programInfo.abellConfigs.sourcePath, filepath + '.abell'),
'utf-8'
);

Expand Down
33 changes: 16 additions & 17 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,31 @@ const rmdirRecursiveSync = function(pathToRemove) {
}
};

const recFindByExt = (base, ext, inputFiles, inputResult) => {
const recursiveFind = (base, ext, inputFiles, inputResult) => {
const files = inputFiles || fs.readdirSync(base);
let result = inputResult || [];

for (const file of files) {
const newbase = path.join(base, file);
if (fs.statSync(newbase).isDirectory()) {
result = recFindByExt(newbase, ext, fs.readdirSync(newbase), result);
result = recursiveFind(newbase, ext, fs.readdirSync(newbase), result);
} else {
if (file.substr(-1 * (ext.length)) == ext) {
result.push(newbase);
}
}
};
}

return result;
};

// Returns all .abell files in src folder except for [$slug]
const getAbellFiles = (sourcePath, extension) => {
const absolutePaths = recFindByExt(sourcePath, extension);
const relativePaths = absolutePaths
.map((path) => {
const pathWithoutExtension = path.split(extension)[0];
const relativePath = pathWithoutExtension.split(`${sourcePath}/`)[1];
return relativePath;
})
.filter((path) => {
return path.split('[$slug]').length === 1;
});
return relativePaths;
const absolutePaths = recursiveFind(sourcePath, extension);
return absolutePaths
.map(absolutePath =>
absolutePath.slice(0, absolutePath.lastIndexOf('.'))
);
};

/**
Expand Down Expand Up @@ -130,10 +125,14 @@ function copyFolderSync(from, to, ignore = []) {
};
createPathIfAbsent(to);
fs.readdirSync(from).forEach((element) => {
if (fs.lstatSync(path.join(from, element)).isFile()) {
fs.copyFileSync(path.join(from, element), path.join(to, element));
const fromElement = path.join(from, element);
const toElement = path.join(to, element);
if (fs.lstatSync(fromElement).isFile()) {
if (!ignore.includes(path.join(from, element))) {
fs.copyFileSync(fromElement, toElement);
}
} else {
copyFolderSync(path.join(from, element), path.join(to, element), ignore);
copyFolderSync(fromElement, toElement, ignore);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion tests/content-generator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('getBaseProgramInfo()', () => {
.to.be.an('object')
.to.have.keys([
'abellConfigs', 'contentTemplate', 'vars', 'contentTemplatePath',
'contentDirectories', 'logs', 'templateExtension'
'contentDirectories', 'logs'
]);
});

Expand Down

0 comments on commit 3ffbf39

Please sign in to comment.