create-pik 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +9 -2
- package/index.js +80 -0
- package/package.json +31 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Opik
|
|
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/README.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# create-pik
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Create a project from an [agent-ready starter template](https://github.com/opikdev/starters):
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm create pik@latest
|
|
7
|
+
npm create pik@latest -- api-hono-starter my-api --yes
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
It downloads the matching [`pik`](https://github.com/opikdev/starters/tree/main/packages/cli) release, verifies its SHA-256 checksum, caches it, and runs `pik new` with your arguments. You need Node 20 or later and `tar`.
|
package/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
|
|
8
|
+
const { version } = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
|
|
9
|
+
const releases = process.env.PIK_DOWNLOAD_URL ?? 'https://github.com/opikdev/starters/releases';
|
|
10
|
+
const timeoutMs = 60_000;
|
|
11
|
+
|
|
12
|
+
const platforms = { darwin: 'darwin', linux: 'linux', win32: 'windows' };
|
|
13
|
+
const architectures = { x64: 'amd64', arm64: 'arm64' };
|
|
14
|
+
|
|
15
|
+
function fail(message) {
|
|
16
|
+
console.error(`create-pik: ${message}`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function download(url) {
|
|
21
|
+
let response;
|
|
22
|
+
try {
|
|
23
|
+
response = await fetch(url, { signal: AbortSignal.timeout(timeoutMs) });
|
|
24
|
+
} catch (error) {
|
|
25
|
+
fail(`couldn't download ${url}: ${error.message}`);
|
|
26
|
+
}
|
|
27
|
+
if (!response.ok) fail(`couldn't download ${url}: HTTP ${response.status}`);
|
|
28
|
+
return Buffer.from(await response.arrayBuffer());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function install(os, arch, binaryPath) {
|
|
32
|
+
const archive = `pik_${version}_${os}_${arch}.${os === 'windows' ? 'zip' : 'tar.gz'}`;
|
|
33
|
+
const base = `${releases}/download/v${version}`;
|
|
34
|
+
const [data, checksums] = await Promise.all([download(`${base}/${archive}`), download(`${base}/checksums.txt`)]);
|
|
35
|
+
|
|
36
|
+
const expected = checksums
|
|
37
|
+
.toString('utf8')
|
|
38
|
+
.split('\n')
|
|
39
|
+
.map((line) => line.trim().split(/\s+/))
|
|
40
|
+
.find(([, file]) => file === archive)?.[0];
|
|
41
|
+
if (!expected) fail(`checksums.txt has no entry for ${archive}`);
|
|
42
|
+
const actual = createHash('sha256').update(data).digest('hex');
|
|
43
|
+
if (actual !== expected) fail(`the checksum of ${archive} doesn't match, so pik wasn't run`);
|
|
44
|
+
|
|
45
|
+
const cacheDir = join(binaryPath, '..');
|
|
46
|
+
mkdirSync(cacheDir, { recursive: true });
|
|
47
|
+
const staging = mkdtempSync(join(cacheDir, '.download-'));
|
|
48
|
+
try {
|
|
49
|
+
writeFileSync(join(staging, archive), data);
|
|
50
|
+
const binary = os === 'windows' ? 'pik.exe' : 'pik';
|
|
51
|
+
const extract = spawnSync('tar', ['-xf', archive, binary], { cwd: staging, stdio: 'inherit' });
|
|
52
|
+
if (extract.status !== 0) fail(`couldn't extract ${archive}. Make sure tar is installed`);
|
|
53
|
+
chmodSync(join(staging, binary), 0o755);
|
|
54
|
+
renameSync(join(staging, binary), binaryPath);
|
|
55
|
+
} finally {
|
|
56
|
+
rmSync(staging, { recursive: true, force: true });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function main() {
|
|
61
|
+
const args = process.argv.slice(2);
|
|
62
|
+
if (args[0] === '--version') {
|
|
63
|
+
console.log(version);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const os = platforms[process.platform];
|
|
68
|
+
const arch = architectures[process.arch];
|
|
69
|
+
if (!os || !arch) fail(`${process.platform}/${process.arch} isn't supported`);
|
|
70
|
+
|
|
71
|
+
const cacheRoot = process.env.XDG_CACHE_HOME ?? join(homedir(), '.cache');
|
|
72
|
+
const binaryPath = join(cacheRoot, 'pik', version, os === 'windows' ? 'pik.exe' : 'pik');
|
|
73
|
+
if (!existsSync(binaryPath)) await install(os, arch, binaryPath);
|
|
74
|
+
|
|
75
|
+
const result = spawnSync(binaryPath, ['new', ...args], { stdio: 'inherit' });
|
|
76
|
+
if (result.error) fail(`couldn't run pik: ${result.error.message}`);
|
|
77
|
+
process.exit(result.status ?? 1);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
await main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pik",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Create a project from an agent-ready starter template with pik",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"create-pik": "index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"index.js",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=20"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/opikdev/starters.git",
|
|
20
|
+
"directory": "packages/create-pik"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/opikdev/starters",
|
|
23
|
+
"keywords": [
|
|
24
|
+
"create",
|
|
25
|
+
"starter",
|
|
26
|
+
"template",
|
|
27
|
+
"scaffold",
|
|
28
|
+
"agents"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "node --test"
|
|
32
|
+
}
|
|
33
|
+
}
|