Skip to content

Commit

Permalink
JavaScript、TypeScriptの両方に対応、リポジトリ名を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Nov 4, 2023
1 parent dbd9575 commit ed8f8b0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 22 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# vite-typescript-auto-loader-plugin
# vite-auto-loader-plugin

[![CodeQL](https://github.com/Next2D/vite-typescript-auto-loader-plugin/actions/workflows/codeql-analysis.yml/badge.svg?branch=main)](https://github.com/Next2D/vite-typescript-auto-loader-plugin/actions/workflows/codeql-analysis.yml)
[![Lint](https://github.com/Next2D/vite-typescript-auto-loader-plugin/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/Next2D/vite-typescript-auto-loader-plugin/actions/workflows/lint.yml)
[![release](https://img.shields.io/github/v/release/Next2D/vite-typescript-auto-loader-plugin)](https://github.com/Next2D/vite-typescript-auto-loader-plugin/releases)
[![license](https://img.shields.io/github/license/Next2D/vite-typescript-auto-loader-plugin)](https://github.com/Next2D/vite-typescript-auto-loader-plugin/blob/main/LICENSE)
[![CodeQL](https://github.com/Next2D/vite-auto-loader-plugin/actions/workflows/codeql-analysis.yml/badge.svg?branch=main)](https://github.com/Next2D/vite-auto-loader-plugin/actions/workflows/codeql-analysis.yml)
[![Lint](https://github.com/Next2D/vite-auto-loader-plugin/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/Next2D/vite-auto-loader-plugin/actions/workflows/lint.yml)
[![release](https://img.shields.io/github/v/release/Next2D/vite-auto-loader-plugin)](https://github.com/Next2D/vite-auto-loader-plugin/releases)
[![license](https://img.shields.io/github/license/Next2D/vite-auto-loader-plugin)](https://github.com/Next2D/vite-auto-loader-plugin/blob/main/LICENSE)

Next2D Framework vite TypeScript Auto Loader plugin.

```sh
npm i -D @next2d/vite-typescript-auto-loader-plugin
npm i -D @next2d/vite-auto-loader-plugin
```

## License
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@next2d/vite-typescript-auto-loader-plugin",
"version": "0.0.5",
"name": "@next2d/vite-auto-loader-plugin",
"version": "0.0.6",
"description": "Next2D Framework vite TypeScript Auto Loader plugin.",
"author": "Toshiyuki Ienaga<ienaga@next2d.app>",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"homepage": "https://next2d.app",
"bugs": "https://github.com/Next2D/vite-typescript-auto-loader-plugin/issues",
"bugs": "https://github.com/Next2D/vite-auto-loader-plugin/issues",
"scripts": {
"lint": "eslint src/**/*.ts",
"publish": "tsc"
Expand All @@ -18,7 +18,7 @@
],
"repository": {
"type": "git",
"url": "git+https://github.com/Next2D/vite-typescript-auto-loader-plugin.git"
"url": "git+https://github.com/Next2D/vite-auto-loader-plugin.git"
},
"dependencies": {
"@types/node": "^20.8.10"
Expand Down
39 changes: 27 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import * as fs from "fs";
import type { ConfigObjectImpl } from "./interface/ConfigObjectImpl";
import type { ObjectImpl } from "./interface/ObjectImpl";

const useTypeScript: boolean = fs.existsSync(`${process.cwd()}/src/index.ts`);
const ext: string = useTypeScript ? "ts" : "js";

/**
* @type {string}
* @private
Expand Down Expand Up @@ -65,12 +68,17 @@ const buildConfig = (object: ObjectImpl): void =>
// cache update
cacheConfig = configString;

fs.writeFileSync(
`${configDir}/Config.ts`,
`import type { ConfigImpl } from "@next2d/framework";
let source: string = "";
if (useTypeScript) {
source += `import type { ConfigImpl } from "@next2d/framework";
const config: ConfigImpl = ${configString};
export { config };`
);
export { config };`;
} else {
source += `const config = ${configString};
export { config };`;
}

fs.writeFileSync(`${configDir}/Config.${ext}`, source);
}
};

Expand Down Expand Up @@ -164,7 +172,7 @@ const buildPackage = (): void =>
for (let idx: number = 0; idx < files.length; ++idx) {

const file: string = files[idx];
if (file.indexOf(".ts") === -1) {
if (file.indexOf(`.${ext}`) === -1) {
continue;
}

Expand All @@ -183,7 +191,7 @@ const buildPackage = (): void =>
switch (true) {

case path.indexOf("src/view/") > -1:
imports += `import { ${name} } from "@/${path.split("src/")[1].split(".ts")[0]}";${EOL}`;
imports += `import { ${name} } from "@/${path.split("src/")[1].split(`.${ext}`)[0]}";${EOL}`;
packages += ` ["${name}", ${name}],${EOL}`;
break;

Expand All @@ -201,7 +209,7 @@ const buildPackage = (): void =>
.join("_")
.slice(0, -3);

imports += `import { ${name} as ${asName} } from "@/${path.split("src/")[1].split(".ts")[0]}";${EOL}`;
imports += `import { ${name} as ${asName} } from "@/${path.split("src/")[1].split(`.${ext}`)[0]}";${EOL}`;
packages += ` ["${key}", ${asName}],${EOL}`;
}
break;
Expand All @@ -219,13 +227,20 @@ const buildPackage = (): void =>
packages = packages.slice(0, -2);
packages += `${EOL}]`;

const packageString: string = `${imports}
let source: string = "";
if (useTypeScript) {
source = `${imports}
const packages: any[] = ${packages};
export { packages };`;
} else {
source = `${imports}
const packages = ${packages};
export { packages };`;
}

if (cachePackages !== packageString) {
cachePackages = packageString;
fs.writeFileSync(`${dir}/src/Packages.ts`, packageString);
if (cachePackages !== source) {
cachePackages = source;
fs.writeFileSync(`${dir}/src/Packages.${ext}`, source);
}
};

Expand Down
11 changes: 11 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"include": [
"src/**/*.ts",
".eslintrc.js"
],
"exclude": [
"node_modules",
"dist"
]
}

0 comments on commit ed8f8b0

Please sign in to comment.