Skip to content

Commit 284ccc9

Browse files
authored
Initial commit
0 parents  commit 284ccc9

File tree

9 files changed

+301
-0
lines changed

9 files changed

+301
-0
lines changed

.devcontainer/devcontainer.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/devcontainers/images/tree/main/src/javascript-node
3+
{
4+
"name": "PyScript Site with GitHub Codespaces",
5+
"image": "mcr.microsoft.com/devcontainers/universal:2",
6+
"hostRequirements": {
7+
"cpus": 4
8+
},
9+
"waitFor": "onCreateCommand",
10+
"updateContentCommand": "",
11+
"postCreateCommand": "",
12+
"postAttachCommand": "",
13+
14+
// Configure tool-specific properties.
15+
"customizations": {
16+
// Configure properties specific to VS Code.
17+
"vscode": {
18+
// Add the IDs of extensions you want installed when the container is created.
19+
"extensions": [
20+
"ritwickdey.LiveServer",
21+
"ms-python.python",
22+
"GitHub.copilot"
23+
],
24+
"settings": {
25+
"emmet.includeLanguages": {
26+
"razor": "html"
27+
},
28+
"emmet.triggerExpansionOnTab": true
29+
}
30+
}
31+
},
32+
33+
"features": {
34+
"ghcr.io/devcontainers/features/github-cli:1": {},
35+
}
36+
}

.github/pull_request_template.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!--
2+
This repository does not accept pull requests through the normal process.
3+
PRs without the 'pre-approved' label will be automatically closed. If you are learning about this repository
4+
and are following the steps, then you need to make changes in your own account.
5+
6+
If you need this PR to be merged, you have two options:
7+
8+
1. Label this PR with the 'pre-approved' label if you have admin or enough privileges
9+
10+
or
11+
12+
2. Tag alfredodeza to take a look
13+
14+
Thank you for your understanding!
15+
-->
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Auto close pull requests
2+
on:
3+
pull_request_target:
4+
types: [opened, labeled, unlabeled, reopened]
5+
6+
jobs:
7+
auto_close:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
13+
- name: Close PR if not pre-approved
14+
if: ${{ !(contains(github.event.pull_request.labels.*.name, 'pre-approved')) && !(contains(github.event.pull_request.body, '@alfredodeza')) }}
15+
run: |
16+
MESSAGE="This repository doesn't accept pull requests. Please fork the repository and make changes there. If you really need this PR to be merged you must be an admin and label this pr with the 'pre-approved' label *or* tag Alfredo Deza (\`@alfredodeza\`) to take a look."
17+
gh pr close ${{ github.event.pull_request.number }} --repo education/codespaces-project-template-js --comment "$MESSAGE"
18+
env:
19+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Build files generated from Parcel
6+
dist
7+
8+
# Dependency directories
9+
node_modules/
10+
11+
# Optional npm cache directory
12+
.npm
13+
14+
# Optional eslint cache
15+
.eslintcache
16+
17+
# dotenv environment variables file
18+
.env
19+
.env.test
20+
21+
# parcel-bundler cache (https://parceljs.org/)
22+
.parcel-cache
23+
24+
.DS_Store

