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

react-creates

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-creates - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

2

dist/src/cli/commands/create-component.d.ts

@@ -0,2 +1,4 @@

import { CreateComponentOption, CreateComponentMeta } from '../../create-component';
export declare function createComponentCommand(): import("commander").Command;
export declare function buildCreateComponentCommand(options: CreateComponentOption, resolveProperty?: CreateComponentMeta['resolveProperty']): Promise<string[]>;
//# sourceMappingURL=create-component.d.ts.map

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.createComponentCommand = void 0;
exports.buildCreateComponentCommand = exports.createComponentCommand = void 0;
const node_1 = require("@file-services/node");

@@ -28,2 +28,9 @@ const commander_1 = require("commander");

fileSystem: node_1.nodeFs,
onFinished({ name: _name, directory: _directory, ...resolvedOptions }) {
if (optionsCache && !options.fresh && !options.yes) {
for (const [key, value] of Object.entries(resolvedOptions)) {
optionsCache.set(key, value);
}
}
},
async resolveProperty(key) {

@@ -42,3 +49,3 @@ if (options.yes) {

}
const values = [...create_component_1.propertiesOptions[key]];
const values = [...create_component_1.createComponentProperties[key]];
const response = await (0, prompts_1.default)({

@@ -48,3 +55,3 @@ type: 'select',

message: `Select component ${key}:`,
choices: values.map((value) => ({ title: value, value })),
choices: values.map((value) => ({ title: value.toString(), value })),
});

@@ -60,2 +67,20 @@ const value = response[key];

exports.createComponentCommand = createComponentCommand;
async function buildCreateComponentCommand(options, resolveProperty) {
const { name, directory, language, propTypes, skipTest, style, type } = await (0, create_component_1.resolveCreateComponentOptions)(options, resolveProperty);
return [
'component',
name,
'-d',
directory,
'-l',
language,
'-t',
type,
propTypes ? '-pt' : '',
skipTest ? '--skipTest' : '',
'-s',
style,
].filter(Boolean);
}
exports.buildCreateComponentCommand = buildCreateComponentCommand;
//# sourceMappingURL=create-component.js.map

13

dist/src/cli/file-system-cache.js

@@ -22,3 +22,7 @@ "use strict";

}
const cachePathDir = (0, find_cache_dir_1.default)({ name: fileSystem.join('react-creates', packageJsonPath), create: true });
const cachePathDir = (0, find_cache_dir_1.default)({
name: fileSystem.join('react-creates', packageJsonPath),
create: true,
cwd: rootDir,
});
return fileSystem.join(cachePathDir, 'cache.json');

@@ -54,6 +58,7 @@ }

var _a;
if (!this.fileSystem.existsSync(this.cachePath)) {
this.fileSystem.writeFileSync(this.cachePath, '{}');
this.currentContent = {};
}
if (!this.currentContent) {
if (!this.fileSystem.existsSync(this.cachePath)) {
this.fileSystem.writeFileSync(this.cachePath, '{}');
}
this.currentContent = (_a = this.fileSystem.readJsonFileSync(this.cachePath)) !== null && _a !== void 0 ? _a : {};

@@ -60,0 +65,0 @@ }

