-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLI] Whisper Starter added to CLI (#4729)
fixes #4728 <!-- Link to relevant issue (for ex: "fixes #1234") which will automatically close the issue once the PR is merged --> ## PR Type <!-- Please uncomment one ore more that apply to this PR --> <!-- - Bugfix --> Feature <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## Describe the new behavior? Whisper starter has been added as a starter option ## PR Checklist - [x ] Test: run `npm run test` and ensure that all tests pass - [ x] Target main branch (or an appropriate release branch if appropriate for a bug fix) - [ x] Ensure that your contribution follows [standard accessibility guidelines](https://docs.microsoft.com/en-us/microsoft-edge/accessibility/design). Use tools like https://webhint.io/ to validate your changes. ## Additional Information --------- Co-authored-by: Zach Teutsch <[email protected]>
- Loading branch information
Showing
8 changed files
with
134 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import os from 'os'; | ||
import * as fs from 'fs'; | ||
import { doesFileExist } from '../util/fileUtil'; | ||
import { PWABuilderData, createUserDataAndWrite } from '../analytics/usage-analytics'; | ||
import { outputMessage } from './util'; | ||
import { formatCodeSnippet, formatEmphasis, formatEmphasisStrong } from './textUtil'; | ||
import * as prompts from "@clack/prompts"; | ||
|
||
const whisperDisplayText: string = formatCodeSnippet(`${formatEmphasis("Want to start using AI on the web?")} We just added a new starter template! | ||
The new whisper template includes a Whisper transcription model to get you started with building AI-empowered progressive web apps! | ||
Run ${formatEmphasisStrong("pwa create -t=whisper myWhisperPWA")} to pull the new template. | ||
`); | ||
|
||
export var WHISPER_CAMPAIGN: Campaign = { | ||
name: "whisper", | ||
displayed: false, | ||
displayText: whisperDisplayText | ||
} | ||
|
||
export type Campaign = { | ||
name: string, | ||
displayed: boolean, | ||
displayText: string | ||
} | ||
|
||
export type CampaignMap = { | ||
[key: string] : Campaign | ||
} | ||
|
||
|
||
export function handleCampaign(campaign: Campaign) { | ||
const pwabuilderDataFilePath: string = os.homedir() + "/.pwabuilder"; | ||
var userData: PWABuilderData; | ||
if(doesFileExist(pwabuilderDataFilePath)) { | ||
userData = JSON.parse(fs.readFileSync(pwabuilderDataFilePath, {encoding: 'utf-8'})); | ||
} else { | ||
userData = createUserDataAndWrite(pwabuilderDataFilePath); | ||
} | ||
|
||
handleShowCampaign(userData, campaign); | ||
} | ||
|
||
function doesCampaignExist(userData: PWABuilderData, campaignKey: string) { | ||
return userData.campaignMap && campaignKey in userData.campaignMap; | ||
} | ||
|
||
function addCampaign(userData: PWABuilderData, campaign: Campaign): PWABuilderData { | ||
if(doesCampaignExist(userData, campaign.name)) { | ||
return userData; | ||
} | ||
|
||
if(!userData.campaignMap) { | ||
userData.campaignMap = {}; | ||
} | ||
userData.campaignMap[campaign.name] = campaign; | ||
|
||
return userData; | ||
} | ||
|
||
function handleShowCampaign(userData: PWABuilderData, campaign: Campaign) { | ||
var userDataWithCampaign: PWABuilderData = addCampaign(userData, campaign); | ||
if(userDataWithCampaign.campaignMap && !userDataWithCampaign.campaignMap[campaign.name].displayed) { | ||
outputMessage(campaign.displayText); | ||
campaign.displayed = true; | ||
userDataWithCampaign.campaignMap[campaign.name] = campaign; | ||
rewritePWABuilderDataFile(userDataWithCampaign) | ||
} | ||
} | ||
|
||
function rewritePWABuilderDataFile(userData: PWABuilderData) { | ||
const pwabuilderDataFilePath: string = os.homedir() + "/.pwabuilder"; | ||
fs.writeFileSync(pwabuilderDataFilePath, JSON.stringify(userData), {encoding: 'utf-8'}); | ||
} |