New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

create-pota

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-pota - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0-alpha.1

lib/args.d.ts

2

lib/main.js

@@ -1,1 +0,1 @@

import{access as P,mkdir as b}from"fs/promises";import I from"kleur";import E from"prompts";import{nameValidator as S}from"./validators.js";import{resolve as u,relative as O}from"path";import{command as f}from"./spawn.js";import{getPackageInfo as T,readPackageJson as _,writePackageJson as A}from"./package.js";import{CUSTOM_CHOICE_VALUE as a,IGNORED_PACKAGE_KEYS as j,NONE_CHOICE as k,OFFICIAL_SCRIPTS as x,OFFICIAL_TEMPLATES as v,TEMPLATE_VALUES_AS_KEYS as D}from"./constants.js";import{parseArguments as L}from"./parseArguments.js";import{initFileTemplate as W,initGitTemplate as F,initNpmTemplate as G}from"./template.js";import N from"ora";const{bold:H,green:M,cyan:m,yellow:r,gray:R}=I;E.override(L(process.argv.slice(2)));const p=process.cwd(),z=[{type:"text",name:"name",message:"Type in your project name:",initial:"pota-project",async validate(e){const t=S(e);if(typeof t=="string")return t;try{return await P(u(p,e)),"The directory of the specified name already exists."}catch{return!0}}},{type:"select",name:"template",message:"Select a template:",initial:0,choices:[...Object.entries(v).map(([e,{value:t}])=>({title:e,value:t})),{title:r(a),value:a,description:"bring your own custom template"}]},{type:e=>e===a?"text":null,name:"template",message:"Custom template package/git url/local path:"},{type:"select",name:"scripts",message:"Select a scripts package:",initial:0,choices(e){const{recommended:t=[]}=v[D[e]]??{};return[...Object.entries(x).map(([h,d])=>t.length>0&&!t.includes(d)?{value:d,title:R(h),description:"not tested with selected template"}:{title:h,value:d,description:"recommended"}),{title:r(a),value:a,description:"bring your own custom script"},k]}},{type:e=>e===a?"text":null,name:"scripts",message:"Custom script package:",validate:S},{type:"toggle",name:"git",message:"Do you want to initialize git in the project directory?",initial:!0,active:"yes",inactive:"no"}],n=await E(z,{onCancel(){throw new Error("Cancelled.")}}).catch(e=>{console.warn(e.message),process.exit(1)}),{name:y,template:s}=n;console.log();const i=N(`downloading ${r(s)}`).start(),c=u(p,y),l=n.scripts===k.value?null:n.scripts;await b(c),process.chdir(c);const K=process.platform==="win32",U=K?/\\|[/]/:/[/]/,V=/((git|ssh|http(s)?)|(git@[\w\.]+))(:(\/\/)?)([\w\.@\:/\-~]+)(\.git)(\/)?/;try{V.test(s)||n.template.startsWith("bitbucket:")||n.template.startsWith("github:")?await F(s):U.test(s)&&!s.startsWith("@")?await W(u(p,s)):await G(s)}catch(e){i.fail(),console.error(`Error occurred initializing '${s}'`),console.error(e.message||e),process.exit(1)}i.succeed();const g={name:y,private:!0,version:"1.0.0",...l&&{pota:l}},C=await _(c);for(const e in C){const t=e;j.includes(t)||(g[t]=C[t])}let o=null;if(l){i.start(`retrieving ${r(l)} metadata`);try{o=await T(l),i.succeed()}catch{i.fail(),process.exit(1)}}if(o?.name&&(g.devDependencies??={},g.devDependencies[o.name]=`^${o["dist-tags"].latest}`),await A(c,g),n.git){i.start("initializing git");try{await f("git init -b main"),i.succeed()}catch(e){e.code===129?(await f("git init"),await f("git branch master -m main"),i.succeed()):i.fail()}}const J=O(p,process.cwd()),w=o?.pota&&typeof o.pota!="string"?Object.entries(o.pota.commands):[],$=w.find(([,e])=>e.suggest)?.[0];if(console.log(),console.log(`Created ${H(y)} \u{1F481} ${M(c)}`),console.log(),o)if(w.length>0){console.log(`${r(o.name)} provides the following commands:`),console.log();for(const[e,t]of w)console.log(` ${m(`npm run ${e}`)}`),t.description&&console.log(` ${t.description}`),console.log()}else console.log(`scripts: ${r(o.name)}`),console.log();console.log("We suggest that you begin by typing:"),console.log(),console.log(` ${m("cd")} ${J}`),console.log(` ${m("npm install")}`),$&&console.log(` ${m(`npm run ${$}`)}`);
import{resolve as k,relative as D}from"path";import{mkdir as j}from"fs/promises";import r from"ora";import O from"kleur";import{promptName as C}from"./prompts/name.js";import{promptTemplate as h}from"./prompts/template.js";import{promptScripts as E}from"./prompts/scripts.js";import{promptGit as N}from"./prompts/git.js";import{command as d}from"./util/spawn.js";import{getPackageInfo as g,isFilePackage as R,isRegistryPackage as T,readPackageJson as F,writePackageJson as G,IGNORED_PACKAGE_KEYS as I}from"./package.js";import{downloadTemplate as S}from"./downloadTemplate.js";import s from"./args.js";const{bold:A,green:J,cyan:l,yellow:m}=O;let e;const p=process.cwd();let b=!0;const K=s.template?Promise.resolve():h.prefetch({keyword:"@pota",scopes:["pota"]}).finally(()=>{b=!1}),f=s.name||await C(p),n=k(p,f);await j(n),process.chdir(n),b&&(e=r(),e.start("retrieving available templates"),await K,e.stop());const c=s.template||await h();let v=!0;const W=S(c,p).finally(()=>{v=!1}),a=s.scripts&&Object.keys(s.scripts).length>0?{...s.scripts}:T(c)?await(async()=>{e??=r(),e.start(`retrieving ${m(c)} metadata`);const t=await g(c,"create-pota.scripts");return e.succeed(),await E(t)})():{},_=typeof s.git>"u"?await N():s.git;v&&(e??=r(),e.start(`downloading ${m(c)}`),await W,e.succeed());const u=[],w={};Object.keys(a).length>0&&(e??=r(),e.start("retrieving scripts metadata"),await Promise.all(Object.values(a).map(async t=>{if(R(t))return;let o=null;try{o=await g(t,"dist-tags.latest")}catch{}w[t]=o?`~${o}`:"latest",u.push(t)})),e.succeed());const i=await F(n);for(const t in i){const o=t;I.includes(o)&&delete i[o]}if(Object.entries(w).length>0&&(i.devDependencies??={},i.devDependencies={...i.devDependencies,...w}),u.length>0&&(i.pota??=[],i.pota=[...i.pota,...u]),await G(n,{name:f,private:!0,version:"1.0.0",...i}),_){e??=r(),e.start("initializing git");try{await d("git init -b main"),e.succeed()}catch(t){t.code===129?(await d("git init"),await d("git branch master -m main"),e.succeed()):e.fail()}}let P={};if(a.builders)try{P=await g(a.builders,"create-pota.commands")}catch{}const y=Object.entries(P),$=y.find(([,t])=>t.suggest)?.[0];if(console.log(),console.log(`Created ${A(f)} \u{1F481} ${J(n)}`),console.log(),a.builders)if(y.length>0){console.log(`${m(a.builders)} provides the following commands:`),console.log();for(const[t,o]of y)console.log(` ${l(`npm run ${t}`)}`),o.description&&console.log(` ${o.description}`),console.log()}else console.log(`scripts: ${m(a.builders)}`),console.log();console.log("We suggest that you begin by typing:"),console.log(),console.log(` ${l("cd")} ${D(p,process.cwd())}`),console.log(` ${l("npm install")}`),$&&console.log(` ${l(`npm run ${$}`)}`);

