Skip to content

Commit

Permalink
Add packType override, fix path regex
Browse files Browse the repository at this point in the history
  • Loading branch information
MulverineX committed Oct 30, 2023
1 parent c1d4c03 commit 09ac058
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sandstone",
"description": "Sandstone, a Typescript library for Minecraft datapacks.",
"version": "1.0.0-alpha.4",
"version": "1.0.0-alpha.5",
"contributors": [
{
"name": "TheMrZZ - Florian ERNST",
Expand Down
9 changes: 7 additions & 2 deletions src/core/resources/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export type ResourceClassArguments<ConflictType extends 'default' | 'list' | 'fu
* - `rename`: Rename the new file to an iterating number (ie. func1, func2, func3)
*/
// eslint-disable-next-line max-len
onConflict?: ConflictType extends 'default' ? BASIC_CONFLICT_STRATEGIES : BASIC_CONFLICT_STRATEGIES | 'append' | 'prepend'
onConflict?: ConflictType extends 'default' ? BASIC_CONFLICT_STRATEGIES : BASIC_CONFLICT_STRATEGIES | 'append' | 'prepend',

/**
* Overrides the default pack for the resource.
*/
packType?: PackType
}

export type ResourceNode<T = ResourceClass<any>> = Node & {
Expand Down Expand Up @@ -65,7 +70,7 @@ export abstract class ResourceClass<N extends ResourceNode = ResourceNode<any>>
constructor(protected core: SandstoneCore, file: { packType: PackType, extension?: string, encoding?: fs.EncodingOption | false }, NodeType: ResourceNodeConstructor<N>, path: ResourcePath, args: ResourceClassArguments<any>) {
this.node = new NodeType(core, this)

this.packType = file.packType
this.packType = args.packType || file.packType

this.fileExtension = file.extension
this.fileEncoding = file.encoding === undefined ? 'utf8' : file.encoding
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export type ReviewState = 'verified'|'pending'|'unsubmitted'|'rejected'
export async function safeWrite(...args: Partial<Parameters<typeof fs['writeFile']>>) {
if (typeof args[0] !== 'string') throw new Error('unimplemented')

await fs.ensureDir(args[0].replace(/\/(?:.(?!\/))+$/, ''))
await fs.ensureDir(args[0].replace(/(?:\/|\\)(?:.(?!(?:\/|\\)))+$/, ''))

return fs.writeFile(...args as Parameters<typeof fs['writeFile']>)
}

0 comments on commit 09ac058

Please sign in to comment.