README.md

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=816765904)
2+
3+
# 🐍📜 PyScript with GitHub Codespaces and Copilot
4+
5+
_Create, customize and deploy your own [PyScript](https://pyscript.net)
6+
website in minutes._
7+
8+
In this template repository we have the development environment and base set
9+
and ready to go. So that you can immediately launch your
10+
[Codespace](https://github.com/features/codespaces/) environment and start
11+
customizing your site using [Copilot](https://copilot.github.com) to help you
12+
write code faster.
13+
14+
* **Who is this for?** __Anyone__ looking to create a
15+
[PyScript](https://pyscript.net/) site, learn web development, or test out
16+
Codespaces.
17+
* **How much experience do you need?** __Zero__. You decide how much you want
18+
to customize based on your experience, and time available.
19+
* **Tools needed:** _None_. No need to install anything! All you need is a web
20+
browser.
21+
* **Prerequisites:** _None_. This template includes your development
22+
environment and deployable web app for you to create your own site.
23+
24+
## About this PyScript template
25+
26+
This template includes the minimal viable PyScript application, from which you
27+
can build.
28+
29+
### Quick Start
30+
31+
1. Click the **Use this Template** button and then **Create a new repository** as can be seen in the image below.
32+
Note: Make sure you've signed in to GitHub otherwise, you wouldn't see the **Use this Template** button.
33+
![PyScript web application](https://raw.githubusercontent.com/education/codespaces-project-template-js/main/__images__/use-this-template.png "Use this Template Image Guide")
34+
1. Select the repository owner (e.g. your GitHub account)
35+
1. Enter a unique name for your new repository
36+
1. Click the **Code** button
37+
1. Click **Create Codespace on main** button
38+
1. Customize your PyScript site with Copilot
39+
1. [Deploy your site](#-deploy-your-web-application)
40+
41+
<details>
42+
<summary><b>🎥 To learn more about Codespaces, watch our video tutorial series</b></summary>
43+
44+
[![Codespaces Tutorial](https://img.youtube.com/vi/ozuDPmcC1io/0.jpg)](https://aka.ms/CodespacesVideoTutorial "Codespaces Tutorial")
45+
</details>
46+
47+
## 🗃️ PyScript template
48+
49+
This repo is a GitHub template to build a PyScript web application. The goal is
50+
to give you a template that you can immediately utilize to create your own
51+
PyScript website through Codespaces.
52+
53+
The repo contains the following:
54+
55+
* `.devcontainer/devcontainer.json`: Configuration file used by Codespaces to
56+
configure Visual Studio Code settings, such as the enabling of additional
57+
extensions.
58+
* `config.json`: the
59+
[PyScript configuration](https://docs.pyscript.net/2024.6.1/user-guide/configuration/)
60+
used by your application.
61+
* `index.html`: the
62+
[HTML page](https://docs.pyscript.net/2024.6.1/user-guide/first-steps/)
63+
used to load your PyScript application.
64+
* `main.py`: the [Python script](https://pyscript.net/) to run.
65+
* `mini-coi.js`: a
66+
[utility](https://docs.pyscript.net/2024.6.1/user-guide/workers/#http-headers)
67+
to ensure all PyScript's features are available.
68+
* `README.md`: this file (that you're reading right now).
69+
70+
## 🚀 Getting started
71+
72+
This PyScript project contains everything you need so that you can immediately
73+
open Codespaces, see it running, and deploy at any point.
74+
75+
Your development environment is all set for you to start.
76+
77+
* Visual Studio Code with the [Python plugin](https://code.visualstudio.com/docs/languages/python) enabled.
78+
* The [LiveServer](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) plugin (so you can view your site).
79+
* GitHub [copilot support](https://github.com/features/copilot) (if you have it enabled for your account).
80+
81+
### Create your PyScript app
82+
83+
1. Create a repository from this template. Use this
84+
[create repo link](https://github.com/ntoll/codespaces-project-template-pyscript/generate).
85+
Select the repository owner, provide a name, a description if you'd like and
86+
if you'd like the new repository to be public or private.
87+
1. Before creating the Codespace, enable GitHub Copilot for your account.
88+
1. Navigate to the main page of the newly created repository.
89+
3. Under the repository name, use the Code drop-down menu, and in the
90+
Codespaces tab, select "Create codespace on main".
91+
4. Wait as GitHub initializes the Codespace.
92+
5. When complete you will see your Codespace load with a terminal section at
93+
the bottom. Codespaces will install all the required extensions in your
94+
container. Once the package installs are completed, you'll be able to start
95+
editing and start a LiveServer to see your site.
96+
97+
## 🏃 Deploy your web application
98+
99+
Project includes the setup needed for you to deploy **FREE** to either
100+
[Azure Static Web Apps](https://azure.microsoft.com/products/app-service/static/?WT.mc_id=academic-79839-sagibbon)
101+
_**or**_ [GitHub Pages](https://pages.github.com/)</a>. Instructions are
102+
included below for Azure. The following YouTube video demonstrates how to get
103+
your Codespace up and running, then deployed to GitHub Pages in under two
104+
minutes:
105+
106+
[![PyScript to Github pages in 2 minutes.](https://img.youtube.com/vi/dmIWFcJ2UTI/0.jpg)](https://www.youtube.com/watch?v=dmIWFcJ2UTI)
107+
108+
### Azure Static Web Apps
109+
110+
[Azure Static Web Apps](https://azure.microsoft.com/products/app-service/static/?WT.mc_id=academic-79839-sagibbon)
111+
is Microsoft's hosting solution for static sites (or sites that are rendered in
112+
the user's browser, not on a server) through Azure. This service provides
113+
additional opportunities to expand your site through Azure Functions,
114+
authentication, staging versions and more.
115+
116+
You'll need both Azure and GitHub accounts to deploy your web application. If
117+
you don't yet have an Azure account you can create it from within during the
118+
deploy process, or from below links:
119+
120+
* [Create a (no Credit Card required) Azure For Students account](https://azure.microsoft.com/free/students/?WT.mc_id=academic-79839-sagibbon)
121+
* [Create a new Azure account](https://azure.microsoft.com/?WT.mc_id=academic-79839-sagibbon)
122+
123+
With your project open in Codespaces:
124+
125+
1. Click Azure icon in the left sidebar. Log in if you are not already, and if
126+
new to Azure, follow the prompts to create your account.
127+
1. From Azure menu click “+” sign and then “Create Static Web App”.
128+
1. If you are not logged into GitHub you will be prompted to log in. If you
129+
have any pending file changes you will then be prompted to commit those
130+
changes.
131+
1. Set your application information when prompted:
132+
1. **Region**: pick the one closest to you
133+
1. **Project structure**: select "React"
134+
1. **Location of application code**: `/`
135+
1. **Build location**: `dist`
136+
1. When complete you will see a notification at the bottom of your screen, and
137+
a new GitHub Action workflow will be added to your project. If you click
138+
“Open Action in GitHub” you will see the action that was created for you,
139+
and it is currently running.
140+
![Azure Static Web App deploy](https://github.com/education/codespaces-project-template-js/raw/main/__images__/swa-deploy.gif "Azure Static Web App deploy")
141+
1. To view the status of your deployment, find your Static Web App resource in
142+
the Azure tab in the VS Code left side bar.
143+
1. Once deployment is complete, you can view your brand new new publicly
144+
accessible application by right clicking on your Static Web App resource and
145+
selecting "Browse Site".
146+
147+
> **Issues?** When creating your Static Web app, if you are prompted to select
148+
> an Azure subscription and are not able to select a subscription, check the
149+
> "Accounts" tab in VS Code. Make sure to choose the "Grant access to ..."
150+
> options if those options appear. Should you receive the error-message
151+
> "RepositoryToken is invalid. ..." switch to Visual Studio Code for the Web
152+
> (vscode.dev) and repeat the steps there.
153+
154+
> 🤩 **Bonus**: [Setup a custom domain for your Azure Static Web App](https://learn.microsoft.com/en-us/shows/azure-tips-and-tricks-static-web-apps/how-to-set-up-a-custom-domain-name-in-azure-static-web-apps-10-of-16--azure-tips-and-tricks-static-w/?WT.mc_id=academic-79839-sagibbon)
155+
156+
## 🔎 Found an issue or have an idea for improvement?
157+
Help us make this template repository better by [letting us know and opening an issue!](/../../issues/new).

config.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

index.html

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<script src="/mini-coi.js" scope="./"></script>
5+
<title>PyScript Application Template</title>
6+
7+
<!-- Recommended meta tags -->
8+
<meta charset="UTF-8">
9+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
10+
11+
<!-- PyScript CSS -->
12+
<link rel="stylesheet" href="https://pyscript.net/releases/2024.6.1/core.css">
13+
14+
<!-- This script tag bootstraps PyScript -->
15+
<script type="module" src="https://pyscript.net/releases/2024.6.1/core.js"></script>
16+
</head>
17+
<body>
18+
<script type="mpy" src="./main.py" config="./config.json" terminal></script>
19+
</body>
20+
</html>

main.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello, world!")

mini-coi.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*! coi-serviceworker v0.1.7 - Guido Zuidhof and contributors, licensed under MIT */
2+
/*! mini-coi - Andrea Giammarchi and contributors, licensed under MIT */
3+
(({ document: d, navigator: { serviceWorker: s } }) => {
4+
if (d) {
5+
const { currentScript: c } = d;
6+
s.register(c.src, { scope: c.getAttribute('scope') || '.' }).then(r => {
7+
r.addEventListener('updatefound', () => location.reload());
8+
if (r.active && !s.controller) location.reload();
9+
});
10+
}
11+
else {
12+
addEventListener('install', () => skipWaiting());
13+
addEventListener('activate', e => e.waitUntil(clients.claim()));
14+
addEventListener('fetch', e => {
15+
const { request: r } = e;
16+
if (r.cache === 'only-if-cached' && r.mode !== 'same-origin') return;
17+
e.respondWith(fetch(r).then(r => {
18+
const { body, status, statusText } = r;
19+
if (!status || status > 399) return r;
20+
const h = new Headers(r.headers);
21+
h.set('Cross-Origin-Opener-Policy', 'same-origin');
22+
h.set('Cross-Origin-Embedder-Policy', 'require-corp');
23+
h.set('Cross-Origin-Resource-Policy', 'cross-origin');
24+
return new Response(body, { status, statusText, headers: h });
25+
}));
26+
});
27+
}
28+
})(self);

0 commit comments

Comments
 (0)