Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shopify-cli-web #5076

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/app/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import init from './hooks/clear_command_cache.js'
import gatherPublicMetadata from './hooks/public_metadata.js'
import gatherSensitiveMetadata from './hooks/sensitive_metadata.js'
import AppCommand from './utilities/app-command.js'
import initService from './services/init/init.js'
import {selectDeveloperPlatformClient} from './utilities/developer-platform-client.js'
import {appFromId, selectOrg} from './services/context.js'
import versionList from './services/versions-list.js'

/**
* All app commands should extend AppCommand.
Expand Down Expand Up @@ -60,3 +64,8 @@ export const commands: {[key: string]: typeof AppCommand} = {
export const AppSensitiveMetadataHook = gatherSensitiveMetadata
export const AppInitHook = init
export const AppPublicMetadataHook = gatherPublicMetadata
export {initService as init}
export {selectDeveloperPlatformClient}
export {appFromId}
export {selectOrg}
export {versionList}
9 changes: 6 additions & 3 deletions packages/app/src/cli/services/versions-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ interface VersionListOptions {
json: boolean
}

export default async function versionList(options: VersionListOptions) {
export default async function versionList(options: VersionListOptions): Promise<AppVersionLine[]> {
const {remoteApp, developerPlatformClient, organization} = options

const {appVersions, totalResults} = await fetchAppVersions(developerPlatformClient, remoteApp, options.json)

if (options.json) {
return outputInfo(JSON.stringify(appVersions, null, 2))
outputInfo(JSON.stringify(appVersions, null, 2))
return appVersions
}

renderCurrentlyUsedConfigInfo({
Expand All @@ -105,7 +106,7 @@ export default async function versionList(options: VersionListOptions) {

if (appVersions.length === 0) {
outputInfo('No app versions found for this app')
return
return []
}

renderTable({
Expand All @@ -125,4 +126,6 @@ export default async function versionList(options: VersionListOptions) {
)

outputInfo(outputContent`\nView all ${String(totalResults)} app versions in the ${link}`)

return appVersions
}
11 changes: 9 additions & 2 deletions packages/cli-kit/src/private/node/conf-store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {isUnitTest} from '../../public/node/context/local.js'
import {LocalStorage} from '../../public/node/local-storage.js'
import {isBrowswer} from '@shopify/cli-kit/node/system'
import {outputContent, outputDebug} from '@shopify/cli-kit/node/output'

interface CacheValue<T> {
Expand Down Expand Up @@ -60,8 +61,14 @@
* @param session - Session.
*/
export function setSession(session: string, config: LocalStorage<ConfSchema> = cliKitStore()): void {
outputDebug(outputContent`Setting session store...`)
config.set('sessionStore', session)
if (isBrowswer()) {
// eslint-disable-next-line no-console
console.log('Setting storageSession...')
sessionStorage.setItem('shopify-cli-web-session', session)
} else {
outputDebug(outputContent`Setting session store...`)
config.set('sessionStore', session)
}
}

/**
Expand Down Expand Up @@ -101,7 +108,7 @@
}

export function cacheStore(key: ExportedKey, value: string, config = cliKitStore()): void {
const cache: Cache = config.get('cache') || {}

Check warning on line 111 in packages/cli-kit/src/private/node/conf-store.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/cli-kit/src/private/node/conf-store.ts#L111

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
cache[key] = {value, timestamp: Date.now()}
config.set('cache', cache)
}
Expand All @@ -112,7 +119,7 @@
* @returns The chache element.
*/
export function cacheRetrieve(key: ExportedKey, config = cliKitStore()): CacheValue<string> | undefined {
const cache: Cache = config.get('cache') || {}

Check warning on line 122 in packages/cli-kit/src/private/node/conf-store.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/cli-kit/src/private/node/conf-store.ts#L122

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
return cache[key]
}

