Skip to content

Commit

Permalink
Released fix for pilet generation
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Oct 21, 2021
1 parent 0980f1a commit a1e2c79
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 9 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# `piral-docs-tools` Changelog

## 0.11.3 (October 22, 2021)
## 0.11.4 (October 22, 2021)

- Improved multiple-pass compiler
- Added `publicPath` to config
- Added `unregister...` APIs

## 0.11.3 (October 21, 2021)

- Fixed issue with doclet generator
- Added template annotation
- Improved standard scaffold template

## 0.11.2 (October 22, 2021)
## 0.11.2 (October 21, 2021)

- Improved dependencies of generated file

Expand Down
8 changes: 7 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const { apps } = require('piral-cli');
const { packageEmulator, updateExistingJson, readText, updateExistingFile } = require('piral-cli/lib/common');
const { loadPlugins } = require('piral-cli/lib/plugin');
const { relative } = require('path');
const { outputPath, package } = require('../src/tools/meta');
const { outputPath, package, sitemap, publicUrl } = require('../src/tools/meta');
const { makeContent } = require('../src/tools/content');
const { name, version } = require('../package.json');

const baseDir = process.cwd();
Expand All @@ -19,13 +20,16 @@ const emulatorApp = `${emulator}/app`;
const target = `${outputPath}/index.html`;
const bundlerName = 'parcel';

makeContent(sitemap);

switch (process.argv.pop()) {
case 'watch':
return apps
.debugPiral(baseDir, {
entry,
target,
bundlerName,
publicUrl,
})
.then(
() => process.exit(0),
Expand All @@ -38,6 +42,7 @@ switch (process.argv.pop()) {
target,
bundlerName,
type: 'emulator-sources',
publicUrl,
})
.then(() =>
updateExistingJson(emulator, 'package.json', {
Expand Down Expand Up @@ -70,6 +75,7 @@ switch (process.argv.pop()) {
target,
bundlerName,
type: 'release',
publicUrl,
})
.then(
() => process.exit(0),
Expand Down
17 changes: 15 additions & 2 deletions src/scripts/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PiralPlugin } from 'piral-core';
import { includeSearchProvider } from './searchProviders';
import { appendSection } from './sitemap';
import { excludeSearchProvider, includeSearchProvider } from './searchProviders';
import { appendSection, removeSection } from './sitemap';
import { PiletDocletApi } from './types';

export function createDocletPlugin(): PiralPlugin<PiletDocletApi> {
Expand All @@ -15,8 +15,21 @@ export function createDocletPlugin(): PiralPlugin<PiletDocletApi> {
},
}));
},
unregisterDocumentation(section, category) {
const routes = removeSection(section, category);
context.dispatch((state) => ({
...state,
routes: Object.keys(routes).reduce((oldRoutes, path) => {
delete oldRoutes[path];
return oldRoutes;
}, state.routes),
}));
},
registerSearchProvider(cb) {
includeSearchProvider(cb);
},
unregisterSearchProvider(cb) {
excludeSearchProvider(cb);
},
});
}
8 changes: 8 additions & 0 deletions src/scripts/searchProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ export function includeSearchProvider(cb: () => Promise<any>) {
searchProviders.push(cb);
}

export function excludeSearchProvider(cb: () => Promise<any>) {
const index = searchProviders.indexOf(cb);

if (index !== -1) {
searchProviders.splice(index, 1);
}
}

export function getSearchProviders() {
return searchProviders;
}
17 changes: 14 additions & 3 deletions src/scripts/sitemap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ export function appendSection(section: SectionInfo, category: string) {

if (parent) {
const j = parent.length;

if (section.links.length > 0) {
const prevRoute = lastLink(parent[j - 1]).route;
navLinks[prevRoute] = [navLinks[prevRoute][0], section.links[0]];
}

for (let i = 0; i < section.links.length; i++) {
const prev = section.links[i - 1] || lastLink(parent[j - 1]);
const curr = section.links[i];
Expand All @@ -117,11 +117,22 @@ export function appendSection(section: SectionInfo, category: string) {
resolvers[curr.route] = parent;
navLinks[curr.route] = [prev, next];
}

parent.push(section);
}

return localRoutes;
}

export function removeSection(section: SectionInfo, category: string) {
const parent = resolveSections(`/${category}`);
const localRoutes: Record<string, React.ComponentType<RouteComponentProps>> = {};

if (parent) {
//TODO fine and remove sections properly
}

return localRoutes;
}

findRoutes();
2 changes: 2 additions & 0 deletions src/scripts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ export interface PiralDocletState {

export interface PiletDocletApi {
registerDocumentation(section: SectionInfo, category: string): void;
unregisterDocumentation(section: SectionInfo, category: string): void;
registerSearchProvider(cb: () => Promise<any>): void;
unregisterSearchProvider(cb: () => Promise<any>): void;
}
2 changes: 2 additions & 0 deletions src/tools/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const baseDir = meta.baseDir;
const config = meta.config;
const defaultsDir = resolve(__dirname, '../defaults');
const redirects = config.redirects || {};
const publicUrl = config.publicPath || '/';
const changelogPath = config.changelogFile && resolve(baseDir, config.changelogFile);
const sass = {
variables: resolve(defaultsDir, 'variables.scss'),
Expand Down Expand Up @@ -49,4 +50,5 @@ module.exports = {
helpers,
layouts,
redirects,
publicUrl,
};
8 changes: 7 additions & 1 deletion src/tools/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,17 @@ function readGeneratedFile(name, type) {
}

function generateFile(name, content, type = 'codegen') {
const path = getGeneratedFilePath(name, type);

if (!existsSync(generated)) {
mkdirSync(generated);
}

writeFileSync(resolve(generated, `${name}.${type}`), content, 'utf8');
const oldContent = readFileSync(path, 'utf8');

if (oldContent !== content) {
writeFileSync(path, content, 'utf8');
}
}

function makeFileFilter(fileNames, include, exclude) {
Expand Down

0 comments on commit a1e2c79

Please sign in to comment.