Skip to content

Commit c889a5b

Browse files
committed
update 6 files and create 1 file
1 parent 82433ce commit c889a5b

7 files changed

Lines changed: 47 additions & 35 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nano191225/scriptup",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "ScriptAPI version updater for Minecraft Bedrock",
55
"license": "MIT",
66
"author": "Nano191225",

src/commands/build.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function build(options: BuildCommandOptions = {}): Promise<void> {
2323
}
2424

2525
const userConfig = await loadTsdownConfig(path.resolve("tsdown.config.ts"));
26-
const sourceEntry = getSourceEntry(userConfig);
26+
const sourceEntry = getSourceEntry("src", userConfig);
2727
if (!sourceEntry) {
2828
logger.error("Source entry not found. Expected src/main.ts, src/index.ts, or tsdown.config.ts entry.");
2929
process.exit(1);
@@ -85,17 +85,19 @@ function ensureBuildOutput(outputEntry: string): void {
8585
}
8686
}
8787

88-
function getSourceEntry(userConfig: UserConfig): string | null {
89-
const mainEntry = path.resolve("src/main.ts");
88+
function getSourceEntry(directory: string, userConfig?: UserConfig): string | null {
89+
const mainEntry = path.resolve(directory, "main.ts");
9090
if (fs.existsSync(mainEntry)) {
9191
return mainEntry;
9292
}
9393

94-
const indexEntry = path.resolve("src/index.ts");
94+
const indexEntry = path.resolve(directory, "index.ts");
9595
if (fs.existsSync(indexEntry)) {
9696
return indexEntry;
9797
}
9898

99+
if (!userConfig) return null;
100+
99101
const configuredEntry = resolveConfiguredEntry(userConfig.entry);
100102
if (!configuredEntry) {
101103
return null;
@@ -148,27 +150,31 @@ async function loadTsdownConfig(configPath: string): Promise<UserConfig> {
148150
}
149151

150152
async function buildLocalPackageDist(): Promise<void> {
151-
const packageEntries = getPackageTypeScriptEntries(path.resolve("package"));
152-
if (packageEntries.length === 0) {
153+
// const packageEntries = getPackageTypeScriptEntries(path.resolve("package"));
154+
const sourceEntry = getSourceEntry("package");
155+
if (!sourceEntry) {
153156
return;
154157
}
155158

156159
logger.info("Building local package sources into dist/... ");
157160

158161
const packageBuildConfig: InlineConfig = {
159162
config: false,
160-
entry: packageEntries.map((entry) => path.relative(process.cwd(), entry)),
163+
entry: path.relative(process.cwd(), sourceEntry),
161164
outDir: path.relative(process.cwd(), path.resolve("dist")),
162165
format: "esm" as const,
163166
target: "es2024",
164167
platform: "neutral" as const,
165168
clean: true,
166169
tsconfig: path.relative(process.cwd(), path.resolve("tsconfig.json")),
167170
outExtensions: () => ({ js: ".js" }),
168-
unbundle: true,
169171
dts: true,
172+
unbundle: false,
170173
deps: {
171-
neverBundle: /^@minecraft\/(?!math(?:\/|$)|vanilla-data(?:\/|$))/,
174+
// alwaysBundle: "**/*",
175+
// neverBundle: /^@minecraft\/(?!math(?:\/|$)|vanilla-data(?:\/|$))/,
176+
// neverBundle: "**/*",
177+
// onlyBundle: false,
172178
}
173179
};
174180

src/commands/new.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export async function createNewProject(projectName: string, options: NewCommandO
2424
await scaffoldProject({
2525
targetDir,
2626
projectName,
27+
directoryName,
2728
lib: options.lib,
2829
workflow: options.workflow,
2930
});
@@ -56,11 +57,11 @@ function resolveProjectTargetDir(projectName: string, options: NewCommandOptions
5657
}
5758

5859
function resolveProjectDirectoryName(projectName: string): string {
59-
const replacedSeparators = projectName.trim().replace(/[\\/]+/g, "$");
60-
const sanitized = replacedSeparators.replace(/[^A-Za-z0-9@$-_.]/g, "");
60+
const replacedSeparators = projectName.trim().replace(/[\\/]+/g, "-");
61+
const sanitized = replacedSeparators.replace(/[^A-Za-z0-9-_]/g, "");
6162

6263
if (sanitized.length === 0) {
63-
logger.error("Project name is empty after sanitizing. Use at least one of A-Z, a-z, 0-9, @, $, -, _, or .");
64+
logger.error("Project name is empty after sanitizing. Use at least one of A-Z, a-z, 0-9, -, or _.");
6465
process.exit(1);
6566
}
6667

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const VERSION = "1.3.1";
1+
export const VERSION = "1.3.2";

src/utils/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ export function error(message: string): void {
1818

1919
export function done(message: string): void {
2020
console.log(`${chalk.green("[DONE]")} ${message}`);
21-
}
21+
}

src/utils/scaffold.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import { Manifest, ManifestDependency, ManifestVersion } from "./manifest.js";
66
import { extractMcVersion, extractModuleVersion, getVersions } from "./versions.js";
77
import * as logger from "./logger.js";
88
import { VERSION } from "../constants.js";
9+
import { getUsername } from "./username.js";
910

1011
const DEFAULT_ENGINE_VERSION: [number, number, number] | string = "1.20.0";
1112

1213
interface ScaffoldOptions {
1314
targetDir: string;
1415
projectName?: string;
16+
directoryName?: string;
1517
lib?: boolean;
1618
workflow?: boolean;
1719
}
@@ -25,13 +27,14 @@ interface ResolvedDependencyInfo {
2527
export async function scaffoldProject(options: ScaffoldOptions): Promise<void> {
2628
const targetDir = path.resolve(options.targetDir);
2729
const projectName = options.projectName?.trim() || path.basename(targetDir);
30+
const directoryName = options.directoryName?.trim() || projectName;
2831
const includeLibraryTemplate = options.lib === true;
2932
const includeWorkflow = options.workflow !== false;
3033

3134
fs.mkdirSync(targetDir, { recursive: true });
3235

3336
const dependencyInfo = await resolveDependencyInfo();
34-
const files = createTemplateFiles(projectName, dependencyInfo, includeWorkflow, includeLibraryTemplate);
37+
const files = createTemplateFiles(projectName, directoryName, dependencyInfo, includeWorkflow, includeLibraryTemplate);
3538

3639
let createdCount = 0;
3740

@@ -135,13 +138,14 @@ async function resolveDependencyInfo(): Promise<ResolvedDependencyInfo> {
135138

136139
function createTemplateFiles(
137140
projectName: string,
141+
directoryName: string,
138142
dependencyInfo: ResolvedDependencyInfo,
139143
includeWorkflow: boolean,
140144
includeLibraryTemplate: boolean,
141145
): Record<string, string> {
142146
const libraryPackageName = includeLibraryTemplate ? resolveLibraryPackageName(projectName) : null;
143147
const manifest = createManifest(projectName, dependencyInfo.engineVersion, dependencyInfo.dependencies, includeLibraryTemplate);
144-
const packageJson = createPackageJson(projectName, dependencyInfo.packageDependencies, includeLibraryTemplate, libraryPackageName);
148+
const packageJson = createPackageJson(projectName, directoryName, dependencyInfo.packageDependencies, includeLibraryTemplate, libraryPackageName);
145149

146150
const files: Record<string, string> = {
147151
".gitignore": "node_modules/\nscripts\ndist\n*.mcpack\n*.mcaddon\n",
@@ -216,6 +220,7 @@ function createManifest(
216220

217221
function createPackageJson(
218222
projectName: string,
223+
directoryName: string,
219224
dependencies: Record<string, string>,
220225
includeLibraryTemplate: boolean,
221226
libraryPackageName: string | null,
@@ -247,7 +252,8 @@ function createPackageJson(
247252
},
248253
main: "./dist/main.js",
249254
types: "./dist/main.d.ts",
250-
prepublishOnly: "scriptup build --release && node .github/workflows/ensure-dts-export.js",
255+
prepublishOnly: "scriptup build --release && node .github/workflows/ensure-dts-export.js",
256+
repository: `https://github.com/${getUsername() ?? "{{your-username}}"}/${directoryName}.git`,
251257
}
252258
: {}),
253259
scripts: {
@@ -637,22 +643,7 @@ function resolveLibraryPackageName(projectName: string): string {
637643

638644
function createLicense(): string {
639645
const year = new Date().getFullYear();
640-
let author = "{{author}}";
641-
try {
642-
const gitNameResult = spawnSync("git", ["config", "user.name"], {
643-
encoding: "utf-8",
644-
shell: true,
645-
});
646-
if (gitNameResult.status === 0) {
647-
const gitName = gitNameResult.stdout.trim();
648-
if (gitName) {
649-
author = gitName;
650-
}
651-
}
652-
} catch (error) {
653-
logger.warn(`Failed to get git user.name: ${error instanceof Error ? error.message : String(error)}`);
654-
logger.warn("Using placeholder author name in LICENSE.");
655-
}
646+
const author = getUsername() || "{{author}}";
656647

657648
return `MIT License
658649
@@ -681,7 +672,7 @@ function normalizePackageName(projectName: string): string {
681672
const normalized = projectName
682673
.trim()
683674
.toLowerCase()
684-
.replace(/[^a-z0-9-_\s]/g, "")
675+
.replace(/[^a-z0-9-@\/_\s]/g, "")
685676
.replace(/\s+/g, "-")
686677
.replace(/-+/g, "-")
687678
.replace(/^-|-$/g, "");

src/utils/username.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { spawnSync } from "node:child_process";
2+
3+
export function getUsername(): string | undefined {
4+
try {
5+
const gitNameResult = spawnSync("git", ["config", "user.name"], {
6+
encoding: "utf-8",
7+
shell: true,
8+
});
9+
if (gitNameResult.status === 0) {
10+
const gitName = gitNameResult.stdout.trim();
11+
if (gitName) return gitName;
12+
}
13+
} catch {}
14+
}

0 commit comments

Comments
 (0)