create-monolayer-app 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/template/_gitignore
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
.DS_Store
|
|
2
2
|
|
|
3
3
|
.env
|
|
4
|
-
/node_modules/
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
node_modules/
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
/
|
|
7
|
+
# React Router
|
|
8
|
+
.react-router/
|
|
9
|
+
build/
|
|
10
10
|
|
|
11
11
|
.pglite_development/
|
|
12
12
|
.pglite_test/
|
|
13
|
+
|
|
14
|
+
.config/kysely.config.js
|
|
15
|
+
.config/kysely.config.js.map
|
|
16
|
+
|
|
17
|
+
.emulator/
|
package/template/package.json
CHANGED
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"postmigrate:down": "npm run db:create-types",
|
|
17
17
|
"migrate:list": "kysely migrate:list",
|
|
18
18
|
"migrate:make": "tsx vendor/kysely-dsql/generator/create-migration.ts",
|
|
19
|
-
"db:create-types": "tsx vendor/kysely-dsql/generator/generate-types-from-pglite.ts"
|
|
19
|
+
"db:create-types": "tsx vendor/kysely-dsql/generator/generate-types-from-pglite.ts",
|
|
20
|
+
"package-app": "node vendor/package-app/package-app.mjs"
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
23
|
"@aws-sdk/dsql-signer": "^3.1126.0",
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, rmSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
|
|
7
|
+
const DEFAULT_OUTPUT_DIR = "build";
|
|
8
|
+
const DEFAULT_GITIGNORE = ".gitignore";
|
|
9
|
+
const DEFAULT_EXCLUDES = [".git", "build"];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolves the package name from package.json in the target directory.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} cwd - The project root directory.
|
|
15
|
+
* @returns {string} Sanitized package name or fallback "app".
|
|
16
|
+
*/
|
|
17
|
+
function getPackageName(cwd) {
|
|
18
|
+
const packageJsonPath = path.resolve(cwd, "package.json");
|
|
19
|
+
if (existsSync(packageJsonPath)) {
|
|
20
|
+
try {
|
|
21
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
22
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof
|
|
23
|
+
if (typeof pkg.name === "string" && pkg.name.trim()) {
|
|
24
|
+
return pkg.name.trim().replace(/^@/u, "").replaceAll("/", "-");
|
|
25
|
+
}
|
|
26
|
+
} catch {
|
|
27
|
+
// Ignore parse errors and use fallback
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return "app";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Packages the current application directory into a timestamped tar.gz archive:
|
|
35
|
+
* `<package-name>-<timestamp>.tar.gz`
|
|
36
|
+
* Cleans and recreates the output directory before packaging.
|
|
37
|
+
*
|
|
38
|
+
* @param {Object} [options] - Configuration options for packaging.
|
|
39
|
+
* @param {string} [options.cwd] - The project root directory. Defaults to `process.cwd()`.
|
|
40
|
+
* @param {string} [options.outputDirectory] - Output directory relative to `cwd`. Defaults to `"build"`.
|
|
41
|
+
* @param {string} [options.packageName] - Custom package name override. Defaults to name from `package.json`.
|
|
42
|
+
* @param {number} [options.timestamp] - Custom timestamp for the archive filename. Defaults to `Date.now()`.
|
|
43
|
+
* @param {string[]} [options.excludes] - Patterns to exclude from the archive.
|
|
44
|
+
* @param {string} [options.gitignorePath] - Gitignore file path relative to `cwd`. Defaults to `".gitignore"`.
|
|
45
|
+
* @returns {{ archiveName: string, relativePath: string, absolutePath: string, packageName: string }} Details of the generated archive.
|
|
46
|
+
*/
|
|
47
|
+
export function packageApp(options = {}) {
|
|
48
|
+
const cwd = options.cwd ?? process.cwd();
|
|
49
|
+
const outputDirectory = options.outputDirectory ?? DEFAULT_OUTPUT_DIR;
|
|
50
|
+
const targetDir = path.resolve(cwd, outputDirectory);
|
|
51
|
+
|
|
52
|
+
// Clean and recreate the output directory
|
|
53
|
+
if (existsSync(targetDir)) {
|
|
54
|
+
rmSync(targetDir, { recursive: true, force: true });
|
|
55
|
+
}
|
|
56
|
+
mkdirSync(targetDir, { recursive: true });
|
|
57
|
+
|
|
58
|
+
const packageName = options.packageName ?? getPackageName(cwd);
|
|
59
|
+
const timestamp = options.timestamp ?? Date.now();
|
|
60
|
+
const archiveName = `${timestamp}.tar.gz`;
|
|
61
|
+
const relativePath = path.posix.join(outputDirectory, archiveName);
|
|
62
|
+
const absolutePath = path.resolve(cwd, relativePath);
|
|
63
|
+
|
|
64
|
+
const gitignoreFile = options.gitignorePath ?? DEFAULT_GITIGNORE;
|
|
65
|
+
const excludes = options.excludes ?? DEFAULT_EXCLUDES;
|
|
66
|
+
|
|
67
|
+
const tarArgs = ["-czf", relativePath];
|
|
68
|
+
|
|
69
|
+
const fullGitignorePath = path.resolve(cwd, gitignoreFile);
|
|
70
|
+
if (existsSync(fullGitignorePath)) {
|
|
71
|
+
tarArgs.push(`--exclude-from=${gitignoreFile}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for (const exclude of excludes) {
|
|
75
|
+
tarArgs.push(`--exclude=${exclude}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
tarArgs.push(".");
|
|
79
|
+
|
|
80
|
+
const result = spawnSync("tar", tarArgs, {
|
|
81
|
+
cwd,
|
|
82
|
+
stdio: "inherit",
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (result.error) {
|
|
86
|
+
throw result.error;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (result.status !== 0) {
|
|
90
|
+
throw new Error(`tar process exited with status ${result.status}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
archiveName,
|
|
95
|
+
relativePath,
|
|
96
|
+
absolutePath,
|
|
97
|
+
packageName,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const [, entryPath] = process.argv;
|
|
102
|
+
if (
|
|
103
|
+
entryPath &&
|
|
104
|
+
import.meta.url === pathToFileURL(path.resolve(entryPath)).href
|
|
105
|
+
) {
|
|
106
|
+
try {
|
|
107
|
+
const result = packageApp();
|
|
108
|
+
console.log(`Successfully packaged application to ${result.relativePath}`);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error(
|
|
111
|
+
"Failed to package application:",
|
|
112
|
+
error instanceof Error ? error.message : error
|
|
113
|
+
);
|
|
114
|
+
process.exitCode = 1;
|
|
115
|
+
}
|
|
116
|
+
}
|