-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
519 additions
and
190 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 |
---|---|---|
|
@@ -6,15 +6,15 @@ | |
<!-- <script src="https://unpkg.com/[email protected]" type="text/javascript"></script> --> | ||
<!-- For testing: Load from local bundle `yarn bundle` --> | ||
<script | ||
src="../../dist/models/mobilenet_v2_mid/model.min.js" | ||
src="../../dist/cjs/models/mobilenet_v2_mid/model.min.js" | ||
type="text/javascript" | ||
></script> | ||
<script | ||
src="../../dist/models/mobilenet_v2_mid/group1-shard1of2.min.js" | ||
src="../../dist/cjs/models/mobilenet_v2_mid/group1-shard1of2.min.js" | ||
type="text/javascript" | ||
></script> | ||
<script | ||
src="../../dist/models/mobilenet_v2_mid/group1-shard2of2.min.js" | ||
src="../../dist/cjs/models/mobilenet_v2_mid/group1-shard2of2.min.js" | ||
type="text/javascript" | ||
></script> | ||
<script src="../../dist/browser/nsfwjs.min.js" type="text/javascript"></script> | ||
|
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,40 @@ | ||
import { readdirSync, readFileSync, statSync, writeFileSync } from "fs"; | ||
import { join } from "path"; | ||
|
||
const directory = "./dist/esm"; // Target directory | ||
const extension = ".js"; | ||
|
||
function addExtensions(dir) { | ||
const files = readdirSync(dir); | ||
|
||
files.forEach((file) => { | ||
const fullPath = join(dir, file); | ||
|
||
if (statSync(fullPath).isDirectory()) { | ||
addExtensions(fullPath); | ||
} else if (fullPath.endsWith(".js")) { | ||
let content = readFileSync(fullPath, "utf8"); | ||
|
||
// Add .js extension to static imports (from './path') | ||
content = content.replace(/(from\s+['"]\.\/[^'"]+)/g, (match) => { | ||
if (!match.endsWith(extension)) { | ||
return `${match}${extension}`; | ||
} | ||
return match; | ||
}); | ||
|
||
// Add .js extension to dynamic imports (import('./path')) | ||
content = content.replace(/(import\(['"]\.\/[^'"]+)/g, (match) => { | ||
if (!match.endsWith(extension)) { | ||
return `${match}${extension}`; | ||
} | ||
return match; | ||
}); | ||
|
||
writeFileSync(fullPath, content); | ||
} | ||
}); | ||
} | ||
|
||
// Call the function on the target directory | ||
addExtensions(directory); |
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,13 @@ | ||
import { writeFileSync } from "fs"; | ||
import { join } from "path"; | ||
|
||
function addPackageJson(dir, type) { | ||
const packageJsonContent = JSON.stringify({ type }, null, 2); | ||
const filePath = join(dir, "package.json"); | ||
writeFileSync(filePath, packageJsonContent); | ||
console.log(`Created package.json in ${dir}`); | ||
} | ||
|
||
// Add package.json for ESM and CJS builds | ||
addPackageJson("./dist/esm", "module"); | ||
addPackageJson("./dist/cjs", "commonjs"); |
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 |
---|---|---|
@@ -1,20 +1,5 @@ | ||
import { readdirSync, unlinkSync } from "fs"; | ||
import { join } from "path"; | ||
import { rmSync } from "fs"; | ||
|
||
const dir = "./models"; | ||
const dir = "./src/models"; | ||
|
||
// Get the names of all subfolders in the dir | ||
const models = readdirSync(dir, { withFileTypes: true }) | ||
.filter((dirent) => dirent.isDirectory()) | ||
.map((dirent) => dirent.name); | ||
|
||
models.forEach((model) => { | ||
const modelDir = join(dir, model); | ||
|
||
readdirSync(modelDir, { withFileTypes: true }) | ||
.filter((dirent) => dirent.isFile() && dirent.name.endsWith(".min.js")) | ||
.forEach((dirent) => { | ||
const file = join(modelDir, dirent.name); | ||
unlinkSync(file); | ||
}); | ||
}); | ||
rmSync(dir, { recursive: true, force: true }); |
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
Oops, something went wrong.