create-ncblock 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/package.json +1 -1
- package/scripts/init.ts +21 -1
- package/scripts/utils/templates.ts +14 -9
package/package.json
CHANGED
package/scripts/init.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execSync } from "child_process"
|
|
2
|
+
import { existsSync, readdirSync } from "fs"
|
|
2
3
|
import { basename, dirname, resolve } from "path"
|
|
3
4
|
import {
|
|
4
5
|
clearScreenDown,
|
|
@@ -53,6 +54,8 @@ function parseArgs(argv: string[]) {
|
|
|
53
54
|
args.install = true
|
|
54
55
|
} else if (arg === "--no-install") {
|
|
55
56
|
args.install = false
|
|
57
|
+
} else if (arg === "--force") {
|
|
58
|
+
args.force = true
|
|
56
59
|
} else if (!arg.startsWith("-")) {
|
|
57
60
|
positional.push(arg)
|
|
58
61
|
}
|
|
@@ -456,6 +459,23 @@ async function main() {
|
|
|
456
459
|
const dest = resolve(dir)
|
|
457
460
|
const templateDir = resolve(templateBaseDir, selectedTemplate.name)
|
|
458
461
|
|
|
462
|
+
const destNonEmpty = existsSync(dest) && readdirSync(dest).length > 0
|
|
463
|
+
if (destNonEmpty) {
|
|
464
|
+
console.log(
|
|
465
|
+
`\n ${c.yellow}⚠ Directory "${dir}" is not empty. Files may be overwritten.${c.reset}`,
|
|
466
|
+
)
|
|
467
|
+
const proceed = await confirm(
|
|
468
|
+
"Continue?",
|
|
469
|
+
args.force as boolean | undefined,
|
|
470
|
+
false,
|
|
471
|
+
)
|
|
472
|
+
if (!proceed) {
|
|
473
|
+
console.log("")
|
|
474
|
+
closePromptInterface()
|
|
475
|
+
process.exit(1)
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
459
479
|
step(
|
|
460
480
|
`Using template ${c.bold}${selectedTemplate.name}${c.reset} ${c.dim}(${selectedTemplate.title})${c.reset}`,
|
|
461
481
|
)
|
|
@@ -478,7 +498,7 @@ async function main() {
|
|
|
478
498
|
installDeps,
|
|
479
499
|
})
|
|
480
500
|
|
|
481
|
-
scaffoldTemplate({ root, templateDir, dest, name })
|
|
501
|
+
scaffoldTemplate({ root, templateDir, dest, name, overwrite: destNonEmpty })
|
|
482
502
|
|
|
483
503
|
step(`Scaffolded project in ${c.bold}${dest}${c.reset}`)
|
|
484
504
|
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from "fs"
|
|
13
13
|
import { tmpdir } from "os"
|
|
14
14
|
import { resolve } from "path"
|
|
15
|
+
import { cleanDist, stagePublishDir } from "./compile-sdk"
|
|
15
16
|
|
|
16
17
|
type StoredTemplateMetadata = {
|
|
17
18
|
title?: string
|
|
@@ -145,15 +146,19 @@ function readSdkVersion(root: string): string {
|
|
|
145
146
|
|
|
146
147
|
function packLocalSdk(root: string, dest: string): string {
|
|
147
148
|
const sdkDir = resolve(root, "sdk")
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
149
|
+
const publishDir = stagePublishDir(sdkDir)
|
|
150
|
+
try {
|
|
151
|
+
const tgzOutput = execSync("npm pack --pack-destination .", {
|
|
152
|
+
cwd: publishDir,
|
|
153
|
+
encoding: "utf-8",
|
|
154
|
+
}).trim()
|
|
155
|
+
const tgz = tgzOutput.split(/\r?\n/).at(-1) ?? tgzOutput
|
|
156
|
+
copyFileSync(resolve(publishDir, tgz), resolve(dest, tgz))
|
|
157
|
+
return `file:./${tgz}`
|
|
158
|
+
} finally {
|
|
159
|
+
rmSync(publishDir, { recursive: true, force: true })
|
|
160
|
+
cleanDist(sdkDir)
|
|
161
|
+
}
|
|
157
162
|
}
|
|
158
163
|
|
|
159
164
|
function copyDirectoryContents(
|