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
43 changes: 32 additions & 11 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum InitMode {
Model = "model",
Plugin = "plugin",
Package = "package",
LuauPackage = "luau-package",
}

enum PackageManager {
Expand Down Expand Up @@ -141,10 +142,12 @@ async function init(argv: yargs.Arguments<InitOptions>, initMode: InitMode) {
type: () => initMode === InitMode.None && "select",
name: "template",
message: "Select template",
choices: [InitMode.Game, InitMode.Model, InitMode.Plugin, InitMode.Package].map(value => ({
title: value,
value,
})),
choices: [InitMode.Game, InitMode.Model, InitMode.Plugin, InitMode.Package, InitMode.LuauPackage].map(
LouieK22 marked this conversation as resolved.
Show resolved Hide resolved
value => ({
title: value,
value,
}),
),
initial: 0,
},
{
Expand Down Expand Up @@ -225,10 +228,24 @@ async function init(argv: yargs.Arguments<InitOptions>, initMode: InitMode) {
await benchmark("Initializing package.json..", async () => {
await cmd(selectedPackageManager.init, cwd);
const pkgJson = await fs.readJson(paths.packageJson);
pkgJson.scripts = {
build: "rbxtsc",
watch: "rbxtsc -w",
};

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

if (template === InitMode.LuauPackage) {
pkgJson.name = RBXTS_SCOPE + "/" + pkgJson.name;
pkgJson.main = "lib/init.lua";
LouieK22 marked this conversation as resolved.
Show resolved Hide resolved
pkgJson.types = "lib/index.d.ts";
pkgJson.files = ["lib/init.lua", "lib/index.d.ts"];
LouieK22 marked this conversation as resolved.
Show resolved Hide resolved
pkgJson.publishConfig = { access: "public" };
}
LouieK22 marked this conversation as resolved.
Show resolved Hide resolved

if (template === InitMode.Package) {
pkgJson.name = RBXTS_SCOPE + "/" + pkgJson.name;
pkgJson.main = "out/init.lua";
Expand All @@ -237,6 +254,7 @@ async function init(argv: yargs.Arguments<InitOptions>, initMode: InitMode) {
pkgJson.publishConfig = { access: "public" };
pkgJson.scripts.prepublishOnly = selectedPackageManager.build;
}

await fs.outputFile(paths.packageJson, JSON.stringify(pkgJson, null, 2));
});

Expand All @@ -256,12 +274,15 @@ async function init(argv: yargs.Arguments<InitOptions>, initMode: InitMode) {

await benchmark("Installing dependencies..", async () => {
const devDependencies = [
"roblox-ts" + (compilerVersion ? `@${compilerVersion}` : ""),
"@rbxts/compiler-types" + (compilerVersion ? `@compiler-${compilerVersion}` : ""),
"@rbxts/types",
"typescript",
];

if (template !== InitMode.LuauPackage) {
devDependencies.push("roblox-ts" + (compilerVersion ? `@${compilerVersion}` : ""));
devDependencies.push("typescript");
}

if (prettier) {
devDependencies.push("prettier");
}
Expand Down Expand Up @@ -372,7 +393,7 @@ async function init(argv: yargs.Arguments<InitOptions>, initMode: InitMode) {
await fs.copy(templateDir, cwd);
});

if (!argv.skipBuild) {
if (template !== InitMode.LuauPackage && !argv.skipBuild) {
await benchmark("Compiling..", () => cmd(selectedPackageManager.build, cwd));
}
}
Expand Down
7 changes: 7 additions & 0 deletions templates/luau-package/lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
interface Module {
sayHello: (name: string) => string;
}

declare const Module: Module;

export = Module;
7 changes: 7 additions & 0 deletions templates/luau-package/lib/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
local Module = {}

function Module.sayHello(name: string)
return `Hello {name}!`
end

return Module
23 changes: 23 additions & 0 deletions templates/luau-package/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
// required
"allowSyntheticDefaultImports": true,
"jsx": "react",
"jsxFactory": "React.createElement",
"jsxFragmentFactory": "React.Fragment",
"module": "commonjs",
"moduleResolution": "Node",
"noLib": true,
"resolveJsonModule": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"moduleDetection": "force",
"strict": true,
"target": "ESNext",
"typeRoots": ["node_modules/@rbxts"],
"declaration": false,

// configurable
"rootDir": "lib"
}
}