@solid-cli/commands
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "@solid-cli/commands", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "The main command handlers for the Solid CLI", | ||
@@ -19,2 +19,7 @@ "license": "MIT", | ||
"types": "./types/index.d.ts" | ||
}, | ||
"./new": { | ||
"import": "./dist/handlers/new.mjs", | ||
"require": "./dist/handlers/new.mjs", | ||
"types": "./types/handlers/new.d.ts" | ||
} | ||
@@ -25,2 +30,3 @@ }, | ||
"@types/node": "^20.5.0", | ||
"prettier": "^3.0.2", | ||
"tsup": "^7.2.0", | ||
@@ -33,10 +39,10 @@ "typescript": "^5.1.6" | ||
"dependencies": { | ||
"@chialab/esbuild-plugin-meta-url": "^0.17.7", | ||
"@clack/prompts": "0.6.3", | ||
"detect-package-manager": "^2.0.1", | ||
"execa": "^7.2.0", | ||
"execa": "^8.0.1", | ||
"picocolors": "^1.0.0", | ||
"@solid-cli/reactivity": "0.0.8", | ||
"@solid-cli/ui": "0.0.5", | ||
"@solid-cli/utils": "0.0.5" | ||
"sucrase": "^3.34.0", | ||
"@solid-cli/reactivity": "0.0.10", | ||
"@solid-cli/utils": "0.0.6", | ||
"@solid-cli/ui": "0.0.6" | ||
}, | ||
@@ -43,0 +49,0 @@ "scripts": { |
@@ -7,5 +7,40 @@ import * as p from "@clack/prompts"; | ||
import { t } from "@solid-cli/utils"; | ||
import { insertAtEnd } from "@solid-cli/utils/fs"; | ||
import { insertAtEnd, readFileToString } from "@solid-cli/utils/fs"; | ||
import { flushQueue } from "@solid-cli/utils/updates"; | ||
import { getRunner } from "@solid-cli/utils/paths"; | ||
import { rm } from "fs/promises"; | ||
import { basename, join, resolve } from "path"; | ||
import { Dirent, copyFileSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "fs"; | ||
// import prettier from "prettier"; | ||
import { transform } from "sucrase"; | ||
const gitIgnore = ` | ||
dist | ||
.solid | ||
.output | ||
.vercel | ||
.netlify | ||
netlify | ||
# Environment | ||
.env | ||
.env*.local | ||
# dependencies | ||
/node_modules | ||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
*.launch | ||
.settings/ | ||
# Temp | ||
gitignore | ||
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
`; | ||
const startSupported = [ | ||
@@ -37,2 +72,84 @@ "bare", | ||
}; | ||
const recurseFiles = (startPath: string, cb: (file: Dirent, startPath: string) => void) => { | ||
startPath = resolve(startPath); | ||
const files = readdirSync(startPath, { withFileTypes: true }); | ||
for (const file of files) { | ||
cb(file, startPath); | ||
} | ||
}; | ||
const convertToJS = async (file: Dirent, startPath: string) => { | ||
const src = join(startPath, file.name); | ||
const dest = resolve(startPath.replace(".solid-start", ""), file.name); | ||
if (file.isDirectory()) { | ||
mkdirSync(dest, { recursive: true }); | ||
recurseFiles(resolve(startPath, file.name), convertToJS); | ||
} else if (file.isFile()) { | ||
if (src.endsWith(".ts") || src.endsWith(".tsx")) { | ||
let { code } = transform(await readFileToString(src), { | ||
transforms: ["typescript", "jsx"], | ||
jsxRuntime: "preserve", | ||
}); | ||
// code = await prettier.format(code, { | ||
// parser: "babel", | ||
// }); | ||
writeFileSync(dest.replace(".ts", ".js"), code, { flag: "wx" }); | ||
} else { | ||
copyFileSync(src, dest); | ||
} | ||
} | ||
}; | ||
const handleTSConversion = async (tempDir: string, projectName: string) => { | ||
await rm(resolve(tempDir, "tsconfig.json")); | ||
writeFileSync( | ||
resolve(projectName, "jsconfig.json"), | ||
JSON.stringify( | ||
{ | ||
compilerOptions: { | ||
jsx: "preserve", | ||
jsxImportSource: "solid-js", | ||
paths: { | ||
"~/*": ["./src/*"], | ||
}, | ||
}, | ||
}, | ||
null, | ||
2, | ||
), | ||
{ flag: "wx" }, | ||
); | ||
// Convert all ts files in temp directory into js | ||
recurseFiles(tempDir, convertToJS); | ||
// Update package.json to remove type deps | ||
const name = basename(resolve(projectName)); | ||
const pkg_file = join(projectName, "package.json"); | ||
const pkg_json = JSON.parse( | ||
readFileSync(pkg_file, "utf-8") | ||
.replace(/"name": ".+"/, (_m) => `"name": "${name}"`) | ||
.replace(/"(.+)": "workspace:.+"/g, (_m, name) => `"${name}": "next"`), | ||
); | ||
delete pkg_json.dependencies["@types/cookie"]; | ||
delete pkg_json.dependencies["@types/debug"]; | ||
delete pkg_json.devDependencies["@types/babel__core"]; | ||
delete pkg_json.devDependencies["@types/node"]; | ||
delete pkg_json.devDependencies["typescript"]; | ||
delete pkg_json.devDependencies["@types/wait-on"]; | ||
writeFileSync(pkg_file, JSON.stringify(pkg_json, null, 2)); | ||
// Remove temp directory | ||
await rm(join(process.cwd(), tempDir), { | ||
recursive: true, | ||
force: true, | ||
}); | ||
}; | ||
const handleNewStartProject = async (projectName: string) => { | ||
@@ -47,2 +164,7 @@ const template = await cancelable( | ||
const withTs = await cancelable(p.confirm({ message: "Use Typescript?" })); | ||
// If the user does not want ts, we create the project in a temp directory inside the project directory | ||
const tempDir = withTs ? projectName : join(projectName, ".solid-start"); | ||
const pM = await detect(); | ||
@@ -55,6 +177,13 @@ await spinnerify({ | ||
getRunner(pM), | ||
["degit", `solidjs/solid-start/examples/${template}#main`, projectName].filter((e) => e !== null) as string[], | ||
["degit", `solidjs/solid-start/examples/${template}#main`, tempDir].filter((e) => e !== null) as string[], | ||
), | ||
}); | ||
if (!withTs) await handleTSConversion(tempDir, projectName); | ||
// Add .gitignore | ||
writeFileSync(join(projectName, ".gitignore"), gitIgnore); | ||
await modifyReadme(projectName); | ||
p.log.info(`${t.GET_STARTED} | ||
@@ -88,3 +217,7 @@ - cd ${projectName} | ||
}; | ||
export const handleNew = async (variation?: AllSupported, name?: string, stackblitz: boolean = false) => { | ||
export const handleNew = async ( | ||
variation?: AllSupported, | ||
name: string = "solid-project", | ||
stackblitz: boolean = false, | ||
) => { | ||
if (!variation) { | ||
@@ -104,2 +237,7 @@ await handleAutocompleteNew(); | ||
const withTs = await cancelable(p.confirm({ message: "Use Typescript?" })); | ||
// If the user does not want ts, we create the project in a temp directory inside the project directory | ||
const tempDir = withTs ? name : join(name, ".solid-start"); | ||
const pM = await detect(); | ||
@@ -116,2 +254,8 @@ | ||
}); | ||
if (!withTs) await handleTSConversion(tempDir, name); | ||
// Add .gitignore | ||
writeFileSync(join(name, ".gitignore"), gitIgnore); | ||
await modifyReadme(name ?? variation); | ||
@@ -118,0 +262,0 @@ p.log.info(`${t.GET_STARTED} |
@@ -56,5 +56,5 @@ import { existsSync, lstatSync, readdirSync } from "fs"; | ||
lookingFor: string | string[], | ||
opts: { depth?: number; ignoreDirs: string[] }, | ||
opts: { depth?: number; ignoreDirs?: string[]; startsWith?: boolean }, | ||
): Promise<string[]> { | ||
let { depth = Infinity, ignoreDirs = ["node_modules", "."] } = opts; | ||
let { depth = Infinity, ignoreDirs = ["node_modules", "."], startsWith = true } = opts; | ||
@@ -82,4 +82,6 @@ startPath = resolve(startPath); | ||
const fileMatch = Array.isArray(lookingFor) | ||
? lookingFor.some((s) => file.name.startsWith(s)) | ||
: file.name.startsWith(lookingFor); | ||
? lookingFor.some((s) => (startsWith ? file.name.startsWith(s) : file.name.endsWith(s))) | ||
: startsWith | ||
? file.name.startsWith(lookingFor) | ||
: file.name.endsWith(lookingFor); | ||
@@ -86,0 +88,0 @@ if (fileMatch) { |
@@ -5,3 +5,3 @@ import { defineConfig } from "tsup"; | ||
export default defineConfig({ | ||
entry: ["src/index.ts"], | ||
entry: ["src/index.ts", "src/handlers/new.ts"], | ||
target: "esnext", | ||
@@ -12,3 +12,4 @@ format: "esm", | ||
clean: true, | ||
minify: true, | ||
esbuildPlugins: [metaUrlPlugin()], | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
113159
24
5
1065
5
+ Addedsucrase@^3.34.0
+ Added@isaacs/cliui@8.0.2(transitive)
+ Added@jridgewell/gen-mapping@0.3.5(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Added@pkgjs/parseargs@0.11.0(transitive)
+ Added@solid-cli/reactivity@0.0.10(transitive)
+ Added@solid-cli/ui@0.0.6(transitive)
+ Added@solid-cli/utils@0.0.6(transitive)
+ Addedansi-regex@6.1.0(transitive)
+ Addedansi-styles@6.2.1(transitive)
+ Addedany-promise@1.3.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedcommander@4.1.1(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@8.0.09.2.2(transitive)
+ Addedexeca@8.0.1(transitive)
+ Addedforeground-child@3.3.0(transitive)
+ Addedget-stream@8.0.1(transitive)
+ Addedglob@10.4.5(transitive)
+ Addedhuman-signals@5.0.0(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedjackspeak@3.4.3(transitive)
+ Addedlines-and-columns@1.2.4(transitive)
+ Addedlru-cache@10.4.3(transitive)
+ Addedminimatch@9.0.5(transitive)
+ Addedminipass@7.1.2(transitive)
+ Addedmz@2.7.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedpackage-json-from-dist@1.0.1(transitive)
+ Addedpath-scurry@1.11.1(transitive)
+ Addedpirates@4.0.6(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstring-width@4.2.35.1.2(transitive)
+ Addedstrip-ansi@7.1.0(transitive)
+ Addedsucrase@3.35.0(transitive)
+ Addedthenify@3.3.1(transitive)
+ Addedthenify-all@1.6.0(transitive)
+ Addedts-interface-checker@0.1.13(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)
- Removed@chialab/esbuild-plugin-meta-url@0.17.7(transitive)
- Removed@chialab/esbuild-rna@0.17.8(transitive)
- Removed@chialab/estransform@0.17.5(transitive)
- Removed@chialab/node-resolve@0.17.1(transitive)
- Removed@parcel/source-map@2.1.1(transitive)
- Removed@solid-cli/reactivity@0.0.8(transitive)
- Removed@solid-cli/ui@0.0.5(transitive)
- Removed@solid-cli/utils@0.0.5(transitive)
- Removeddetect-libc@1.0.3(transitive)
- Removedexeca@7.2.0(transitive)
- Removedhuman-signals@4.3.1(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
Updated@solid-cli/reactivity@0.0.10
Updated@solid-cli/ui@0.0.6
Updated@solid-cli/utils@0.0.6
Updatedexeca@^8.0.1