mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
feat: add post-build-script to gradually migrate
This commit is contained in:
1 parent
3977db87a3
commit
8eaec839d3
11 files changed
+624
-154
No files matched your search
@@ -6,6 +6,6 @@
|
||||
"types": "dist/index.d.ts",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
"build": "tsc && node post-build-script.js"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
function addJsExtension(filePath) {
|
||||
if (fs.statSync(filePath).isDirectory()) {
|
||||
for (const child of fs.readdirSync(filePath)) {
|
||||
addJsExtension(path.join(filePath, child))
|
||||
}
|
||||
} else if (filePath.endsWith('.js')) {
|
||||
let content = fs.readFileSync(filePath, 'utf8')
|
||||
content = content.replace(/from\s+["']([^"']+)["']/g, (match, group1) => {
|
||||
if (!group1.match(/^[./]|http|https/)) return match // Skip node_modules
|
||||
if (!group1.endsWith('.js')) return `from "${group1}.js"`
|
||||
return match
|
||||
})
|
||||
fs.writeFileSync(filePath, content, 'utf8')
|
||||
}
|
||||
}
|
||||
|
||||
addJsExtension('./dist')
|
||||
@@ -1,20 +1,20 @@
|
||||
/* eslint-disable max-classes-per-file */
|
||||
export class DuplicateItemError extends Error {
|
||||
constructor(message) {
|
||||
constructor(message: string) {
|
||||
super(message)
|
||||
this.name = 'DuplicateItemError'
|
||||
}
|
||||
}
|
||||
|
||||
export class ParentNotExistsError extends Error {
|
||||
constructor(message) {
|
||||
constructor(message: string) {
|
||||
super(message)
|
||||
this.name = 'ParentNotExistsError'
|
||||
}
|
||||
}
|
||||
|
||||
export class FileNotExistsError extends Error {
|
||||
constructor(message) {
|
||||
constructor(message: string) {
|
||||
super(message)
|
||||
this.name = 'FileNotExistsError'
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
DuplicateItemError,
|
||||
ParentNotExistsError,
|
||||
FileNotExistsError,
|
||||
} from './errors.js'
|
||||
} from './errors'
|
||||
import { basename, dirname } from './utils.js'
|
||||
|
||||
export default class FileNode extends File {
|
||||
|
||||
File renamed without changes.
File renamed without changes.
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { DuplicateItemError, ParentNotExistsError } from './errors.js'
|
||||
import { DuplicateItemError, ParentNotExistsError } from './errors'
|
||||
import FileNode from './fileNode.js'
|
||||
|
||||
function createNodeFromFiles(files) {
|
||||
@@ -1,14 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "nodenext",
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "node",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"outDir": "./dist",
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"allowJs": true
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "src/*.test.js", "dist"]
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
Reference in new issue
Block a user