Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@solid-cli/commands

Package Overview
Dependencies
Maintainers
3
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solid-cli/commands - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

dist/handlers/new.mjs

18

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc