Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process glob-like path that refers to a real file correctly #117

Merged
merged 4 commits into from
Jun 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed

- Fix that cannot find Markdown from directory that includes non-ASCII code ([#108](https://github.com/marp-team/marp-cli/issues/108), [#109](https://github.com/marp-team/marp-cli/pull/109))
- Process glob-like path that refers to a real file correctly ([#95](https://github.com/marp-team/marp-cli/issues/95), [#117](https://github.com/marp-team/marp-cli/pull/117))

## v0.11.1 - 2019-06-28

Expand Down
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class MarpCLIConfig {
const theme = await this.loadTheme()
const initialThemes = theme instanceof Theme ? [theme] : []

const themeSetPathes =
const themeSetPaths =
this.args.themeSet ||
(this.conf.themeSet
? (Array.isArray(this.conf.themeSet)
Expand All @@ -131,13 +131,13 @@ export class MarpCLIConfig {
: [])

const themeSet = await ThemeSet.initialize(
(inputDir ? [inputDir] : []).concat(themeSetPathes),
(inputDir ? [inputDir] : []).concat(themeSetPaths),
initialThemes
)

if (
themeSet.themes.size <= initialThemes.length &&
themeSetPathes.length > 0
themeSetPaths.length > 0
)
warn('Not found additional theme CSS files.')

Expand Down
27 changes: 24 additions & 3 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as url from 'url'
import { tmpName } from 'tmp'
import { promisify } from 'util'

const stat = promisify(fs.stat)
const mkdirpPromise = promisify<string, any>(mkdirp)
const readFile = promisify(fs.readFile)
const tmpNamePromise = promisify(tmpName)
Expand Down Expand Up @@ -118,15 +119,35 @@ export class File {

private static stdinBuffer?: Buffer

static async find(...pathes: string[]): Promise<File[]> {
return (await globby(pathes, {
static async find(...paths: string[]): Promise<File[]> {
const filepaths = new Set<string>()
const globs: string[] = []

// Collect passed files that refers to a real path at first
for (const p of paths) {
try {
const s: fs.Stats = await stat(p)

if (s.isFile()) {
filepaths.add(path.resolve(p))
continue
}
} catch (e) {}

globs.push(p)
}

// Find remaining path through globby
;(await globby(globs, {
absolute: true,
expandDirectories: {
extensions: [],
files: markdownExtensions.map(ext => `*.${ext}`),
},
ignore: ['**/node_modules'],
})).map(p => new File(p))
})).forEach(p => filepaths.add(p))

return [...filepaths.values()].map(p => new File(p))
}

static async findDir(directory: string): Promise<File[]> {
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions test/marp-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,17 @@ describe('Marp CLI', () => {
)
})

context('when glob special chars are included in real file path', () => {
it('finds out a file correctly', async () => {
jest.spyOn(cli, 'info').mockImplementation()
jest
.spyOn<any, any>(Converter.prototype, 'convertFiles')
.mockImplementation(() => [])

expect(await marpCli([assetFn('_files/字/(non-ascii).md')])).toBe(0)
})
})

context('when non-ASCII code is included in directory name', () => {
it('finds out markdown files correctly', async () => {
jest.spyOn(cli, 'info').mockImplementation()
Expand Down
2 changes: 1 addition & 1 deletion test/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('ThemeSet', () => {
})

describe('#findPath', () => {
it('returns the result of findings from original pathes', async () => {
it('returns the result of findings from original paths', async () => {
const themeSet = await ThemeSet.initialize([themeDir])
const found = await themeSet.findPath()

Expand Down