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

@sparkbox/carbon-cli

Package Overview
Dependencies
Maintainers
6
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sparkbox/carbon-cli - npm Package Compare versions

Comparing version 0.5.3-1e375f7.0 to 0.5.3-d73e642.0

dist/download.js

9

dist/build-templates.js

@@ -9,5 +9,10 @@ "use strict";

async function buildTemplates(options) {
const templateFiles = await util_1.run(`egrep -lr '<%.*%>' ${options.projectDir} || true`);
const templateFiles = await util_1.run(`egrep -lr '<%=.+%>' ${options.projectDir} || true`);
const templates = templateFiles.split('\n').filter(Boolean);
return Promise.all(templates.map(file => render(file, options)));
return Promise.all(templates.map(file => {
// for now, if a template fails to render,
// we're assuming there's a valid reason and
// letting it silently fail
return render(file, options).catch(() => { });
}));
}

@@ -14,0 +19,0 @@ exports.buildTemplates = buildTemplates;

@@ -11,5 +11,22 @@ "use strict";

const prompts_1 = require("./prompts");
const debug = process.env.DEBUG === 'octokit' ? console.log : () => { };
async function GHClient({ authToken, org }) {
const gh = await github(authToken);
const user = await getUser(gh);
const owner = org || user.login;
const repos = org ? await getOrgRepos(gh, org) : await getUserRepos(gh, user.login);
const getDownload = (repo, branch) => getDownloadUrl(gh, repo, owner, branch);
const createRepo = org
? (name) => createOrgRepo(gh, name, org)
: (name) => createUserRepo(gh, name);
return { owner, repos, getDownload, createRepo };
}
exports.GHClient = GHClient;
async function github(authToken) {
if (authToken) {
return new rest_1.default({ userAgent: '@sparkbox/carbon-cli', auth: authToken });
return new rest_1.default({
userAgent: '@sparkbox/carbon-cli',
auth: authToken,
log: { debug },
});
}

@@ -24,8 +41,24 @@ const { username, password } = await prompts_1.login();

},
log: { debug },
});
}
exports.github = github;
async function getRepos(gh) {
async function getUser(gh) {
const { data: user } = await gh.users.getAuthenticated();
return user;
}
exports.getUser = getUser;
async function getUserRepos(gh, username) {
const { data: repos } = await gh.repos.listForUser({
username,
type: 'all',
sort: 'updated',
per_page: 100,
});
return repos;
}
exports.getUserRepos = getUserRepos;
async function getOrgRepos(gh, org) {
const { data: repos } = await gh.repos.listForOrg({
org: 'sparkbox',
org,
type: 'all',

@@ -37,15 +70,4 @@ sort: 'updated',

}
exports.getRepos = getRepos;
// temporarily will create a "user" repo as oposed to "org"
async function createRepo(gh, name) {
// const { data: teams } = await gh.teams.list({ org: 'sparkbox' });
// const { id: sbTeamId } = teams.find(t => t.slug === 'sparkbox') || {};
// const { data: newRepo } = await gh.repos.createInOrg({
// name,
// org: 'sparkbox',
// private: true,
// team_id: sbTeamId,
// allow_merge_commit: false,
// auto delete head branches?
// });
exports.getOrgRepos = getOrgRepos;
async function createUserRepo(gh, name) {
const { data: newRepo } = await gh.repos.createForAuthenticatedUser({

@@ -58,5 +80,32 @@ name,

}
exports.createRepo = createRepo;
// TODO:
// repos.updateBranchProtection to protect master
exports.createUserRepo = createUserRepo;
async function createOrgRepo(gh, name, org) {
const { data: teams } = await gh.teams.list({ org });
const { id: teamId } = teams.find(t => t.slug === org) || {};
const { data: newRepo } = await gh.repos.createInOrg({
name,
org,
private: true,
team_id: teamId,
allow_merge_commit: false,
});
return newRepo;
}
exports.createOrgRepo = createOrgRepo;
async function getDownloadUrl(gh, repo, owner, branch = 'master') {
// https://github.com/sparkbox/${repoName}/archive/${branch}.zip
let res;
try {
res = (await gh.repos.getArchiveLink({
owner,
repo,
archive_format: 'tarball',
ref: branch || 'master',
}));
return res.url;
}
catch (e) {
return `https://github.com/sparkbox/${repo}/archive/${branch}.zip`;
}
}
//# sourceMappingURL=github.js.map

@@ -10,2 +10,3 @@ #!/usr/bin/env node

const build_templates_1 = require("./build-templates");
const download_1 = require("./download");
const github_1 = require("./github");

@@ -17,48 +18,55 @@ const prompts_1 = require("./prompts");

async function main() {
const gh = await github_1.github(CARBON_CLI_TOKEN);
const repos = await github_1.getRepos(gh);
const projectOptions = await prompts_1.buildOptions(repos.map(r => r.name));
const { repos, getDownload, createRepo } = await github_1.GHClient({
authToken: CARBON_CLI_TOKEN,
org: 'sparkbox',
});
const projectOptions = await prompts_1.buildOptions(repos);
const { sourceRepo, branch, projectName, projectDir, shouldCreateRemote } = projectOptions;
const downloadLink = await getDownload(sourceRepo.name, branch);
util_1.reviewOptions(projectOptions);
const proceed = await prompts_1.confirmOptions();
if (!proceed)
const confirmation = await prompts_1.confirmOptions();
if (!confirmation) {
process.exit();
return;
status.start(`initialize repo`);
await util_1.run(`mkdir ${projectName} && cd ${projectName} && git init`);
status.succeed();
status.start(`download ${sourceRepo}`);
await util_1.run(`curl -Lk ${util_1.tarUrl(sourceRepo, branch)} | tar -C ${projectName} -x --strip-components=1`);
status.succeed();
status.start('tidy up package.json');
await build_package_1.buildPackage(projectDir);
status.succeed();
status.start('customize project files');
await build_templates_1.buildTemplates(projectOptions);
status.succeed();
let newRemote;
if (shouldCreateRemote) {
status.start('create new remote on GitHub');
newRemote = await github_1.createRepo(gh, projectName);
await util_1.run(`
cd ${projectDir} &&
git remote add origin ${newRemote.ssh_url} &&
git add . &&
git commit --no-verify --no-gpg-sign -m "initial commit" &&
git push -u origin master
`);
}
try {
status.start(`initialize repo`);
await util_1.run(`mkdir ${projectName} && cd ${projectName} && git init`);
status.succeed();
status.start(`download ${sourceRepo.name}`);
await download_1.download(downloadLink, projectDir);
status.succeed();
status.start('tidy up package.json');
await build_package_1.buildPackage(projectDir);
status.succeed();
status.start('customize project files');
await build_templates_1.buildTemplates(projectOptions);
status.succeed();
let newRemote;
if (shouldCreateRemote) {
status.start('create new remote on GitHub');
newRemote = await createRepo(projectName);
await util_1.run(`
cd ${projectDir} &&
git remote add origin ${newRemote.ssh_url} &&
git add . &&
git commit --no-verify --no-gpg-sign -m "initial commit" &&
git push -u origin master
`);
status.succeed();
}
// TODO: skipping install for now
// status.start('install dependencies');
// await run(`cd ${projectName} && npm i`);
// status.succeed();
util_1.overview(projectOptions, newRemote);
}
// TODO: skipping install for now
// status.start('install dependencies');
// await run(`cd ${projectName} && npm i`);
// status.succeed();
util_1.overview(projectOptions, newRemote);
catch (e) {
await util_1.run(`rm -rf ${projectDir}`);
status.fail(e);
util_1.message.error(e);
process.exit(1);
}
}
main().catch(e => {
status.fail();
util_1.message.error(e);
// clean up here
// await run(`rm -rf ${projectDir}`).catch(() => {});
process.exit(1);
});
main();
//# sourceMappingURL=main.js.map

@@ -15,10 +15,13 @@ "use strict";

inquirer_1.registerPrompt('autocomplete', inquirer_autocomplete_prompt_1.default);
async function buildOptions(repoNames) {
const opts = await inquirer_1.prompt([
async function buildOptions(repos) {
const repoNames = repos.map(r => r.name);
const { sourceRepoName } = await inquirer_1.prompt([
{
type: 'autocomplete',
name: 'sourceRepo',
name: 'sourceRepoName',
message: 'search for a repo to replicate',
source: fuzzyMatch(repoNames),
},
]);
const opts = await inquirer_1.prompt([
{

@@ -52,3 +55,5 @@ type: 'input',

]);
return { ...opts, projectDir: path_1.join(process.cwd(), opts.projectName) };
const sourceRepo = repos.find(r => r.name === sourceRepoName);
const projectDir = path_1.join(process.cwd(), opts.projectName);
return { ...opts, sourceRepo, projectDir };
}

@@ -55,0 +60,0 @@ exports.buildOptions = buildOptions;

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

${gray.bold('from:')} ${magenta(projectOptions.sourceRepo)}:${magenta(projectOptions.branch)}
${gray.bold('from:')} ${magenta(projectOptions.sourceRepo.name)}:${magenta(projectOptions.branch)}
${gray.bold('to:')} ${cyan(projectOptions.projectDir)}

@@ -26,0 +26,0 @@

@@ -5,3 +5,4 @@ "use strict";

const util_1 = require("util");
exports.read = util_1.promisify(fs_1.readFile);
exports.write = util_1.promisify(fs_1.writeFile);
//# sourceMappingURL=write-file.js.map
{
"name": "@sparkbox/carbon-cli",
"version": "0.5.3-1e375f7.0",
"version": "0.5.3-d73e642.0",
"description": "Project Setup Automation",

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

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