-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'trunk' of github.com:WordPress/playground-tools into up…
…date/playground-dependencies
- Loading branch information
Showing
8 changed files
with
200 additions
and
102 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
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
36 changes: 36 additions & 0 deletions
36
packages/wordpress-playground-block/src/components/playground-preview/write-theme-files.ts
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,36 @@ | ||
import type { EditorFile } from '../../index'; | ||
import { | ||
PlaygroundClient, | ||
activateTheme, | ||
// @ts-ignore | ||
} from 'https://playground.wordpress.net/client/index.js'; | ||
|
||
export const writeThemeFiles = async ( | ||
client: PlaygroundClient, | ||
files: EditorFile[] | ||
) => { | ||
const docroot = await client.documentRoot; | ||
const themeFolderName = 'demo-theme'; | ||
const themePath = docroot + '/wp-content/themes/' + themeFolderName; | ||
if (await client.fileExists(themePath)) { | ||
await client.rmdir(themePath, { | ||
recursive: true, | ||
}); | ||
} | ||
await client.mkdir(themePath); | ||
|
||
for (const file of files) { | ||
const filePath = `${themePath}/${file.name}`; | ||
const parentDir = filePath.split('/').slice(0, -1).join('/'); | ||
await client.mkdir(parentDir); | ||
await client.writeFile(filePath, file.contents); | ||
} | ||
|
||
try { | ||
await activateTheme(client, { | ||
themeFolderName, | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}; |
Oops, something went wrong.