Skip to content

Commit

Permalink
0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Astrid committed Jan 29, 2024
1 parent 570aa19 commit aa5eed7
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 61 deletions.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "scribunto-bundler",
"description": "Lua bundler for Scribunto",
"version": "0.1.0",
"version": "0.1.1",
"author": "Astrid <[email protected]>",
"license": "MIT",
"type": "module",
Expand All @@ -13,7 +13,8 @@
"bundler"
],
"files": [
"dist"
"dist",
"templates"
],
"repository": {
"type": "git",
Expand All @@ -29,11 +30,12 @@
},
"dependencies": {
"@robertsspaceindustries/sub": "^1.0.8",
"@types/klaw": "^3.0.6",
"commander": "^11.1.0",
"klaw": "^4.1.0",
"picocolors": "^1.0.0"
},
"devDependencies": {
"@types/klaw": "^3.0.6",
"@types/node": "^20.11.7",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
Expand All @@ -44,9 +46,9 @@
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"klaw": "^4.1.0",
"prettier": "^3.2.4",
"tsup": "^8.0.1",
"typescript": "^5.3.3"
}
}

18 changes: 8 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface Module {

export default async function bundleProject() {
const workingDir = process.cwd();
const configPath = path.join(workingDir, `.${name}.js`);
const configPath = path.join(workingDir, '.bundler.js');

info(`Using ${configPath}`);

Expand Down
21 changes: 18 additions & 3 deletions src/components/bundler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import fs from 'node:fs';
import path from 'node:path';

import formatString from '@robertsspaceindustries/sub';

import dirname from '../utils/dirname';

import type { Module } from '../bundle';

const bundlerManagerTemplate = TEMPLATES.bundler;
const bundlerModuleTemplate = TEMPLATES.bundlerModule;
const bundlerReturnTemplate = TEMPLATES.bundlerReturn;
const bundlerDir = path.resolve(dirname, 'templates/bundler');
const bundlerManagerTemplate = fs.readFileSync(
path.join(bundlerDir, 'manager.lua'),
'utf-8',
);
const bundlerModuleTemplate = fs.readFileSync(
path.join(bundlerDir, 'module.lua'),
'utf-8',
);
const bundlerReturnTemplate = fs.readFileSync(
path.join(bundlerDir, 'return.lua'),
'utf-8',
);

export default function Bundler(modules: Module[]) {
const formattedModules = [];
Expand Down
55 changes: 28 additions & 27 deletions src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,38 @@ import childProcess from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';

import formatString from '@robertsspaceindustries/sub';

import { event, ready, wait, warn } from './utils/log';
import { name, version } from '../package.json';

const files = {
[`.${name}.js`]: TEMPLATES.config,
'package.json': formatString(TEMPLATES.package, {
name,
version,
}),
'.gitignore': TEMPLATES['.gitignore'],
'src/main.lua': '',
};

export default function createProject() {
import klaw from 'klaw';

import dirname from './utils/dirname';
import { error, info, ready, wait } from './utils/log';
import { name } from '../package.json';

const templateDir = path.resolve(dirname, 'templates/create');

export default async function createProject() {
const workingDir = process.cwd();

for (const file of Object.keys(files)) {
const target = path.join(workingDir, file);
if (!fs.existsSync(target)) {
fs.mkdirSync(path.dirname(target), { recursive: true });
fs.writeFileSync(target, files[file], 'utf-8');
event(`Created file ${file}`);
} else warn(`File ${file} already exists`);
}
let filesCopied = 0;
for await (const file of klaw(templateDir))
if (file.stats.isFile()) {
const relative = path.relative(templateDir, file.path);
const targetPath = path.relative(workingDir, relative);

fs.mkdirSync(path.dirname(targetPath), { recursive: true });
fs.copyFileSync(file.path, targetPath);
filesCopied += 1;
}
info(`Copied ${filesCopied} file${filesCopied === 1 ? '' : 's'}`);

wait('Installing packages...');
childProcess.execSync(`npm install`, {
cwd: workingDir,
});
try {
childProcess.execSync(`npm install`, {
cwd: workingDir,
});
} catch (err) {
error(err);
process.exit(1);
}

ready(`Base ${name} project created`);
}
1 change: 0 additions & 1 deletion src/enviroment.d.ts

This file was deleted.

7 changes: 7 additions & 0 deletions src/utils/dirname.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import path from 'path';
import { fileURLToPath } from 'url';

// Inner `path.dirname` goes to `dist`, hence the outer
const dirname = path.dirname(path.dirname(fileURLToPath(import.meta.url)));

export default dirname;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# dependencies
/node_modules

# production
/dist

# package managers
package-lock.json
4 changes: 4 additions & 0 deletions templates/create/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Lua.diagnostics.globals": ["mw"],
"Lua.workspace.ignoreDir": ["dist"]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "module",
"dependencies": {
"{{name}}": "^{{version}}"
"scribunto-bundler": "0.1.1"
}
}
Empty file added templates/create/src/main.lua
Empty file.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"outDir": "dist",
"emitDeclarationOnly": true,
},
"include": ["**/*.ts", "**/*.js"],
"include": ["**/*.ts", "**/*.js", "templates/create/.bundler.js"],
"exclude": ["dist", "node_modules"],
}
18 changes: 5 additions & 13 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import fs from 'node:fs';
import path from 'node:path';

import klaw from 'klaw';
import { defineConfig } from 'tsup';

const templates: Record<string, string> = {};
for await (const file of klaw('src/templates'))
if (file.stats.isFile())
templates[path.parse(file.path).name] = fs.readFileSync(file.path, 'utf-8');

export default defineConfig({
outDir: 'dist',
entry: ['src/index.ts'],
splitting: false,
clean: true,
sourcemap: false,
splitting: false,
target: 'node20',
format: 'esm',
dts: true,
define: {
TEMPLATES: JSON.stringify(templates),
banner: {
js: '#!/usr/bin/env node',
},
banner: { js: '#!/usr/bin/env node' },
});

0 comments on commit aa5eed7

Please sign in to comment.