@@ -1,3 +0,3 @@

export declare function normalizePackagePath(path: string, filename?: string): string;
export interface PackageJsonShape {
import { SupportedScripts } from './prompts/scripts.js';
export interface PackageJsonShape<T = unknown> {
private?: true;

@@ -20,20 +20,40 @@ exports?: unknown;

keywords?: ReadonlyArray<string>;
pota?: string | {
commands: Record<string, {
description?: string;
suggest?: boolean;
}>;
};
'create-pota'?: T;
pota?: ReadonlyArray<string>;
}
export declare type TemplatePackageJson = PackageJsonShape<{
scripts?: SupportedScripts;
}>;
export declare type ScriptsPackageJson = PackageJsonShape<{
commands: Record<string, {
description?: string;
suggest?: boolean;
}>;
}>;
export declare type PackageJsonShapeKey = keyof PackageJsonShape;
export declare const IGNORED_PACKAGE_KEYS: ReadonlyArray<PackageJsonShapeKey>;
/**
* appends 'package.json' to the specified path, if its not already there
*/
export declare function normalizePackagePath(path: string, filename?: string): string;
/**
* checks if the specified npm package name is a git package
*/
export declare function isGitPackage(pkg: string): boolean;
/**
* checks if the specified npm package name is a file package
*/
export declare function isFilePackage(pkg: string): boolean;
export declare function isRegistryPackage(pkg: string): boolean;
/**
* reads the package.json of the specified path
*/
export declare function readPackageJson(path: string): Promise<PackageJsonShape>;
/**
* writes to the package.json of the specified path
*/
export declare function writePackageJson(path: string, pkg: PackageJsonShape): Promise<void>;
export declare type PackageInfo = PackageJsonShape & {
dist: {
tarball: string;
};
'dist-tags': {
latest: string;
};
};
export declare function getPackageInfo(pkg: string): Promise<PackageInfo>;
/**
* retrives the package info (npm registry metadata, including package.json)
*/
export declare function getPackageInfo(pkg: string, ...fields: ReadonlyArray<string>): Promise<unknown>;

@@ -1,1 +0,1 @@

import{join as o}from"path";import{readFile as e,writeFile as i}from"fs/promises";import{command as a}from"./spawn.js";export function normalizePackagePath(n,r="package.json"){return n.endsWith(r)?n:o(n,r)}export async function readPackageJson(n){return n=normalizePackagePath(n),JSON.parse(await e(n,{encoding:"utf8"}))}export async function writePackageJson(n,r){n=normalizePackagePath(n),await i(n,JSON.stringify(r,null,2),{encoding:"utf8"})}export async function getPackageInfo(n){const r=await a(`npm info ${n} --json`,!1);return r?JSON.parse(r):null}
import{join as o}from"path";import{readFile as r,writeFile as i}from"fs/promises";import{command as s}from"./util/spawn.js";export const IGNORED_PACKAGE_KEYS=["name","version","author","bin","bugs","description","exports","files","license","create-pota","publishConfig","repository","keywords"];export function normalizePackagePath(t,n="package.json"){return t.endsWith(n)?t:o(t,n)}const a=/((git|ssh|http(s)?)|(git@[\w\.]+))(:(\/\/)?)([\w\.@\:/\-~]+)(\.git)(\/)?/;export function isGitPackage(t){return a.test(t)||t.startsWith("bitbucket:")||t.startsWith("github:")}const c=process.platform==="win32",u=c?/\\|[/]/:/[/]/;export function isFilePackage(t){return u.test(t)&&!t.startsWith("@")}export function isRegistryPackage(t){return!isFilePackage(t)&&!isGitPackage(t)}export async function readPackageJson(t){return t=normalizePackagePath(t),JSON.parse(await r(t,{encoding:"utf8"}))}export async function writePackageJson(t,n){t=normalizePackagePath(t),await i(t,JSON.stringify(n,null,2),{encoding:"utf8"})}export async function getPackageInfo(t,...n){const e=await s(`npm info ${t} ${n.join(" ")} --json`,!1);if(!e)throw new Error(`could not find ${t} ${n.join(" ")} metadata`);return JSON.parse(e)}
{
"name": "create-pota",
"version": "1.0.1",
"version": "2.0.0-alpha.1",
"description": "Command for creating Pota projects",

@@ -28,2 +28,3 @@ "bugs": {

"dependencies": {
"@psimk/typed-object": "^1.0.4",
"cross-spawn": "^7.0.3",

@@ -51,3 +52,4 @@ "degit": "^2.8.4",

"@types/validate-npm-package-name": "^3.0.3",
"minimize-js": "^1.2.0"
"minimize-js": "^1.2.0",
"typescript": "^4.7.0-beta"
},

@@ -54,0 +56,0 @@ "engines": {

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