Skip to content

Commit

Permalink
removed components, small style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
garikbesson committed Sep 11, 2024
1 parent 0228d75 commit cd6cae8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 40 deletions.
3 changes: 0 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import semver from 'semver';
import { createProject, runDepsInstall } from './make';
import { promptAndGetConfig, } from './user-input';
import * as show from './messages';
import { trackUsage } from './tracking';

(async function () {

Expand All @@ -21,7 +20,6 @@ import { trackUsage } from './tracking';
projectName,
contract,
frontend,
components,
install,
},
projectPath,
Expand All @@ -34,7 +32,6 @@ import { trackUsage } from './tracking';
createSuccess = await createProject({
contract,
frontend,
components,
templatesDir: path.resolve(__dirname, '../templates'),
projectPath,
});
Expand Down
11 changes: 3 additions & 8 deletions src/make.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import fs from 'fs';
import { ncp } from 'ncp';
import path from 'path';

export async function createProject({ contract, frontend, components, projectPath, templatesDir }: CreateContractParams & CreateGatewayParams): Promise<boolean> {
export async function createProject({ contract, frontend, projectPath, templatesDir }: CreateContractParams & CreateGatewayParams): Promise<boolean> {
if (contract !== 'none') {
await createContract({ contract, projectPath, templatesDir });
} else {
await createGateway({ frontend, components, projectPath, templatesDir });
await createGateway({ frontend, projectPath, templatesDir });
}

return true;
Expand All @@ -23,15 +23,10 @@ async function createContract({ contract, projectPath, templatesDir }: CreateCon

}

async function createGateway({ frontend, components, projectPath, templatesDir }: CreateGatewayParams) {
async function createGateway({ frontend, projectPath, templatesDir }: CreateGatewayParams) {
const sourceFrontendDir = path.resolve(`${templatesDir}/frontend/${frontend}`);
fs.mkdirSync(projectPath, { recursive: true });
await copyDir(sourceFrontendDir, projectPath);

if (components) {
const sourceComponentsDir = path.resolve(`${templatesDir}/frontend/components/${frontend}`);
await copyDir(sourceComponentsDir, projectPath);
}
}

// Wrap `ncp` tool to wait for the copy to finish when using `await`
Expand Down
4 changes: 2 additions & 2 deletions src/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk';
import { trackingMessage, trackUsage } from './tracking';
import { trackingMessage } from './tracking';
import { Contract, Frontend, FrontendMessage, ProjectName } from './types';

if (process.env.NEAR_NO_COLOR) {
Expand All @@ -14,7 +14,7 @@ export const welcome = () =>
👋 {bold {green Welcome to Near!}} Learn more: https://docs.near.org/
🔧 Let's get your project ready.
{blue ======================================================}
(${trackingMessage})`);
(${trackingMessage})\n`);

export const setupFailed = () =>
show(chalk`{bold {red ==========================================}}
Expand Down
5 changes: 2 additions & 3 deletions src/tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const MIXPANEL_TOKEN = '24177ef1ec09ffea5cb6f68909c66a61';

const tracker = mixpanel.init(MIXPANEL_TOKEN);

export const trackingMessage = chalk`Near collects anonymous information on the commands used. No personal information that could identify you is shared`;
export const trackingMessage = chalk.italic('Near collects anonymous information on the commands used. No personal information that could identify you is shared');

// TODO: track different failures & install usage
export const trackUsage = async (frontend: Frontend, components: boolean, contract: Contract) => {
export const trackUsage = async (frontend: Frontend, contract: Contract) => {
// prevents logging from CI
if (process.env.NEAR_ENV === 'ci' || process.env.NODE_ENV === 'ci') {
console.log('Mixpanel logging is skipped in CI env');
Expand All @@ -18,7 +18,6 @@ export const trackUsage = async (frontend: Frontend, components: boolean, contra
try {
const mixPanelProperties = {
frontend,
components,
contract,
os: process.platform,
nodeVersion: process.versions.node,
Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export type ProjectName = string;
export interface UserConfig {
contract: Contract;
frontend: Frontend;
components: boolean;
projectName: ProjectName;
install: boolean;
error: (() => void) | undefined;
Expand All @@ -26,7 +25,6 @@ export type CreateContractParams = {

export type CreateGatewayParams = {
frontend: Frontend,
components: boolean,
projectPath: string,
templatesDir: string,
}
Expand Down
31 changes: 9 additions & 22 deletions src/user-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ export async function getUserArgs(): Promise<UserConfig> {
.argument('[projectName]')
.option('--frontend [next-page|next-app|none]')
.option('--contract [ts|rs|none]')
.option('--components')
.option('--install')
.addHelpText('after', 'You can create a frontend or a contract with tests');

program.parse();

const options = program.opts();
const [projectName] = program.args;
const { contract, frontend, install, components } = options;
return { contract, frontend, components, projectName, install, error: undefined };
const { contract, frontend, install } = options;
return { contract, frontend, projectName, install, error: undefined };
}

type Choices<T> = { title: string, description?: string, value: T }[];
Expand All @@ -49,11 +48,6 @@ const frontendChoices: Choices<Frontend> = [
{ title: 'NextJS (App Router)', description: 'A web-app built using Next.js new App Router', value: 'next-app' },
];

const componentChoices: Choices<Boolean> = [
{ title: 'No', value: false },
{ title: 'Yes', value: true },
];

const appPrompt: PromptObject = {
type: 'select',
name: 'app',
Expand All @@ -68,13 +62,6 @@ const frontendPrompt: PromptObject = {
choices: frontendChoices,
};

const componentsPrompt: PromptObject = {
type: 'select',
name: 'components',
message: 'Are you planning in using on-chain NEAR Components (aka BOS Components)?',
choices: componentChoices,
};

const contractPrompt: PromptObject[] = [
{
type: 'select',
Expand Down Expand Up @@ -109,20 +96,20 @@ export async function getUserAnswers(): Promise<UserConfig> {

if (app === 'gateway') {
// If gateway, ask for the framework to use
const { frontend, components, projectName, install } = await promptUser([frontendPrompt, componentsPrompt, namePrompts, npmPrompt]);
return { frontend, components, contract: 'none', projectName, install, error: undefined };
const { frontend, projectName, install } = await promptUser([frontendPrompt, namePrompts, npmPrompt]);
return { frontend, contract: 'none', projectName, install, error: undefined };
} else {
// If platform is Window, return the error
if (process.platform === 'win32') {
return { frontend: 'none', components: false, contract: 'none', projectName: '', install: false, error: show.windowsWarning };
return { frontend: 'none', contract: 'none', projectName: '', install: false, error: show.windowsWarning };
}

// If contract, ask for the language for the contract
let { contract } = await promptUser(contractPrompt);

const { projectName } = await promptUser(namePrompts);
const install = contract === 'ts' ? (await promptUser(npmPrompt)).install as boolean : false;
return { frontend: 'none', components: false, contract, projectName, install, error: undefined };
return { frontend: 'none', contract, projectName, install, error: undefined };
}
}

Expand All @@ -138,7 +125,7 @@ export async function promptAndGetConfig(): Promise<{ config: UserConfig, projec
}

if (args.error) {
trackUsage('none', false, 'none');
trackUsage('none', 'none');
return args.error();
}

Expand All @@ -149,8 +136,8 @@ export async function promptAndGetConfig(): Promise<{ config: UserConfig, projec
if (!validateUserArgs(args)) return;

// track user input
const { frontend, components, contract } = args;
trackUsage(frontend, components, contract);
const { frontend, contract } = args;
trackUsage(frontend, contract);

let path = projectPath(args.projectName);

Expand Down

0 comments on commit cd6cae8

Please sign in to comment.