create-three-blocks-starter 0.0.2 → 0.0.4
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/bin/index.js +26 -8
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Node 18+
|
|
3
3
|
// Usage:
|
|
4
|
-
//
|
|
4
|
+
// THREE_BLOCKS_SECRET_KEY=sk_live_... npx create-three-blocks-starter my-app
|
|
5
5
|
// npx create-three-blocks-starter my-app (will prompt for key)
|
|
6
6
|
|
|
7
7
|
import fs from 'node:fs';
|
|
@@ -103,7 +103,7 @@ async function main() {
|
|
|
103
103
|
if (!appName) {
|
|
104
104
|
die(
|
|
105
105
|
`Usage:\n` +
|
|
106
|
-
`
|
|
106
|
+
` THREE_BLOCKS_SECRET_KEY=sk_live_... npx three-blocks-create-app <directory>\n` +
|
|
107
107
|
` (or: npx three-blocks-create-app <directory> and enter the key when prompted)`
|
|
108
108
|
);
|
|
109
109
|
}
|
|
@@ -112,9 +112,9 @@ async function main() {
|
|
|
112
112
|
await ensureEmptyDir(targetDir);
|
|
113
113
|
|
|
114
114
|
// 1) License key (env or prompt)
|
|
115
|
-
let license = process.env.
|
|
115
|
+
let license = process.env.THREE_BLOCKS_SECRET_KEY;
|
|
116
116
|
if (license) {
|
|
117
|
-
console.log(`${gray('›')} Using ${bold('
|
|
117
|
+
console.log(`${gray('›')} Using ${bold('THREE_BLOCKS_SECRET_KEY')} from environment ${dim(`(${mask(license)})`)}`);
|
|
118
118
|
} else {
|
|
119
119
|
console.log('');
|
|
120
120
|
console.log(bold(cyan('Three Blocks Starter')) + ' ' + dim(`[channel: ${channel}]`));
|
|
@@ -130,7 +130,7 @@ async function main() {
|
|
|
130
130
|
console.log(`> Fetching short-lived token (temp .npmrc) [channel: ${channel}] ...`);
|
|
131
131
|
run('npx', ['-y', LOGIN_CLI, '--mode', 'project', '--scope', SCOPE, '--channel', channel], {
|
|
132
132
|
cwd: tmp,
|
|
133
|
-
env: { ...process.env,
|
|
133
|
+
env: { ...process.env, THREE_BLOCKS_SECRET_KEY: license, THREE_BLOCKS_CHANNEL: channel },
|
|
134
134
|
});
|
|
135
135
|
if (!fs.existsSync(tmpNpmrc)) die('Login failed: temp .npmrc not created.');
|
|
136
136
|
// Extract registry URL from temp .npmrc so we can pass it explicitly to npm create
|
|
@@ -146,7 +146,7 @@ async function main() {
|
|
|
146
146
|
console.log(`> Fetching starter tarball ${starterSpec} ...`);
|
|
147
147
|
const createEnv = {
|
|
148
148
|
...process.env,
|
|
149
|
-
|
|
149
|
+
THREE_BLOCKS_SECRET_KEY: license,
|
|
150
150
|
NPM_CONFIG_USERCONFIG: tmpNpmrc,
|
|
151
151
|
npm_config_userconfig: tmpNpmrc,
|
|
152
152
|
};
|
|
@@ -167,7 +167,7 @@ async function main() {
|
|
|
167
167
|
|
|
168
168
|
// 4) Write .env.local and .gitignore entries
|
|
169
169
|
await fsp.writeFile(path.join(targetDir, '.env.local'),
|
|
170
|
-
`
|
|
170
|
+
`THREE_BLOCKS_SECRET_KEY=${license}\nTHREE_BLOCKS_CHANNEL=${channel}\n`, { mode: 0o600 }).catch(() => {});
|
|
171
171
|
const giPath = path.join(targetDir, '.gitignore');
|
|
172
172
|
let gi = '';
|
|
173
173
|
try { gi = await fsp.readFile(giPath, 'utf8'); } catch {}
|
|
@@ -199,11 +199,29 @@ async function main() {
|
|
|
199
199
|
cwd: targetDir,
|
|
200
200
|
env: {
|
|
201
201
|
...process.env,
|
|
202
|
-
|
|
202
|
+
THREE_BLOCKS_SECRET_KEY: license,
|
|
203
203
|
THREE_BLOCKS_CHANNEL: channel,
|
|
204
204
|
},
|
|
205
205
|
});
|
|
206
206
|
|
|
207
|
+
{
|
|
208
|
+
const coreSpec = `@three-blocks/core@${channel === 'stable' ? 'latest' : channel}`;
|
|
209
|
+
console.log(`> Installing ${coreSpec} ...`);
|
|
210
|
+
const addArgs = hasPnpm ? ['add', '--save-exact', coreSpec] : ['install', '--save-exact', coreSpec];
|
|
211
|
+
const r = spawnSync(hasPnpm ? 'pnpm' : 'npm', addArgs, {
|
|
212
|
+
stdio: 'inherit',
|
|
213
|
+
cwd: targetDir,
|
|
214
|
+
env: {
|
|
215
|
+
...process.env,
|
|
216
|
+
THREE_BLOCKS_SECRET_KEY: license,
|
|
217
|
+
THREE_BLOCKS_CHANNEL: channel,
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
if (r.status !== 0) {
|
|
221
|
+
console.log(`${yellow('⚠')} Warning: could not install @three-blocks/core (exit ${r.status}).`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
207
225
|
// 6) Cleanup temp dir
|
|
208
226
|
try { fs.rmSync(tmp, { recursive: true, force: true }); } catch {}
|
|
209
227
|
|