-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update resolve logic, add possibility to customise markdown plugin
- Loading branch information
1 parent
b177841
commit d9da48a
Showing
25 changed files
with
386 additions
and
343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
|
||
const { IFilemap } = require('./core-filemap-i') | ||
const { extname } = require('./util-path') | ||
const { hash } = require('./util-hash') | ||
|
||
class Filemap extends IFilemap { | ||
constructor (options) { | ||
super(options) | ||
|
||
this.packageScope = options.packageScope | ||
this.staticDirs = options.staticDirs | ||
this.wd = options.wd | ||
} | ||
|
||
map (abspath, referer) { | ||
super.map(abspath, referer) | ||
|
||
if (this.staticDirs != null) { | ||
for (const directory of this.staticDirs) { | ||
if (abspath.startsWith(directory)) return '/' + path.relative(directory, abspath) | ||
} | ||
} | ||
|
||
const ext = extname(abspath) | ||
const genericName = hash(path.relative(this.packageScope, abspath)) | ||
|
||
switch (ext) { | ||
case '.html': | ||
return '/' + path.relative(this.wd, abspath) | ||
case '.css': | ||
case '.js': | ||
return '/' + path.join('static', ext.substring(1), genericName + ext) | ||
default: | ||
return '/' + path.join('static', 'media', genericName + ext) | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
Filemap | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
const assert = require('assert') | ||
|
||
class IFilemap { | ||
map (abspath, referer, options) { | ||
assert(typeof abspath === 'string') | ||
return null | ||
} | ||
} | ||
|
||
module.exports = { | ||
IFilemap | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
|
||
const { IFilemap } = require('./core-filemap-i') | ||
const { hash } = require('./util-hash') | ||
const { foldLevels } = require('./util-path') | ||
|
||
const workdir = Symbol('workdir') | ||
|
||
class Filemap extends IFilemap { | ||
constructor (options) { | ||
super(options) | ||
|
||
this.aliases = options.aliases | ||
this.packageScope = options.packageScope | ||
this.staticDirs = options.staticDirs | ||
this.wd = options.wd | ||
|
||
this[workdir] = path.relative(this.packageScope, this.wd) | ||
} | ||
|
||
map (abspath, referer) { | ||
super.map(abspath, referer) | ||
|
||
if (this.staticDirs != null) { | ||
for (const directory of this.staticDirs) { | ||
if (abspath.startsWith(directory)) return '/' + path.relative(directory, abspath) | ||
} | ||
} | ||
|
||
const relative = path.relative(this.packageScope, abspath) | ||
|
||
if (relative.startsWith(this[workdir])) { | ||
return '/' + path.relative(this[workdir], relative) | ||
} | ||
|
||
if (relative.startsWith('../')) { | ||
if (relative.includes('node_modules')) { | ||
const base = abspath.substring(0, abspath.indexOf('node_modules') + 'node_modules'.length) | ||
for (const [alias, directory] of this.aliases) { | ||
if (base === directory) return '/' + path.join(alias, abspath.substring(base.length + 1)) | ||
} | ||
} | ||
|
||
return null | ||
} | ||
|
||
const right = foldLevels(path.relative(this[workdir], relative)) | ||
const middle = relative.substring(0, relative.lastIndexOf(right)) | ||
|
||
const alias = `~${hash(middle)}` // todo a readable solution | ||
if (!this.aliases.has(alias)) { | ||
const base = path.join(this.packageScope, middle.substring(0, middle.length - path.sep.length)) | ||
this.aliases.set(alias, base) | ||
} | ||
|
||
return '/' + path.join(alias, right) | ||
} | ||
|
||
output (relative) { | ||
return relative | ||
} | ||
} | ||
|
||
module.exports = { | ||
Filemap | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.