Skip to content

Commit 6a9015b

Browse files
committed
Predictable stores and remove file extensions
1 parent cc72325 commit 6a9015b

18 files changed

+109
-81
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ const router = new Router({
4848
routes: [
4949
createRoute({
5050
requireContext: require.context('./..', true, /.demo.vue$/),
51-
path: '/demo'
51+
path: '/demo',
52+
hideFileExtensions: true, // optional, hides file extensions in list.
5253
}),
5354
]
5455
})
@@ -73,7 +74,7 @@ if (process.env.NODE_ENV !== 'production') {
7374
children: [
7475
createRoute({
7576
requireContext: require.context('./..', true, /.demo.vue$/),
76-
path: '/demo'
77+
path: '/demo',
7778
}),
7879
],
7980
})

demo/routes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ const router = new Router({
1010
createRoute({
1111
requireContext: require.context('./tree', true, /.vue$/),
1212
path: '/demo',
13+
hideFileExtensions: true,
1314
}),
1415
createRoute({
1516
requireContext: require.context('./../src', true, /.demo.vue$/),
1617
path: '/src',
18+
hideFileExtensions: true,
1719
}),
1820
],
1921
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-book",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "Tree view for your demo components",
55
"main": "index.js",
66
"private": false,

src/app.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import VueBookRouteFactory from './classes/Main/VueBookRouteFactory'
22
import './scss/app.scss'
33
import './font-awesome-config'
4-
import { VueBookConfig } from '@/classes/Main/VueBookConfig'
4+
import { VueBookConfig } from './classes/Main/VueBookConfig'
55

66
export function createRoute (options: Partial<VueBookConfig>) {
77
const config = new VueBookConfig(options)
88

99
return VueBookRouteFactory.create(config)
1010
}
1111

12-
/** @deprecated use VueBook.createRoute instead */
12+
/** @deprecated use createRoute instead */
1313
export default function (requireContext: any, path: string | RegExp) {
1414
return createRoute(new VueBookConfig({
1515
requireContext,
1616
path,
17+
hideFileExtensions: true,
1718
}))
1819
}

src/classes/Factory/DemoFolderFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import DemoFolder from '../Main/DemoFolder'
1+
import { DemoFolder } from '../Main/DemoFolder'
22
import DemoFileFactory from './DemoFileFactory'
33

44
export default class DemoFolderFactory {

src/classes/Main/DemoFile.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import DemoFolder from './DemoFolder'
1+
import { DemoFolder } from './DemoFolder'
22

33
export default class DemoFile {
44
path: string = ''
@@ -18,6 +18,10 @@ export default class DemoFile {
1818
return this.path.split('/').pop() || ''
1919
}
2020

21+
getFilenameWithoutExtension(): string {
22+
return this.getFilename().split('.')[0]
23+
}
24+
2125
getParentFolderPath (): string {
2226
return this.path.split('/').slice(0, -1).join('/')
2327
}

src/classes/Main/DemoFolder.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import DemoFile from './DemoFile'
22
import DemoFolderMapper from '../Mapper/DemoFolderMapper'
3+
import DemoFileCollection from '@/classes/Main/DemoFileCollection'
34

4-
export default class DemoFolder {
5+
export class DemoFolder {
56
name: string = ''
67
isOpen: boolean = false
78
folders: DemoFolder[] = []
@@ -12,6 +13,24 @@ export default class DemoFolder {
1213
Object.assign(this, data)
1314
}
1415

16+
static createFromDemoFileCollection (demoFileCollection: DemoFileCollection) {
17+
const folderTemporary = new DemoFolder()
18+
19+
// Add all files to temporary folder.
20+
const files = demoFileCollection.demoFiles
21+
files.forEach((node: any) => folderTemporary.addDemoFile(node))
22+
23+
const rootFolder = folderTemporary.folders[0]
24+
console.log('rootFolder', rootFolder)
25+
26+
// Bind nodes to folders.
27+
rootFolder.fillParents()
28+
// Open topmost folder for convenience.
29+
rootFolder.open()
30+
31+
return rootFolder
32+
}
33+
1534
addFile (node: DemoFile, relativePath: string): void {
1635
if (relativePath) {
1736
const folderNameArray = relativePath.split('/')

src/classes/Main/VueBookConfig.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
export class VueBookConfig {
22
requireContext: any
3-
path: string | RegExp
3+
path!: string | RegExp
44
hideFileExtensions: boolean = false
55

66
constructor (data: Partial<VueBookConfig> = {}) {
7+
if (!data.requireContext) {
8+
throw(`'requireContext' is not defined on VueBookConfig`)
9+
}
10+
if (!data.path) {
11+
throw(`'path' is not defined on VueBookConfig`)
12+
}
713
Object.assign(this, data)
814
}
915
}

src/classes/Main/VueBookRouteFactory.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import DemoFile from './DemoFile'
33
import VueBookDemoPage from '../../components/DemoPage/VueBookDemoPage.vue'
44
import DemoFileCollection from './DemoFileCollection'
55
import { RouteConfig } from 'vue-router'
6-
import { VueBookConfig } from '@/classes/Main/VueBookConfig'
6+
import { VueBookConfig } from './VueBookConfig'
7+
import { DemoFolder } from './DemoFolder'
78

89
/**
910
* Creates route for vue-router with all necessary boilerplate.
@@ -13,7 +14,7 @@ export default class VueBookRouteFactory {
1314
const requireContext = vueBookConfig.requireContext
1415
const path = vueBookConfig.path
1516

16-
const demoFilesCollection = new DemoFileCollection({
17+
const demoFileCollection = new DemoFileCollection({
1718
demoFiles: requireContext.keys().map((key: string) => {
1819
return new DemoFile({
1920
path: path + key.substr(1),
@@ -26,9 +27,11 @@ export default class VueBookRouteFactory {
2627
path: path + '*',
2728
component: VueBookDemoPage,
2829
meta: {
29-
demoFilesCollection,
30+
demoFolder: DemoFolder.createFromDemoFileCollection(demoFileCollection),
31+
demoFileCollection,
3032
hideFileExtensions: vueBookConfig.hideFileExtensions,
3133
},
3234
}
3335
}
36+
3437
}

src/classes/Mapper/DemoFolderMapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import DemoFolder from '../Main/DemoFolder'
1+
import { DemoFolder } from '../Main/DemoFolder'
22
import DemoFileMapper from './DemoFileMapper'
33

44
export default class DemoFolderMapper {

0 commit comments

Comments
 (0)