Expand Down Expand Up @@ -146,7 +153,7 @@
task: () => Promise<void>,
config = cliKitStore(),
): Promise<boolean> {
const cache: Cache = config.get('cache') || {}

Check warning on line 156 in packages/cli-kit/src/private/node/conf-store.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/cli-kit/src/private/node/conf-store.ts#L156

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
const cacheKey: MostRecentOccurrenceKey = `most-recent-occurrence-${key}`
const cached = cache[cacheKey]

Expand Down Expand Up @@ -197,7 +204,7 @@
*/
export async function runWithRateLimit(options: RunWithRateLimitOptions, config = cliKitStore()): Promise<boolean> {
const {key, limit, timeout, task} = options
const cache: Cache = config.get('cache') || {}

Check warning on line 207 in packages/cli-kit/src/private/node/conf-store.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/cli-kit/src/private/node/conf-store.ts#L207

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
const cacheKey: RateLimitKey = `rate-limited-occurrences-${key}`
const cached = cache[cacheKey]
const now = Date.now()
Expand Down
9 changes: 9 additions & 0 deletions packages/cli-kit/src/public/node/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,12 @@ export function terminalSupportsPrompting(): boolean {
}
return Boolean(process.stdin.isTTY && process.stdout.isTTY)
}

/**
* Check if the current environment is a browser.
*
* @returns True if the current environment is a browser.
*/
export function isBrowswer(): boolean {
return typeof global === 'undefined'
}
1 change: 1 addition & 0 deletions packages/cli-kit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"include": ["./src/**/*.ts", "decs.d.ts", "./src/**/*.tsx"],
"exclude": ["./dist"],
"compilerOptions": {
"lib": ["ES2020", "DOM"],
"outDir": "dist",
"rootDir": "src",
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo"
Expand Down
21 changes: 19 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@ import HelpCommand from './cli/commands/help.js'
import List from './cli/commands/notifications/list.js'
import Generate from './cli/commands/notifications/generate.js'
import ClearCache from './cli/commands/cache/clear.js'
import ThemeCommands from '@shopify/theme'
import {versionService} from './cli/services/commands/version.js'
import ThemeCommands, {list} from '@shopify/theme'
import {COMMANDS as HydrogenCommands, HOOKS as HydrogenHooks} from '@shopify/cli-hydrogen'
import {commands as AppCommands} from '@shopify/app'
import {
init,
selectDeveloperPlatformClient,
appFromId,
selectOrg,
versionList,
commands as AppCommands,
} from '@shopify/app'
import {commands as PluginCommandsCommands} from '@oclif/plugin-commands'
import {commands as PluginPluginsCommands} from '@oclif/plugin-plugins'
import {DidYouMeanCommands} from '@shopify/plugin-did-you-mean'
import {runCLI} from '@shopify/cli-kit/node/cli'
import {renderFatalError} from '@shopify/cli-kit/node/ui'
import {FatalError} from '@shopify/cli-kit/node/error'
import {ensureAuthenticatedPartners} from '@shopify/cli-kit/node/session'
import fs from 'fs'

export {DidYouMeanHook} from '@shopify/plugin-did-you-mean'
Expand Down Expand Up @@ -138,4 +147,12 @@ export const COMMANDS: any = {
'cache:clear': ClearCache,
}

export {list as themeList}
export {ensureAuthenticatedPartners}
export {selectDeveloperPlatformClient}
export {appFromId}
export {selectOrg}
export {versionList}
export {init as appInit}
export {versionService}
export default runShopifyCLI
10 changes: 7 additions & 3 deletions packages/theme/src/cli/services/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ interface Options {
name?: string
id?: number
json: boolean
ignoreDevelopmentThemes?: boolean
}

export async function list(adminSession: AdminSession, options: Options) {
export async function list(adminSession: AdminSession, options: Options): Promise<string> {
const store = adminSession.storeFqdn
const filter = new Filter({
...ALLOWED_ROLES.reduce((roles: FilterProps, role) => {
Expand All @@ -25,14 +26,16 @@ export async function list(adminSession: AdminSession, options: Options) {
})

let storeThemes = await fetchStoreThemes(adminSession)
const developmentTheme = getDevelopmentTheme()
const developmentTheme = options.ignoreDevelopmentThemes ? undefined : getDevelopmentTheme()
const hostTheme = getHostTheme(store)
if (filter.any()) {
storeThemes = filterThemes(store, storeThemes, filter)
}

const themesJson = JSON.stringify(storeThemes, null, 2)
if (options.json) {
return outputInfo(JSON.stringify(storeThemes, null, 2))
outputInfo(themesJson)
return themesJson
}

const themes = storeThemes.map(({id, name, role}) => {
Expand All @@ -51,4 +54,5 @@ export async function list(adminSession: AdminSession, options: Options) {
})

renderTable({rows: themes, columns})
return themesJson
}
1 change: 1 addition & 0 deletions packages/theme/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ export {ensureValidPassword} from './cli/utilities/theme-environment/storefront-
// Expose core utilities for developers to build and expand on the CLI
export {pull} from './cli/services/pull.js'
export {push} from './cli/services/push.js'
export {list} from './cli/services/list.js'
export {publicFetchStoreThemes as fetchStoreThemes} from './cli/utilities/theme-selector/fetch.js'
Loading