Skip to content

Commit

Permalink
added flatten directory option
Browse files Browse the repository at this point in the history
  • Loading branch information
photodow committed Apr 30, 2021
1 parent a6e6473 commit 16e8198
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/repo-to-wiki.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: photodow/wiki-helpers@v1.7
- uses: photodow/wiki-helpers@v1.8
with:
rootPath: "./samples"
- name: Upload Documentation to Wiki
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ You can find this script in the [GitHub Action Marketplace](https://github.com/m

```yml
- name: Wiki Helpers
uses: photodow/wiki-helpers@v1.7
uses: photodow/wiki-helpers@v1.8
```
<details>
Expand All @@ -103,7 +103,7 @@ jobs:
- uses: actions/checkout@v2
with:
repository: ${{github.repository}}.wiki
- uses: photodow/wiki-helpers@v1.7
- uses: photodow/wiki-helpers@v1.8
with:
rootPath: ./
buildPath: ./
Expand Down Expand Up @@ -131,9 +131,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: photodow/wiki-helpers@v1.7
- uses: photodow/wiki-helpers@v1.8
with:
rootPath: "./samples"
flattenDir: true
- name: Upload Documentation to Wiki
uses: SwiftDocOrg/github-wiki-publish-action@v1
with:
Expand All @@ -159,6 +160,7 @@ npm run build [...optionName=optionValue]
| `templatePath` | `String` | Path to your custom template for everything. |
| `depsTitleHook` | `String` | Title of your dependencies list. Defaults to `Dependencies`. Case sensitive. |
| `buildPath` | `String` | `./build (default)` Indicate a directory you would like the updated files to build into. |
| `flattenDir` | `Boolean` | `false (default)` By default it maintains folder structure. `true` flattens all the files into a flat structure within the `buildPath`. |

## Helpers

Expand Down
3 changes: 2 additions & 1 deletion action.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ try {
resetOnly: core.getInput('resetOnly'),
templatePath: core.getInput('templatePath'),
depsTitleHook: core.getInput('depsTitleHook'),
buildPath: core.getInput('buildPath')
buildPath: core.getInput('buildPath'),
flattenDir: core.getInput('flattenDir')
});
} catch (error) {
core.setFailed(error.message);
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ inputs:
description: 'Title of your dependencies list. Defaults to Dependencies. Case sensitive.'
buildPath: # id of input
description: './build (default) Indicate a directory you would like the updated files to build into.'
flattenDir: # id of input
description: 'false (default) By default it maintains folder structure. true flattens all the files into a flat structure within the buildPath.'
branding:
icon: 'book-open'
color: 'gray-dark'
Expand Down
24 changes: 17 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const fs = __nccwpck_require__(747);
const Path = __nccwpck_require__(622);
let globalOptions, builders, miners;

// TODO: build action and publish
// TODO: Publish action
// TODO: global option booleans not exactly working
// TODO: Publish npm
// TODO: ignore list
// TODO: custom miners, builders ... miners=./lib/mine.js builders=./lib/build.js done=./lib/done.js
Expand Down Expand Up @@ -48,7 +47,8 @@ function setGlobalOptions (config = {}) {
resetOnly: arguments.resetOnly || false,
templatePath: arguments.templatePath || undefined,
depsTitleHook: arguments.depsTitleHook || 'Dependencies',
buildPath: arguments.buildPath || './build'
buildPath: arguments.buildPath || './build',
flattenDir: arguments.flattenDir || false
};
}

