Socket
Socket
Sign inDemoInstall

argon-cli

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

argon-cli - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

128

index.js

@@ -9,4 +9,7 @@ #!/usr/bin/env node

let config = null;
let globalConfig = null;
const globalConfigFilePath = `${process.cwd()}/${configFile}`;
try {
config = require(`${process.cwd()}/${configFile}`).createComponent;
globalConfig = require(globalConfigFilePath);
config = globalConfig.createComponent;
} catch (e) {

@@ -23,2 +26,3 @@ console.log(chalk.red(chalk.bold('An error occurred while loading configuration')));

// Resolve Layout File name
let layoutFileName = '';

@@ -55,37 +59,93 @@ try {

function createComponent(name) {
// Create folder structure
const currentConfig = argv.atom
? 'atomsFolder'
: argv.molecule
? 'moleculesFolder'
: 'componentsFolder';
const componentPath = `${process.cwd()}/${config[currentConfig]}/${name.toLowerCase()}`;
fs.mkdirsSync(componentPath);
// Create files
fs.writeFileSync(`${componentPath}/_${name}.scss`, '');
const templateFileName = name.toLowerCase();
const jsFileName = `${name.charAt(0).toUpperCase()}${name.substring(1)}`;
try {
const isAtomOrMolecule = (argv.atom || argv.molecule);
const slyComponentTemplate = fs.readFileSync(`${__dirname}/templates/slyComponentTemplate.txt`, 'utf8').toString();
const slyTemplate = fs.readFileSync(`${__dirname}/templates/slyTemplate.txt`, 'utf8').toString();
const jsTemplate = fs.readFileSync(`${__dirname}/templates/jsClassTemplate.txt`, 'utf8').toString();
const jsTestTemplate = fs.readFileSync(`${__dirname}/templates/jsTestFileTemplate.txt`, 'utf8').toString();
const uxPreviewTemplate = fs.readFileSync(`${__dirname}/templates/uxPreviewTemplate.txt`, 'utf8').toString();
fs.writeFileSync(`${componentPath}/${templateFileName}-template.html`, (isAtomOrMolecule ? slyTemplate : slyComponentTemplate).replace('#templateFileName#', templateFileName).replace('#className#', jsFileName));
if (!isAtomOrMolecule) {
const instanceName = `${name.charAt(0).toLowerCase()}${name.substring(1)}`;
fs.writeFileSync(`${componentPath}/${jsFileName}.js`, jsTemplate.replace(/#component#/g, jsFileName));
fs.writeFileSync(`${componentPath}/${jsFileName}.spec.js`, jsTestTemplate.replace(/#component#/g, jsFileName).replace(/#instance#/g, instanceName));
fs.writeFileSync(`${componentPath}/ux-model.json`, '{}');
const previewHtml = uxPreviewTemplate.replace(/#name#/g, templateFileName).replace(/#layoutFileName#/, layoutFileName);
fs.writeFileSync(`${componentPath}/${templateFileName}.hbs`, previewHtml);
}
console.log(chalk.green(chalk.bold(`${targetModule} ${name} has been created!`)));
} catch (e) {
console.log(chalk.red(chalk.bold('Unable to read template file(s)!')));
// Resolve webpack configuration
if (globalConfig.webpack) {
const webpackConfig = globalConfig.webpack;
if (webpackConfig.cacheGroups) {
const bundles = Object.keys(webpackConfig.cacheGroups).filter(bundle => webpackConfig.cacheGroups[bundle].testMultiple);
questions.push({
type: 'list',
message: `Select a bundle where you wish to place your JavaScript file\nOR\nSelect "new" to create new bundle`,
choices: ['new', ...bundles],
default: 'new',
name: 'bundle'
});
}
}
function createNewBundle(bundle) {
return new Promise((resolve, reject) => {
if (bundle === 'new') {
inquirer.prompt([{
message: 'Enter a bundle name',
name: 'bundleName',
type: 'text'
}]).then(({ bundleName: name }) => {
Object.assign(globalConfig.webpack.cacheGroups, {
[name]: {
testMultiple: true,
name,
enforce: true,
chunks: 'all'
}
});
Object.assign(globalConfig.webpack.componentGroups, {
[name]: []
});
resolve();
}).catch(reject);
} else {
resolve();
}
});
}
function createComponent(name, bundle) {
createNewBundle(bundle).then(() => {
// Create folder structure
const currentConfig = argv.atom
? 'atomsFolder'
: argv.molecule
? 'moleculesFolder'
: 'componentsFolder';
const compRelativePath = `${config[currentConfig]}/${name.toLowerCase()}`;
const componentPath = `${process.cwd()}/${compRelativePath}`;
fs.mkdirsSync(componentPath);
// Create files
fs.writeFileSync(`${componentPath}/_${name}.scss`, '');
const templateFileName = name.toLowerCase();
const jsFileName = `${name.charAt(0).toUpperCase()}${name.substring(1)}`;
try {
const isAtomOrMolecule = (argv.atom || argv.molecule);
const slyComponentTemplate = fs.readFileSync(`${__dirname}/templates/slyComponentTemplate.txt`, 'utf8').toString();
const slyTemplate = fs.readFileSync(`${__dirname}/templates/slyTemplate.txt`, 'utf8').toString();
const jsTemplate = fs.readFileSync(`${__dirname}/templates/jsClassTemplate.txt`, 'utf8').toString();
const jsTestTemplate = fs.readFileSync(`${__dirname}/templates/jsTestFileTemplate.txt`, 'utf8').toString();
const uxPreviewTemplate = fs.readFileSync(`${__dirname}/templates/uxPreviewTemplate.txt`, 'utf8').toString();
fs.writeFileSync(`${componentPath}/${templateFileName}-template.html`, (isAtomOrMolecule ? slyTemplate : slyComponentTemplate).replace('#templateFileName#', templateFileName).replace('#className#', jsFileName));
if (!isAtomOrMolecule) {
const instanceName = `${name.charAt(0).toLowerCase()}${name.substring(1)}`;
fs.writeFileSync(`${componentPath}/${jsFileName}.js`, jsTemplate.replace(/#component#/g, jsFileName));
fs.writeFileSync(`${componentPath}/${jsFileName}.spec.js`, jsTestTemplate.replace(/#component#/g, jsFileName).replace(/#instance#/g, instanceName));
fs.writeFileSync(`${componentPath}/ux-model.json`, '{}');
const previewHtml = uxPreviewTemplate.replace(/#name#/g, templateFileName).replace(/#layoutFileName#/, layoutFileName);
fs.writeFileSync(`${componentPath}/${templateFileName}.hbs`, previewHtml);
}
console.log(chalk.green(chalk.bold(`${targetModule} ${name} has been created!`)));
} catch (e) {
console.log(chalk.red(chalk.bold('Unable to read template file(s)!')));
}
// Add bundle
if (
bundle
&& !globalConfig.webpack.componentGroups[bundle].includes(`${compRelativePath}/`)
) {
globalConfig.webpack.componentGroups[bundle].push(`${compRelativePath}/`);
// Write configuration back
fs.writeFileSync(globalConfigFilePath, JSON.stringify(globalConfig, null, 2));
}
}).catch(() => {
console.log(chalk.red(chalk.bold('Something went wrong while resolving the bundle!')));
});
}
inquirer.prompt(questions)

@@ -116,3 +176,3 @@ .then((data) => {

} else {
createComponent(inputComponentName);
createComponent(inputComponentName, data.bundle);
}

@@ -119,0 +179,0 @@ } catch (e) {

{
"name": "argon-cli",
"version": "0.1.1",
"version": "0.2.0",
"description": "Argon CLI provide tools for creating components and running build scripts",

@@ -5,0 +5,0 @@ "main": "index.js",

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