Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Luau package template #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ function cmd(cmdStr: string, cwd: string) {
});
}

function shouldHaveDefaultScripts(template: InitMode) {
return template !== InitMode.LuauPackage;
}

function isPackageTemplate(template: InitMode): template is InitMode.Package | InitMode.LuauPackage {
return template === InitMode.Package || template === InitMode.LuauPackage;
}

const GIT_IGNORE = ["/node_modules", "/out", "/include", "*.tsbuildinfo"];

async function init(argv: yargs.Arguments<InitOptions>, initMode: InitMode) {
Expand Down Expand Up @@ -229,29 +237,28 @@ async function init(argv: yargs.Arguments<InitOptions>, initMode: InitMode) {
await cmd(selectedPackageManager.init, cwd);
const pkgJson = await fs.readJson(paths.packageJson);

if (template === InitMode.LuauPackage) {
pkgJson.scripts = undefined;
} else {
if (shouldHaveDefaultScripts(template)) {
pkgJson.scripts = {
build: "rbxtsc",
watch: "rbxtsc -w",
};
} else {
pkgJson.scripts = undefined;
}

if (template === InitMode.LuauPackage) {
if (isPackageTemplate(template)) {
pkgJson.name = RBXTS_SCOPE + "/" + pkgJson.name;
pkgJson.main = "lib/init.lua";
pkgJson.types = "lib/index.d.ts";
pkgJson.files = ["lib/init.lua", "lib/index.d.ts"];
pkgJson.publishConfig = { access: "public" };
}

if (template === InitMode.Package) {
pkgJson.name = RBXTS_SCOPE + "/" + pkgJson.name;
if (template === InitMode.LuauPackage) {
pkgJson.main = "src/init.lua";
pkgJson.types = "src/index.d.ts";
pkgJson.files = ["src/*"];
LouieK22 marked this conversation as resolved.
Show resolved Hide resolved
} else if (template === InitMode.Package) {
pkgJson.main = "out/init.lua";
pkgJson.types = "out/index.d.ts";
pkgJson.files = ["out", "!**/*.tsbuildinfo"];
pkgJson.publishConfig = { access: "public" };
pkgJson.scripts.prepublishOnly = selectedPackageManager.build;
}

Expand Down
2 changes: 1 addition & 1 deletion templates/luau-package/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"declaration": false,

// configurable
"rootDir": "lib"
"rootDir": "src"
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"target": "ES2019",
"lib": ["ES2019"],
"strict": true,
"noFallthroughCasesInSwitch": true,
"noFallthroughCasesInSwitch": false,
"strictNullChecks": true,
"esModuleInterop": true,
"removeComments": true,
Expand Down