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

Add convertImportPaths #13

Merged
merged 3 commits into from
Dec 1, 2023
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ if has('syntax')
syntax on
endif
```

</details>

<details>
Expand Down
1 change: 1 addition & 0 deletions denops/dpp/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function defaultContext(): Context {

export function defaultDppOptions(): DppOptions {
return {
convertImportPaths: [],
extOptions: {},
extParams: {},
hooksFileMarker: "{{{,}}}",
Expand Down
33 changes: 33 additions & 0 deletions denops/dpp/dpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,39 @@ export class Dpp {
}
}

// Generate static.ts
let mods: string[] = [];
for (const importPath of options.convertImportPaths) {
for (const glob of importPath.globs) {
for (const plugin of Object.values(recordPlugins)) {
if (!await isDirectory(`${plugin.rtp}/denops`)) {
continue;
}

mods = mods.concat(
await fn.glob(
denops,
`${plugin.rtp}/${glob}`,
true,
true,
) as string[],
);
}
}

const staticFile = `${basePath}/${name}/${importPath.output}`;
const staticLines = [];
for (const [index, path] of mods.entries()) {
staticLines.push(`import * as mod${index} from "file:https://${path}"`);
}
staticLines.push("export const mods = {");
for (const [index, path] of mods.entries()) {
staticLines.push(` "${path}": mod${index},`);
}
staticLines.push("};");
await Deno.writeTextFile(staticFile, staticLines.join("\n"));
}

await denops.cmd("doautocmd <nomodeline> User Dpp:makeStatePost");
}

Expand Down
6 changes: 6 additions & 0 deletions denops/dpp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ export type Context = {
placeholder?: unknown;
};

type ImportPath = {
globs: string[];
output: string;
};

export type DppOptions = {
convertImportPaths: ImportPath[];
extOptions: Record<ExtName, Partial<ExtOptions>>;
extParams: Record<ExtName, Partial<BaseExtParams>>;
hooksFileMarker: string;
Expand Down
14 changes: 14 additions & 0 deletions doc/dpp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ INTERFACE *dpp-interface*
------------------------------------------------------------------------------
OPTIONS *dpp-options*

*dpp-option-convertImportPaths*
convertImportPaths (ImportPath[])
It is the list of dynamic import paths for denops plugins.
It is converted to "output" file under {base-path}/{name}
directory.

>
type ImportPath = {
globs: string[];
output: string;
};
<
It is useful for dynamic load denops plugins.

*dpp-option-extOptions*
extOptions (dictionary)
It is a dictionary that maps ext names to its options.
Expand Down
Loading