import type { IFileSystem } from '@file-services/types';
export declare const propertiesOptions: {
export declare const createComponentProperties: {
language: string[];

@@ -22,2 +22,3 @@ type: string[];

templateDirectory?: string;
onFinished?: (options: Required<CreateComponentOption>) => Promise<void> | void;
logger?: {

@@ -28,3 +29,4 @@ log: (...messages: any[]) => void;

}
export declare function createComponent(options: CreateComponentOption, { resolveProperty, fileSystem, templateDirectory, logger, }?: CreateComponentMeta): Promise<void>;
export declare function createComponent(options: CreateComponentOption, { resolveProperty, fileSystem, templateDirectory, logger, onFinished, }?: CreateComponentMeta): Promise<void>;
export declare function resolveCreateComponentOptions(options: CreateComponentOption, resolveProperty?: CreateComponentMeta['resolveProperty']): Promise<Required<CreateComponentOption>>;
//# sourceMappingURL=create-component.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createComponent = exports.propertiesOptions = void 0;
exports.resolveCreateComponentOptions = exports.createComponent = exports.createComponentProperties = void 0;
const node_1 = require("@file-services/node");

@@ -9,3 +9,3 @@ const mustache_1 = require("mustache");

const defaultTemplateDirectory = node_1.nodeFs.join(node_1.nodeFs.dirname(require.resolve('react-creates/package.json')), 'templates', 'component');
exports.propertiesOptions = {
exports.createComponentProperties = {
language: ['typescript', 'javascript'],

@@ -15,23 +15,5 @@ type: ['function', 'class'],

};
async function createComponent(options, { resolveProperty, fileSystem = node_1.nodeFs, templateDirectory = defaultTemplateDirectory, logger = console, } = {}) {
var _a, _b;
if (!options.type) {
options.type = (await (resolveProperty === null || resolveProperty === void 0 ? void 0 : resolveProperty('type'))) || 'function';
}
if (!options.language) {
options.language = (await (resolveProperty === null || resolveProperty === void 0 ? void 0 : resolveProperty('language'))) || 'typescript';
}
if (!options.propTypes) {
options.propTypes = (_a = (await (resolveProperty === null || resolveProperty === void 0 ? void 0 : resolveProperty('propTypes')))) !== null && _a !== void 0 ? _a : false;
}
if (!options.skipTest) {
options.skipTest = (_b = (await (resolveProperty === null || resolveProperty === void 0 ? void 0 : resolveProperty('skipTest')))) !== null && _b !== void 0 ? _b : false;
}
if (!options.style) {
options.style = (await (resolveProperty === null || resolveProperty === void 0 ? void 0 : resolveProperty('style'))) || 'none';
}
if (options.style === 'none') {
options.style = undefined;
}
const { language, type, name, directory: target } = options;
async function createComponent(options, { resolveProperty, fileSystem = node_1.nodeFs, templateDirectory = defaultTemplateDirectory, logger = console, onFinished, } = {}) {
const resolvedOptions = await resolveCreateComponentOptions(options, resolveProperty);
const { language, type, name, directory: target } = resolvedOptions;
const resolvedSource = fileSystem.join(templateDirectory, language, type);

@@ -42,5 +24,9 @@ const resolvedTarget = fileSystem.join(target, name);

const files = await fileSystem.promises.readdir(resolvedTarget);
const modifiedOptions = {
...resolvedOptions,
style: resolvedOptions.style === 'none' ? undefined : resolvedOptions.style,
};
try {
for (const oldFileName of files) {
if (options.skipTest && testFileRegex.test(oldFileName)) {
if (modifiedOptions.skipTest && testFileRegex.test(oldFileName)) {
/**

@@ -52,3 +38,3 @@ * Delete test file

}
if (!options.style && styleFileRegex.test(oldFileName)) {
if (!modifiedOptions.style && styleFileRegex.test(oldFileName)) {
/**

@@ -63,3 +49,3 @@ * Delete style file

*/
const fileName = (0, mustache_1.render)(oldFileName, options).replace(/.template$/, '');
const fileName = (0, mustache_1.render)(oldFileName, modifiedOptions).replace(/.template$/, '');
const filePath = fileSystem.join(resolvedTarget, fileName);

@@ -71,6 +57,7 @@ await fileSystem.promises.rename(fileSystem.join(resolvedTarget, oldFileName), filePath);

const content = await fileSystem.promises.readFile(filePath, 'utf8');
const resolvedContent = (0, mustache_1.render)(content, options);
const resolvedContent = (0, mustache_1.render)(content, modifiedOptions);
await fileSystem.promises.writeFile(filePath, resolvedContent, 'utf8');
}
logger.log(`Component "${name}" created.\n\n${resolvedTarget}\n`);
onFinished === null || onFinished === void 0 ? void 0 : onFinished(resolvedOptions);
}

@@ -84,2 +71,15 @@ catch (error) {

exports.createComponent = createComponent;
async function resolveCreateComponentOptions(options, resolveProperty = () => void 0) {
var _a, _b, _c, _d, _e, _f, _g, _h;
return {
name: options.name,
directory: options.directory,
type: (_a = options.type) !== null && _a !== void 0 ? _a : ((await (resolveProperty === null || resolveProperty === void 0 ? void 0 : resolveProperty('type'))) || 'function'),
language: (_b = options.language) !== null && _b !== void 0 ? _b : ((await (resolveProperty === null || resolveProperty === void 0 ? void 0 : resolveProperty('language'))) || 'typescript'),
propTypes: (_d = (_c = options.propTypes) !== null && _c !== void 0 ? _c : (await (resolveProperty === null || resolveProperty === void 0 ? void 0 : resolveProperty('propTypes')))) !== null && _d !== void 0 ? _d : false,
skipTest: (_f = (_e = options.skipTest) !== null && _e !== void 0 ? _e : (await (resolveProperty === null || resolveProperty === void 0 ? void 0 : resolveProperty('skipTest')))) !== null && _f !== void 0 ? _f : false,
style: (_h = (_g = options.style) !== null && _g !== void 0 ? _g : (await (resolveProperty === null || resolveProperty === void 0 ? void 0 : resolveProperty('style')))) !== null && _h !== void 0 ? _h : 'none',
};
}
exports.resolveCreateComponentOptions = resolveCreateComponentOptions;
//# sourceMappingURL=create-component.js.map

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

export { ComponentOption, CreateComponentMeta, CreateComponentOption, createComponent, propertiesOptions, } from './create-component';
export { ComponentOption, CreateComponentMeta, CreateComponentOption, createComponent, createComponentProperties, resolveCreateComponentOptions, } from './create-component';
export { buildCreateComponentCommand } from './cli/commands/create-component';
export { FileSystemCache } from './cli/file-system-cache';
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileSystemCache = exports.propertiesOptions = exports.createComponent = void 0;
exports.FileSystemCache = exports.buildCreateComponentCommand = exports.resolveCreateComponentOptions = exports.createComponentProperties = exports.createComponent = void 0;
var create_component_1 = require("./create-component");
Object.defineProperty(exports, "createComponent", { enumerable: true, get: function () { return create_component_1.createComponent; } });
Object.defineProperty(exports, "propertiesOptions", { enumerable: true, get: function () { return create_component_1.propertiesOptions; } });
Object.defineProperty(exports, "createComponentProperties", { enumerable: true, get: function () { return create_component_1.createComponentProperties; } });
Object.defineProperty(exports, "resolveCreateComponentOptions", { enumerable: true, get: function () { return create_component_1.resolveCreateComponentOptions; } });
var create_component_2 = require("./cli/commands/create-component");
Object.defineProperty(exports, "buildCreateComponentCommand", { enumerable: true, get: function () { return create_component_2.buildCreateComponentCommand; } });
var file_system_cache_1 = require("./cli/file-system-cache");
Object.defineProperty(exports, "FileSystemCache", { enumerable: true, get: function () { return file_system_cache_1.FileSystemCache; } });
//# sourceMappingURL=index.js.map
{
"name": "react-creates",
"version": "2.0.1",
"version": "2.0.2",
"description": "React creates for you useful and common tools that adapt themselves to your project for faster and easier development",

@@ -5,0 +5,0 @@ "files": [

import { nodeFs } from '@file-services/node';
import { program } from 'commander';
import { createComponent, ComponentOption, propertiesOptions } from '../../create-component';
import {
createComponent,
ComponentOption,
createComponentProperties,
CreateComponentOption,
resolveCreateComponentOptions,
CreateComponentMeta,
} from '../../create-component';
import prompts from 'prompts';

@@ -25,2 +32,9 @@ import { FileSystemCache } from '../file-system-cache';

fileSystem: nodeFs,
onFinished({ name: _name, directory: _directory, ...resolvedOptions }) {
if (optionsCache && !options.fresh && !options.yes) {
for (const [key, value] of Object.entries(resolvedOptions)) {
optionsCache.set(key, value);
}
}
},
async resolveProperty(key) {

@@ -43,3 +57,3 @@ if (options.yes) {

const values = [...propertiesOptions[key as keyof typeof propertiesOptions]];
const values = [...createComponentProperties[key as keyof typeof createComponentProperties]];
const response = await prompts({

@@ -49,3 +63,3 @@ type: 'select',

message: `Select component ${key}:`,
choices: values.map((value) => ({ title: value, value })),
choices: values.map((value) => ({ title: value.toString(), value })),
});

@@ -65,1 +79,26 @@

}
export async function buildCreateComponentCommand(
options: CreateComponentOption,
resolveProperty?: CreateComponentMeta['resolveProperty']
): Promise<string[]> {
const { name, directory, language, propTypes, skipTest, style, type } = await resolveCreateComponentOptions(
options,
resolveProperty
);
return [
'component',
name,
'-d',
directory,
'-l',
language,
'-t',
type,
propTypes ? '-pt' : '',
skipTest ? '--skipTest' : '',
'-s',
style,
].filter(Boolean);
}

@@ -23,3 +23,7 @@ import { nodeFs } from '@file-services/node';

const cachePathDir = findCacheDir({ name: fileSystem.join('react-creates', packageJsonPath), create: true })!;
const cachePathDir = findCacheDir({
name: fileSystem.join('react-creates', packageJsonPath),
create: true,
cwd: rootDir,
})!;

@@ -69,7 +73,8 @@ return fileSystem.join(cachePathDir, 'cache.json');

private getCacheContent() {
if (!this.fileSystem.existsSync(this.cachePath)) {
this.fileSystem.writeFileSync(this.cachePath, '{}');
this.currentContent = {};
}
if (!this.currentContent) {
if (!this.fileSystem.existsSync(this.cachePath)) {
this.fileSystem.writeFileSync(this.cachePath, '{}');
}
this.currentContent = (this.fileSystem.readJsonFileSync(this.cachePath) as Record<string, any>) ?? {};

@@ -76,0 +81,0 @@ }

@@ -13,3 +13,3 @@ import { nodeFs } from '@file-services/node';

export const propertiesOptions = {
export const createComponentProperties = {
language: ['typescript', 'javascript'],

@@ -39,2 +39,3 @@ type: ['function', 'class'],

templateDirectory?: string;
onFinished?: (options: Required<CreateComponentOption>) => Promise<void> | void;
logger?: {

@@ -53,30 +54,8 @@ log: (...messages: any[]) => void;

logger = console,
onFinished,
}: CreateComponentMeta = {}
) {
if (!options.type) {
options.type = (await resolveProperty?.('type')) || 'function';
}
const resolvedOptions = await resolveCreateComponentOptions(options, resolveProperty);
const { language, type, name, directory: target } = resolvedOptions;
if (!options.language) {
options.language = (await resolveProperty?.('language')) || 'typescript';
}
if (!options.propTypes) {
options.propTypes = (await resolveProperty?.('propTypes')) ?? false;
}
if (!options.skipTest) {
options.skipTest = (await resolveProperty?.('skipTest')) ?? false;
}
if (!options.style) {
options.style = (await resolveProperty?.('style')) || 'none';
}
if (options.style === 'none') {
options.style = undefined;
}
const { language, type, name, directory: target } = options;
const resolvedSource = fileSystem.join(templateDirectory, language, type);

@@ -90,5 +69,10 @@ const resolvedTarget = fileSystem.join(target, name);

const modifiedOptions = {
...resolvedOptions,
style: resolvedOptions.style === 'none' ? undefined : resolvedOptions.style,
};
try {
for (const oldFileName of files) {
if (options.skipTest && testFileRegex.test(oldFileName)) {
if (modifiedOptions.skipTest && testFileRegex.test(oldFileName)) {
/**

@@ -101,3 +85,3 @@ * Delete test file

if (!options.style && styleFileRegex.test(oldFileName)) {
if (!modifiedOptions.style && styleFileRegex.test(oldFileName)) {
/**

@@ -113,3 +97,3 @@ * Delete style file

*/
const fileName = render(oldFileName, options).replace(/.template$/, '');
const fileName = render(oldFileName, modifiedOptions).replace(/.template$/, '');
const filePath = fileSystem.join(resolvedTarget, fileName);

@@ -122,6 +106,8 @@ await fileSystem.promises.rename(fileSystem.join(resolvedTarget, oldFileName), filePath);

const content = await fileSystem.promises.readFile(filePath, 'utf8');
const resolvedContent = render(content, options);
const resolvedContent = render(content, modifiedOptions);
await fileSystem.promises.writeFile(filePath, resolvedContent, 'utf8');
}
logger.log(`Component "${name}" created.\n\n${resolvedTarget}\n`);
onFinished?.(resolvedOptions);
} catch (error) {

@@ -134,1 +120,16 @@ logger.error(`Failed to create "${name}" component.\n\n${resolvedTarget}\n${error}`);

}
export async function resolveCreateComponentOptions(
options: CreateComponentOption,
resolveProperty: CreateComponentMeta['resolveProperty'] = () => void 0
): Promise<Required<CreateComponentOption>> {
return {
name: options.name,
directory: options.directory,
type: options.type ?? ((await resolveProperty?.('type')) || 'function'),
language: options.language ?? ((await resolveProperty?.('language')) || 'typescript'),
propTypes: options.propTypes ?? (await resolveProperty?.('propTypes')) ?? false,
skipTest: options.skipTest ?? (await resolveProperty?.('skipTest')) ?? false,
style: options.style ?? (await resolveProperty?.('style')) ?? 'none',
};
}

@@ -6,4 +6,6 @@ export {

createComponent,
propertiesOptions,
createComponentProperties,
resolveCreateComponentOptions,
} from './create-component';
export { buildCreateComponentCommand } from './cli/commands/create-component';
export { FileSystemCache } from './cli/file-system-cache';

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

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

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