Skip to content

Commit

Permalink
[from now] 2024/08/06 17:05:37
Browse files Browse the repository at this point in the history
diff --git a/src/bin.ts b/src/bin.ts
index 3a0e511..0ff6df8 100644
--- a/src/bin.ts
+++ b/src/bin.ts
@@ -3,35 +3,19 @@ import typia from 'typia';
 import { dirname, resolve } from 'pathe';
 import { readPackageJSON, resolvePackageJSON } from 'pkg-types';
 import type { JSR } from './type';
+import { getExclude, getInclude } from './utils';

 const pkgJSONPath = await resolvePackageJSON();
 const pkgJSON = await readPackageJSON(pkgJSONPath);
 const rootDir = dirname(pkgJSONPath);
 const jsrPath = resolve(rootDir, 'jsr.json');

-const isStartWithExclamation = typia.createIs<`!${string}`>();
-const { files } = pkgJSON;
-const include = files == null ? ['dist'] : files.filter(file => isStartWithExclamation(file));
-const exclude = files == null
-	? undefined
-	: files
-		.filter(file => !isStartWithExclamation(file))
-		.map((file) => {
-			if (file.startsWith('!**/')) {
-				return file.slice(4);
-			}
-			if (file.startsWith('!')) {
-				return file.slice(1);
-			}
-			return file;
-		});
-
 const jsr = {
 	name: pkgJSON.name as string,
 	version: pkgJSON.version as string,
 	publish: {
-		include,
-		exclude,
+		include: getInclude(pkgJSON),
+		exclude: getExclude(pkgJSON),
 	},
 	exports: pkgJSON.exports,
 };
diff --git a/src/utils.ts b/src/utils.ts
new file mode 100644
index 0000000..d6fb053
--- /dev/null
+++ b/src/utils.ts
@@ -0,0 +1,44 @@
+import typia from 'typia';
+import type { PackageJson } from 'pkg-types';
+import { parse } from 'pathe';
+
+const isStartWithExclamation = typia.createIs<`!${string}`>();
+
+export function getInclude(pkgJSON: PackageJson): string[] | undefined {
+	const { files } = pkgJSON;
+	const include = files == null ? ['dist'] : files.filter(file => isStartWithExclamation(file));
+	return include;
+}
+
+export function getExclude(pkgJSON: PackageJson): string[] | undefined {
+	const { files } = pkgJSON;
+	const exclude = files == null
+		? undefined
+		: files
+			.filter(file => !isStartWithExclamation(file))
+			.map((file) => {
+				if (file.startsWith('!**/')) {
+					return file.slice(4);
+				}
+				if (file.startsWith('!')) {
+					return file.slice(1);
+				}
+				return file;
+			});
+	return exclude;
+}
+
+function convertDir(path: string, from: string, to: string): string {
+	const s = sep(path);
+}
+
+export function getExports(pkgJSON: PackageJson): Record<string, string> | string | undefined {
+	const { exports } = pkgJSON;
+	if (exports == null) {
+		return;
+	}
+	if (typeof exports === 'string') {
+		return exports;
+	}
+	return exports;
+}
  • Loading branch information
ryoppippi committed Aug 6, 2024
1 parent 968a732 commit 3695511
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
22 changes: 3 additions & 19 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,19 @@ import typia from 'typia';
import { dirname, resolve } from 'pathe';
import { readPackageJSON, resolvePackageJSON } from 'pkg-types';
import type { JSR } from './type';
import { getExclude, getInclude } from './utils';

const pkgJSONPath = await resolvePackageJSON();
const pkgJSON = await readPackageJSON(pkgJSONPath);
const rootDir = dirname(pkgJSONPath);
const jsrPath = resolve(rootDir, 'jsr.json');

const isStartWithExclamation = typia.createIs<`!${string}`>();
const { files } = pkgJSON;
const include = files == null ? ['dist'] : files.filter(file => isStartWithExclamation(file));
const exclude = files == null
? undefined
: files
.filter(file => !isStartWithExclamation(file))
.map((file) => {
if (file.startsWith('!**/')) {
return file.slice(4);
}
if (file.startsWith('!')) {
return file.slice(1);
}
return file;
});

const jsr = {
name: pkgJSON.name as string,
version: pkgJSON.version as string,
publish: {
include,
exclude,
include: getInclude(pkgJSON),
exclude: getExclude(pkgJSON),
},
exports: pkgJSON.exports,
};
Expand Down
44 changes: 44 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import typia from 'typia';
import type { PackageJson } from 'pkg-types';
import { parse } from 'pathe';

const isStartWithExclamation = typia.createIs<`!${string}`>();

export function getInclude(pkgJSON: PackageJson): string[] | undefined {
const { files } = pkgJSON;
const include = files == null ? ['dist'] : files.filter(file => isStartWithExclamation(file));
return include;
}

export function getExclude(pkgJSON: PackageJson): string[] | undefined {
const { files } = pkgJSON;
const exclude = files == null
? undefined
: files
.filter(file => !isStartWithExclamation(file))
.map((file) => {
if (file.startsWith('!**/')) {
return file.slice(4);
}
if (file.startsWith('!')) {
return file.slice(1);
}
return file;
});
return exclude;
}

function convertDir(path: string, from: string, to: string): string {
const s = sep(path);
}

export function getExports(pkgJSON: PackageJson): Record<string, string> | string | undefined {
const { exports } = pkgJSON;
if (exports == null) {
return;
}
if (typeof exports === 'string') {
return exports;
}
return exports;
}

0 comments on commit 3695511

Please sign in to comment.