From 74fed8629961b9b2f588edb151216cad4d4b93cb Mon Sep 17 00:00:00 2001 From: garikbesson Date: Fri, 27 Sep 2024 19:18:59 +0300 Subject: [PATCH] Removed components (#2158) * removed components, small style fixes * fix: tests * feat! :removed function call key --------- Co-authored-by: gagdiez --- .github/workflows/test-frontend.yml | 2 -- src/app.ts | 3 -- src/make.ts | 11 ++----- src/messages.ts | 4 +-- src/tracking.ts | 5 ++- src/types.ts | 2 -- src/user-input.ts | 31 ++++++------------- templates/frontend/next-app/src/app/layout.js | 4 +-- .../frontend/next-page/src/pages/_app.js | 4 +-- test/__snapshots__/user-input.test.ts.snap | 3 +- test/make.test.ts | 2 -- 11 files changed, 22 insertions(+), 49 deletions(-) diff --git a/.github/workflows/test-frontend.yml b/.github/workflows/test-frontend.yml index 56a3a549..7a472d11 100644 --- a/.github/workflows/test-frontend.yml +++ b/.github/workflows/test-frontend.yml @@ -20,7 +20,5 @@ jobs: run: npm run start -- hello-near --frontend next-page - name: Install run: cd hello-near && npm install - - name: Create Frontend Components - run: npm run start -- hello-components --frontend next-page --components - name: Install run: cd hello-components && npm install diff --git a/src/app.ts b/src/app.ts index c0a22635..426c75fc 100644 --- a/src/app.ts +++ b/src/app.ts @@ -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 () { @@ -21,7 +20,6 @@ import { trackUsage } from './tracking'; projectName, contract, frontend, - components, install, }, projectPath, @@ -34,7 +32,6 @@ import { trackUsage } from './tracking'; createSuccess = await createProject({ contract, frontend, - components, templatesDir: path.resolve(__dirname, '../templates'), projectPath, }); diff --git a/src/make.ts b/src/make.ts index da65e38c..f62e61cd 100644 --- a/src/make.ts +++ b/src/make.ts @@ -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 { +export async function createProject({ contract, frontend, projectPath, templatesDir }: CreateContractParams & CreateGatewayParams): Promise { if (contract !== 'none') { await createContract({ contract, projectPath, templatesDir }); } else { - await createGateway({ frontend, components, projectPath, templatesDir }); + await createGateway({ frontend, projectPath, templatesDir }); } return true; @@ -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` diff --git a/src/messages.ts b/src/messages.ts index 46e63950..4865c7df 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -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) { @@ -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 ==========================================}} diff --git a/src/tracking.ts b/src/tracking.ts index f6b46de0..b93a5f10 100644 --- a/src/tracking.ts +++ b/src/tracking.ts @@ -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'); @@ -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, diff --git a/src/types.ts b/src/types.ts index 424d0ae4..51fda33e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,7 +12,6 @@ export type ProjectName = string; export interface UserConfig { contract: Contract; frontend: Frontend; - components: boolean; projectName: ProjectName; install: boolean; error: (() => void) | undefined; @@ -26,7 +25,6 @@ export type CreateContractParams = { export type CreateGatewayParams = { frontend: Frontend, - components: boolean, projectPath: string, templatesDir: string, } diff --git a/src/user-input.ts b/src/user-input.ts index 9454bede..39e9136b 100644 --- a/src/user-input.ts +++ b/src/user-input.ts @@ -19,7 +19,6 @@ export async function getUserArgs(): Promise { .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'); @@ -27,8 +26,8 @@ export async function getUserArgs(): Promise { 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 = { title: string, description?: string, value: T }[]; @@ -49,11 +48,6 @@ const frontendChoices: Choices = [ { title: 'NextJS (App Router)', description: 'A web-app built using Next.js new App Router', value: 'next-app' }, ]; -const componentChoices: Choices = [ - { title: 'No', value: false }, - { title: 'Yes', value: true }, -]; - const appPrompt: PromptObject = { type: 'select', name: 'app', @@ -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', @@ -109,12 +96,12 @@ export async function getUserAnswers(): Promise { 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 @@ -122,7 +109,7 @@ export async function getUserAnswers(): Promise { 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 }; } } @@ -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(); } @@ -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); diff --git a/templates/frontend/next-app/src/app/layout.js b/templates/frontend/next-app/src/app/layout.js index a3f96284..ad700a45 100644 --- a/templates/frontend/next-app/src/app/layout.js +++ b/templates/frontend/next-app/src/app/layout.js @@ -5,11 +5,11 @@ import { useEffect, useState } from 'react'; import '@/app/globals.css'; import { NearContext } from '@/context'; import { Navigation } from '@/components/navigation'; -import { NetworkId, HelloNearContract } from '@/config'; +import { NetworkId } from '@/config'; import { Wallet } from '@/wallets/near'; -const wallet = new Wallet({ networkId: NetworkId, createAccessKeyFor: HelloNearContract }); +const wallet = new Wallet({ networkId: NetworkId }); // Layout Component export default function RootLayout({ children }) { diff --git a/templates/frontend/next-page/src/pages/_app.js b/templates/frontend/next-page/src/pages/_app.js index 234f7e92..62942588 100644 --- a/templates/frontend/next-page/src/pages/_app.js +++ b/templates/frontend/next-page/src/pages/_app.js @@ -5,9 +5,9 @@ import { NearContext } from '@/context'; import { Navigation } from '@/components/navigation'; import { Wallet } from '@/wallets/near'; -import { NetworkId, HelloNearContract } from '@/config'; +import { NetworkId } from '@/config'; -const wallet = new Wallet({ createAccessKeyFor: HelloNearContract, networkId: NetworkId }); +const wallet = new Wallet({ networkId: NetworkId }); export default function MyApp({ Component, pageProps }) { const [signedAccountId, setSignedAccountId] = useState(''); diff --git a/test/__snapshots__/user-input.test.ts.snap b/test/__snapshots__/user-input.test.ts.snap index 2b89f4dc..ed93c22d 100644 --- a/test/__snapshots__/user-input.test.ts.snap +++ b/test/__snapshots__/user-input.test.ts.snap @@ -8,7 +8,8 @@ exports[`messages snapshot basic messages 1`] = ` 👋 Welcome to Near! Learn more: https://docs.near.org/ 🔧 Let's get your project ready. ====================================================== -(Near collects anonymous information on the commands used. No personal information that could identify you is shared)", +(Near collects anonymous information on the commands used. No personal information that could identify you is shared) +", ], [ "========================================== diff --git a/test/make.test.ts b/test/make.test.ts index 2af8f3a1..fd782107 100644 --- a/test/make.test.ts +++ b/test/make.test.ts @@ -17,7 +17,6 @@ describe('create contract', () => { await createProject({ contract, frontend: 'none', - components: false, templatesDir: rootDir, projectPath, }); @@ -60,7 +59,6 @@ describe('create frontend', () => { await createProject({ contract: 'none', frontend: frontend, - components: false, templatesDir: rootDir, projectPath, });