-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update method optimized for optimal reliablity
- Loading branch information
1 parent
bac0cb6
commit 2ac3eed
Showing
12 changed files
with
116 additions
and
142 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function getNewFilePath(filePath: string, type: 'cjs' | 'mjs') { | ||
const prefix = type[0] | ||
|
||
return filePath.replace(/\.(js|ts)$/, (match) => { | ||
return match.replace(/(js|ts)/i, (type) => prefix + type) | ||
}) | ||
} |
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,33 @@ | ||
import * as fs from 'fs' | ||
import { NodeType } from './types.t' | ||
|
||
export function getUpdatedData(fileData: any, found: NodeType[], cb: any) { | ||
const newEntries: NodeType[] = [ | ||
{ start: 0, end: 0, value: '', filename: '' }, | ||
...found.sort((a, b) => a.start - b.start), | ||
] | ||
|
||
const chunks = newEntries.map((node, i, arr) => { | ||
const nextNode = arr[i + 1] | ||
const nodeEnd = node.end | ||
const nextNodeEnd = nextNode ? nextNode.start : Infinity | ||
const str = fileData.slice(nodeEnd, nextNodeEnd) | ||
|
||
if (!nextNode) return str | ||
return [str, `"${cb(nextNode) ?? nextNode.value}"`] | ||
}) | ||
|
||
return chunks.flat().join('') | ||
} | ||
|
||
export function resolveJsFilePath(target: string) { | ||
function isExists(target: string) { | ||
if (fs.existsSync(target) && fs.statSync(target).isFile()) return target | ||
} | ||
|
||
return ( | ||
isExists(target) || | ||
isExists(target + '.js') || | ||
isExists(target + '/index.js') | ||
) | ||
} |
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 |
---|---|---|
|
@@ -2,6 +2,5 @@ export type NodeType = { | |
start: number | ||
end: number | ||
value: string | ||
rawValue: string | ||
filename: string | ||
} |
Oops, something went wrong.