create-loom 0.0.1
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/LICENSE +21 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +87 -0
- package/package.json +27 -0
- package/template/copy-non-typescript-files +16 -0
- package/template/src/index.ts +9 -0
- package/template/src/public/style.css +6 -0
- package/template/src/public/{error}.tsx +12 -0
- package/template/src/public/{page}.tsx +12 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Matt Kantor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as JSONC from 'comment-json';
|
|
3
|
+
import nodeChildProcess from 'node:child_process';
|
|
4
|
+
import { cp, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
5
|
+
import * as nodePath from 'node:path';
|
|
6
|
+
import { parseArgs } from 'node:util';
|
|
7
|
+
const templateDirectory = `${import.meta.dirname}/../template`;
|
|
8
|
+
// This is overkill for now, but reserves space for future options (because
|
|
9
|
+
// `create-loom --foo` is an error).
|
|
10
|
+
const { positionals: cliArgs } = parseArgs({
|
|
11
|
+
args: process.argv.slice(2), // remove `execPath` and `filename`
|
|
12
|
+
strict: true,
|
|
13
|
+
allowPositionals: true,
|
|
14
|
+
});
|
|
15
|
+
if (cliArgs[0] === undefined) {
|
|
16
|
+
throw new Error('Missing required path argument');
|
|
17
|
+
}
|
|
18
|
+
const path = nodePath.resolve(process.cwd(), cliArgs[0]);
|
|
19
|
+
/**
|
|
20
|
+
* Create and move to the project directory.
|
|
21
|
+
*/
|
|
22
|
+
await mkdir(path, { recursive: true });
|
|
23
|
+
process.chdir(path);
|
|
24
|
+
/**
|
|
25
|
+
* Create `package.json`.
|
|
26
|
+
*/
|
|
27
|
+
nodeChildProcess.execSync('npm init --yes');
|
|
28
|
+
/**
|
|
29
|
+
* Add dependencies.
|
|
30
|
+
*/
|
|
31
|
+
nodeChildProcess.execSync('npm install --save-dev typescript @types/node');
|
|
32
|
+
nodeChildProcess.execSync('npm install @superhighway/silk @superhighway/loom');
|
|
33
|
+
/**
|
|
34
|
+
* Copy `src`, `.gitignore`, etc to the project from the template directory.
|
|
35
|
+
*/
|
|
36
|
+
await cp(templateDirectory, path, { recursive: true });
|
|
37
|
+
/**
|
|
38
|
+
* Create `tsconfig.json`.
|
|
39
|
+
*/
|
|
40
|
+
nodeChildProcess.execSync('tsc --init');
|
|
41
|
+
const tsConfigSource = (await readFile(`${path}/tsconfig.json`, {
|
|
42
|
+
encoding: 'utf-8',
|
|
43
|
+
}))
|
|
44
|
+
// Clean up some comments that will be irrelevant after config manipulation:
|
|
45
|
+
.replace('// "outDir": "./dist",\n', '')
|
|
46
|
+
.replace(/\/\/ For nodejs:\n\s*\/\/ "lib": \["esnext"\],\n\s*\/\/ "types": \["node"\],\n\s*\/\/ and npm install -D @types\/node\n/, '');
|
|
47
|
+
const tsConfig = JSONC.parse(tsConfigSource);
|
|
48
|
+
if (typeof tsConfig !== 'object' ||
|
|
49
|
+
tsConfig === null ||
|
|
50
|
+
!('compilerOptions' in tsConfig)) {
|
|
51
|
+
throw new Error('TypeScript config was not an object with a `compilerOptions` property');
|
|
52
|
+
}
|
|
53
|
+
const compilerOptions = tsConfig['compilerOptions'];
|
|
54
|
+
if (typeof compilerOptions !== 'object' || compilerOptions === null) {
|
|
55
|
+
throw new Error('TypeScript config `compilerOptions` was not an object');
|
|
56
|
+
}
|
|
57
|
+
// Note this is still a reference to the property of `tsConfig`.
|
|
58
|
+
const assignableCompilerOptions = compilerOptions;
|
|
59
|
+
// `tsc --init` includes `jsx`, but it's nice to keep all `jsx*` properties
|
|
60
|
+
// adjacent, so delete and create a new property of the same name rather than
|
|
61
|
+
// updating the extant one.
|
|
62
|
+
delete assignableCompilerOptions.jsx;
|
|
63
|
+
assignableCompilerOptions.jsx = 'react';
|
|
64
|
+
assignableCompilerOptions.jsxFactory = 'createElement';
|
|
65
|
+
assignableCompilerOptions.jsxFragmentFactory = 'createElement';
|
|
66
|
+
assignableCompilerOptions.types = ['node'];
|
|
67
|
+
assignableCompilerOptions.outDir = 'dist';
|
|
68
|
+
const updatedTSConfigSource = JSONC.stringify(tsConfig, null, 2);
|
|
69
|
+
await writeFile(`${path}/tsconfig.json`, updatedTSConfigSource);
|
|
70
|
+
/**
|
|
71
|
+
* Edit `package.json` to add scripts and other necessary properties.
|
|
72
|
+
*/
|
|
73
|
+
const scripts = {
|
|
74
|
+
build: 'npm run compile; npm run copy-non-typescript-files',
|
|
75
|
+
clean: 'rm -rf dist* *.tsbuildinfo',
|
|
76
|
+
compile: 'tsc --build',
|
|
77
|
+
'copy-non-typescript-files': './copy-non-typescript-files',
|
|
78
|
+
start: 'npm run clean && npm run build; node .',
|
|
79
|
+
};
|
|
80
|
+
const packageManifestPath = `${path}/package.json`;
|
|
81
|
+
const packageManifest = (await import(packageManifestPath, {
|
|
82
|
+
with: { type: 'json' },
|
|
83
|
+
})).default;
|
|
84
|
+
packageManifest.scripts = scripts;
|
|
85
|
+
packageManifest.main = 'dist/index.js';
|
|
86
|
+
packageManifest.type = 'module';
|
|
87
|
+
await writeFile(packageManifestPath, `${JSON.stringify(packageManifest, null, 2)}\n`);
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-loom",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"bin": "dist/index.js",
|
|
5
|
+
"devDependencies": {
|
|
6
|
+
"@types/node": "^24.8.1",
|
|
7
|
+
"typescript": "^5.9.3"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/*",
|
|
11
|
+
"template/*"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"repository": "github:mkantor/create-loom",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc --build tsconfig.main.json",
|
|
18
|
+
"build:tests": "tsc --project tsconfig.main.json --outDir dist-test --declarationDir dist && tsc --build tsconfig.test.json",
|
|
19
|
+
"clean": "rm -rf dist* *.tsbuildinfo",
|
|
20
|
+
"start": "npm run clean && npm run build && node .",
|
|
21
|
+
"test": "npm run build:tests && cd dist-test && node --test"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"comment-json": "^4.4.1"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
root_dir="src"
|
|
4
|
+
out_dir="dist"
|
|
5
|
+
|
|
6
|
+
find "$root_dir" \
|
|
7
|
+
\( -type f -or -type l \) \
|
|
8
|
+
-and \
|
|
9
|
+
\( -not -name '*.tsx' -and -not -name '*.ts' \) \
|
|
10
|
+
-exec sh \
|
|
11
|
+
-c '
|
|
12
|
+
mkdir -p "$(
|
|
13
|
+
dirname "'$out_dir'/$(echo $1 | sed -e s#^'$root_dir'/##)"
|
|
14
|
+
)"
|
|
15
|
+
cp -R $1 "'$out_dir'/$(echo $1 | sed -e s#^'$root_dir'/##)"
|
|
16
|
+
' shell {} \;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { page } from '@superhighway/loom'
|
|
2
|
+
import { createElement } from '@superhighway/silk'
|
|
3
|
+
|
|
4
|
+
export default page((request, { status }) => (
|
|
5
|
+
<html lang="en">
|
|
6
|
+
<head>
|
|
7
|
+
<title>Error</title>
|
|
8
|
+
<link rel="stylesheet" href="style.css" />
|
|
9
|
+
</head>
|
|
10
|
+
<body>Something went wrong.</body>
|
|
11
|
+
</html>
|
|
12
|
+
))
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { page } from '@superhighway/loom'
|
|
2
|
+
import { createElement } from '@superhighway/silk'
|
|
3
|
+
|
|
4
|
+
export default page(request => (
|
|
5
|
+
<html lang="en">
|
|
6
|
+
<head>
|
|
7
|
+
<title>Greeting</title>
|
|
8
|
+
<link rel="stylesheet" href="style.css" />
|
|
9
|
+
</head>
|
|
10
|
+
<body>Hello, world!</body>
|
|
11
|
+
</html>
|
|
12
|
+
))
|