Skip to content

Commit

Permalink
Types (Scribouilli#106)
Browse files Browse the repository at this point in the history
* Mise en place de TypeScript

* correction des types pur utils.js

* Correction des types de actions.js

* Correction types buidStatus

* Correction types config.js

* Correction types databaseAPI

* Correction types routeComponentLifeCycle.js

* Rajout de types minimaux de l'API github

* Correction de types du store

* Correction des types des routes

* Correction des types des routes

* Correction des types sur les composants Svelte
---------

Co-authored-by: Fanny Cheung <[email protected]>
  • Loading branch information
DavidBruant and Ynote authored Nov 2, 2023
1 parent 1e1af8a commit 20358a3
Show file tree
Hide file tree
Showing 36 changed files with 899 additions and 486 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Build and Deploy
on:
on:
push:
branches:
- principale
Expand All @@ -15,9 +15,10 @@ jobs:

- name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built.
run: |
npm install
npm pkg delete scripts.prepare
npm ci --omit=dev
npm run build
- name: Add and commit
run: |
git config user.name github-actions
Expand All @@ -31,4 +32,4 @@ jobs:
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: online
force: true
force: true
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
npx lint-staged

npx svelte-check

npx tsc
20 changes: 16 additions & 4 deletions assets/scripts/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ export const getCurrentRepoArticles = () => {
.catch(msg => handleErrors(msg))
}

/**
*
* @param {string} owner
* @param {string} repo
* @returns {Promise<any>}
*/
export const setupRepo = (owner, repo) => databaseAPI.setupRepo(owner, repo)

/**
Expand All @@ -134,6 +140,7 @@ export const setupRepo = (owner, repo) => databaseAPI.setupRepo(owner, repo)
* but also the build status and the site repo config. If the user is not
* logged in, it redirects to the authentication page.
*
* @param {string} querystring
* @returns {Promise<void>}
*/
export const setCurrentRepositoryFromQuerystring = async querystring => {
Expand Down Expand Up @@ -208,13 +215,18 @@ export const setBuildStatus = (owner, repoName) => {
*/
export const createRepositoryForCurrentAccount = async repoName => {
const login = await store.state.login

if(!login){
throw new TypeError(`login manquant dans createRepositoryForCurrentAccount`)
}

const escapedRepoName = repoName
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.replace(/[^a-zA-Z0-9_-]+/g, '-')
.toLowerCase()

const waitRepoReady = new Promise((resolve, reject) => {
const waitRepoReady = /** @type {Promise<void>} */(new Promise((resolve) => {
const timer = setInterval(() => {
databaseAPI.checkRepoReady(login, escapedRepoName).then(res => {
if (res) {
Expand All @@ -223,9 +235,9 @@ export const createRepositoryForCurrentAccount = async repoName => {
}
})
}, 1000)
})
}))

const waitGithubPages = new Promise((resolve, reject) => {
const waitGithubPages = /** @type {Promise<void>} */(new Promise((resolve) => {
const timer = setInterval(() => {
databaseAPI.checkGithubPages(login, escapedRepoName).then(res => {
if (res) {
Expand All @@ -234,7 +246,7 @@ export const createRepositoryForCurrentAccount = async repoName => {
}
})
}, 5000)
})
}))
return databaseAPI
.createDefaultRepository(login, escapedRepoName)
.then(() => {
Expand Down
15 changes: 13 additions & 2 deletions assets/scripts/buildStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,22 @@ Voir `databaseAPI.getLastDeployment(login, repoName)` et `databaseAPI.getDeploym
*/

/**
* @typedef {"building" | "built" | "errored"} BuildStatus
*/

/**
*
* @param {string} owner
* @param {string} repoName
* @returns
*/
export default function (owner, repoName) {
/** @type {"building" | "built" | "errored"} */
/** @type {BuildStatus} */
let repoStatus = 'building'
let reaction = undefined
/** @type {(status: BuildStatus) => any} */
let reaction
/** @type {ReturnType<setTimeout> | undefined} */
let timeout

function scheduleCheck(delay = 5000) {
Expand All @@ -79,6 +85,10 @@ export default function (owner, repoName) {
get status() {
return repoStatus
},
/**
*
* @param {(status: BuildStatus) => any} callback
*/
subscribe(callback) {
console.log('subscribe reaction.. ', callback)
reaction = callback
Expand Down Expand Up @@ -116,6 +126,7 @@ export default function (owner, repoName) {
},
setBuildingAndCheckStatusLater(t = 30000) {
repoStatus = 'building'
// @ts-ignore
clearTimeout(timeout)
timeout = undefined
scheduleCheck(t)
Expand Down
18 changes: 17 additions & 1 deletion assets/scripts/components/Header.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<script>
// @ts-check
/** @type {any} */
export let buildStatus
/** @typedef {import("./../store.js").ScribouilliState} ScribouilliState */
/** @type {ScribouilliState["currentRepository"] | undefined} */
export let currentRepository
/** @type {boolean} */
export let showArticles
/** @type {string} */
let status
$: status = buildStatus?.status
if (buildStatus) {
// @ts-ignore
buildStatus.subscribe(s => {
if (s) {
status = s
Expand All @@ -18,15 +26,23 @@
$: buildStatusClass = buildStatus ? `build-${status}` : undefined
/** @type {string | undefined} */
let publishedWebsiteURL
$: publishedWebsiteURL = currentRepository?.publishedWebsiteURL
/** @type {string | undefined} */
let repositoryURL
$: repositoryURL = currentRepository?.repositoryURL
/** @type {string | undefined} */
let repoName
$: repoName = currentRepository?.name
/** @type {string | undefined} */
let account
$: account = currentRepository?.owner
/** @type {string | undefined} */
$: homeURL =
repoName && account
? `./atelier-list-pages?repoName=${repoName}&account=${account}`
Expand Down
6 changes: 6 additions & 0 deletions assets/scripts/components/Skeleton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
import Header from "./Header.svelte";
import Footer from "./Footer.svelte";
/** @type {boolean} */
export let showArticles = false;
/** @type {any} */
export let buildStatus = undefined;
/** @typedef {import("./../store.js").ScribouilliState} ScribouilliState */
/** @type {ScribouilliState["currentRepository"] | undefined} */
export let currentRepository = undefined;
</script>

Expand Down
2 changes: 2 additions & 0 deletions assets/scripts/components/screens/AfterGithubLogin.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<script>
import Skeleton from "./../Skeleton.svelte";
import SiteCreationLoader from "./../loaders/SiteCreationLoader.svelte";
import '../../../types.js'
/** @type {Promise<GithubRepository[]|Void>} */
export let currentUserReposP;
</script>

Expand Down
11 changes: 11 additions & 0 deletions assets/scripts/components/screens/ArticleContenu.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
<script>
import {makeAtelierListArticlesURL} from '../../routes/atelier-list-articles.js'
import '../../../types.js'
/** @type {Promise<EditeurFile>} */
export let fileP;
/** @type any */
export let buildStatus;
/** @type {FileContenu[]} */
export let contenus;
/** @type {boolean} */
export let showArticles;
/** @typedef {import("./../../store.js").ScribouilliState} ScribouilliState */
/** @type ScribouilliState["currentRepository"] */
export let currentRepository;
import Editeur from "./intern/Editeur.svelte";
Expand Down
8 changes: 8 additions & 0 deletions assets/scripts/components/screens/AtelierArticles.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<script>
import ListContenu from './intern/ListContenu.svelte'
/** @type any */
export let buildStatus
/** @type {any[] | undefined} */
export let articles
/** @type {boolean | undefined} */
export let showArticles
/** @typedef {import("./../../store.js").ScribouilliState} ScribouilliState */
/** @type ScribouilliState["currentRepository"] */
export let currentRepository
</script>

Expand Down
8 changes: 8 additions & 0 deletions assets/scripts/components/screens/AtelierPages.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<script>
import ListContenu from './intern/ListContenu.svelte'
/** @type any */
export let buildStatus
/** @type {any[] | undefined} */
export let pages
/** @type {boolean | undefined} */
export let showArticles
/** @typedef {import("./../../store.js").ScribouilliState} ScribouilliState */
/** @type ScribouilliState["currentRepository"] */
export let currentRepository
</script>

Expand Down
1 change: 1 addition & 0 deletions assets/scripts/components/screens/CreateNewSite.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
let loading = false;
let hasError = false
// @ts-ignore
const onSubmit = (e) => {
e.preventDefault();
Expand Down
1 change: 1 addition & 0 deletions assets/scripts/components/screens/Login.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import Skeleton from "../Skeleton.svelte";
/** @type {string} */
export let href;
</script>

Expand Down
11 changes: 11 additions & 0 deletions assets/scripts/components/screens/PageContenu.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
<script>
import {makeAtelierListPageURL} from '../../routes/atelier-list-pages.js'
import '../../../types.js'
/** @type {Promise<EditeurFile>} */
export let fileP;
/** @type any */
export let buildStatus;
/** @type {FileContenu[]} */
export let contenus;
/** @type {boolean} */
export let showArticles
/** @typedef {import("./../../store.js").ScribouilliState} ScribouilliState */
/** @type ScribouilliState["currentRepository"] */
export let currentRepository;
import Editeur from "./intern/Editeur.svelte";
Expand Down
8 changes: 8 additions & 0 deletions assets/scripts/components/screens/SelectCurrentSite.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
import Loader from "./../loaders/Loader.svelte";
import { setupRepo } from "../../actions";
/** @type {string | Promise<string> | undefined} */
export let currentAccount
/** typedef {import("../../../types").GithubRepository} GithubRepository */
/** @type {GithubRepository[]} */
export let currentAccountRepositories;
/** @type {GithubRepository} */
let repo
let loading = false;
// @ts-ignore
const displayRepoName = repo => {
if (repo.owner.login === currentAccount) {
return repo.name
Expand All @@ -20,6 +27,7 @@
}
}
// @ts-ignore
const onSubmit = (e) => {
e.preventDefault();
Expand Down
Loading

0 comments on commit 20358a3

Please sign in to comment.