Expand Down Expand Up @@ -414,17 +414,26 @@ function writeEachFileOnce (filesObj) {
const updated = filesObj[key].content.updated;
const name = filesObj[key].name;
const path = Path.join(globalOptions.buildPath, filesObj[key].path.replace(globalOptions.rootPath.replace('./', ''), ''));
let writeTo = Path.join(path, filesObj[key].name);

if (original !== updated || globalOptions.buildPath) {

if (globalOptions.buildPath) {
fs.mkdirSync(path, { recursive: true });
fs.mkdirSync(globalOptions.buildPath, { recursive: true });

if (!globalOptions.flattenDir) {
fs.mkdirSync(path, { recursive: true });
}
}
console.log(typeof globalOptions.flattenDir, globalOptions.flattenDir);
if (globalOptions.flattenDir) {
writeTo = Path.join(globalOptions.buildPath, filesObj[key].name);
}

waitForIt.push(new Promise((resolve, reject) => {
fs.writeFile(Path.join(path, filesObj[key].name), updated, (err) => {
fs.writeFile(writeTo, updated, (err) => {
if (err) console.log(err);
console.log(`Successfully ${!globalOptions.buildPath ? 'updated' : 'created'} ${Path.join(path, filesObj[key].name)}.`);
console.log(`Successfully ${!globalOptions.buildPath ? 'updated' : 'created'} ${writeTo}.`);
count += 1;
resolve(filesObj);
});
Expand Down Expand Up @@ -6659,7 +6668,8 @@ try {
resetOnly: core.getInput('resetOnly'),
templatePath: core.getInput('templatePath'),
depsTitleHook: core.getInput('depsTitleHook'),
buildPath: core.getInput('buildPath')
buildPath: core.getInput('buildPath'),
flattenDir: core.getInput('flattenDir')
});
} catch (error) {
core.setFailed(error.message);
Expand Down
21 changes: 15 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const fs = require("fs");
const Path = require("path");
let globalOptions, builders, miners;

// TODO: build action and publish
// TODO: Publish action
// TODO: global option booleans not exactly working
// TODO: Publish npm
// TODO: ignore list
// TODO: custom miners, builders ... miners=./lib/mine.js builders=./lib/build.js done=./lib/done.js
Expand Down Expand Up @@ -42,7 +41,8 @@ function setGlobalOptions (config = {}) {
resetOnly: arguments.resetOnly || false,
templatePath: arguments.templatePath || undefined,
depsTitleHook: arguments.depsTitleHook || 'Dependencies',
buildPath: arguments.buildPath || './build'
buildPath: arguments.buildPath || './build',
flattenDir: arguments.flattenDir || false
};
}

Expand Down Expand Up @@ -408,17 +408,26 @@ function writeEachFileOnce (filesObj) {
const updated = filesObj[key].content.updated;
const name = filesObj[key].name;
const path = Path.join(globalOptions.buildPath, filesObj[key].path.replace(globalOptions.rootPath.replace('./', ''), ''));
let writeTo = Path.join(path, filesObj[key].name);

if (original !== updated || globalOptions.buildPath) {

if (globalOptions.buildPath) {
fs.mkdirSync(path, { recursive: true });
fs.mkdirSync(globalOptions.buildPath, { recursive: true });

if (!globalOptions.flattenDir) {
fs.mkdirSync(path, { recursive: true });
}
}
console.log(typeof globalOptions.flattenDir, globalOptions.flattenDir);
if (globalOptions.flattenDir) {
writeTo = Path.join(globalOptions.buildPath, filesObj[key].name);
}

waitForIt.push(new Promise((resolve, reject) => {
fs.writeFile(Path.join(path, filesObj[key].name), updated, (err) => {
fs.writeFile(writeTo, updated, (err) => {
if (err) console.log(err);
console.log(`Successfully ${!globalOptions.buildPath ? 'updated' : 'created'} ${Path.join(path, filesObj[key].name)}.`);
console.log(`Successfully ${!globalOptions.buildPath ? 'updated' : 'created'} ${writeTo}.`);
count += 1;
resolve(filesObj);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backlinks-test",
"version": "1.0.0",
"version": "v1.8",
"description": "This action offers a number of helpers to help automate some of the laborious tasks across many files within a wiki. For example generating table of contents or backlinking references.",
"main": "./lib/index.js",
"scripts": {
Expand Down

0 comments on commit 16e8198

Please sign in to comment.