@initweb-fr/datacamp 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,246 @@
1
+ # Finsweet Developer Starter
2
+
3
+ A starter template for both Client & Power projects.
4
+
5
+ Before starting to work with this template, please take some time to read through the documentation.
6
+
7
+ ## Reference
8
+
9
+ - [Included tools](#included-tools)
10
+ - [Requirements](#requirements)
11
+ - [Getting started](#getting-started)
12
+ - [Installing](#installing)
13
+ - [Building](#building)
14
+ - [Serving files on development mode](#serving-files-on-development-mode)
15
+ - [Building multiple files](#building-multiple-files)
16
+ - [Setting up a path alias](#setting-up-a-path-alias)
17
+ - [Contributing guide](#contributing-guide)
18
+ - [Pre-defined scripts](#pre-defined-scripts)
19
+ - [CI/CD](#cicd)
20
+ - [Continuous Integration](#continuous-integration)
21
+ - [Continuous Deployment](#continuous-deployment)
22
+ - [How to automatically deploy updates to npm](#how-to-automatically-deploy-updates-to-npm)
23
+
24
+ ## Included tools
25
+
26
+ This template contains some preconfigured development tools:
27
+
28
+ - [Typescript](https://www.typescriptlang.org/): A superset of Javascript that adds an additional layer of Typings, bringing more security and efficiency to the written code.
29
+ - [Prettier](https://prettier.io/): Code formatting that assures consistency across all Finsweet's projects.
30
+ - [ESLint](https://eslint.org/): Code linting that enforces industries' best practices. It uses [our own custom configuration](https://github.com/finsweet/eslint-config) to maintain consistency across all Finsweet's projects.
31
+ - [Playwright](https://playwright.dev/): Fast and reliable end-to-end testing.
32
+ - [esbuild](https://esbuild.github.io/): Javascript bundler that compiles, bundles and minifies the original Typescript files.
33
+ - [Changesets](https://github.com/changesets/changesets): A way to manage your versioning and changelogs.
34
+ - [Finsweet's TypeScript Utils](https://github.com/finsweet/ts-utils): Some utilities to help you in your Webflow development.
35
+
36
+ ## Requirements
37
+
38
+ This template requires the use of [pnpm](https://pnpm.js.org/en/). You can [install pnpm](https://pnpm.io/installation) with:
39
+
40
+ ```bash
41
+ npm i -g pnpm
42
+ ```
43
+
44
+ To enable automatic deployments to npm, please read the [Continuous Deployment](#continuous-deployment) section.
45
+
46
+ ## Getting started
47
+
48
+ The quickest way to start developing a new project is by [creating a new repository from this template](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template#creating-a-repository-from-a-template).
49
+
50
+ Once the new repository has been created, update the `package.json` file with the correct information, specially the name of the package which has to be unique.
51
+
52
+ ### Installing
53
+
54
+ After creating the new repository, open it in your terminal and install the packages by running:
55
+
56
+ ```bash
57
+ pnpm install
58
+ ```
59
+
60
+ If this is the first time using Playwright and you want to use it in this project, you'll also have to install the browsers by running:
61
+
62
+ ```bash
63
+ pnpm playwright install
64
+ ```
65
+
66
+ You can read more about the use of Playwright in the [Testing](#testing) section.
67
+
68
+ It is also recommended that you install the following extensions in your VSCode editor:
69
+
70
+ - [Prettier - Code formatter](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
71
+ - [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
72
+
73
+ ### Building
74
+
75
+ To build the files, you have two defined scripts:
76
+
77
+ - `pnpm dev`: Builds and creates a local server that serves all files (check [Serving files on development mode](#serving-files-on-development-mode) for more info).
78
+ - `pnpm build`: Builds to the production directory (`dist`).
79
+
80
+ ### Serving files on development mode
81
+
82
+ When you run `pnpm dev`, two things happen:
83
+
84
+ - esbuild is set to `watch` mode. Every time that you save your files, the project will be rebuilt.
85
+ - A local server is created under `http://localhost:3000` that serves all your project files. You can import them in your Webflow projects like:
86
+
87
+ ```html
88
+ <script defer src="http://localhost:3000/{FILE_PATH}.js"></script>
89
+ ```
90
+
91
+ - Live Reloading is enabled by default, meaning that every time you save a change in your files, the website you're working on will reload automatically. You can disable it in `/bin/build.js`.
92
+
93
+ ### Building multiple files
94
+
95
+ If you need to build multiple files into different outputs, you can do it by updating the build settings.
96
+
97
+ In `bin/build.js`, update the `ENTRY_POINTS` array with any files you'd like to build:
98
+
99
+ ```javascript
100
+ const ENTRY_POINTS = [
101
+ 'src/home/index.ts',
102
+ 'src/contact/whatever.ts',
103
+ 'src/hooyah.ts',
104
+ 'src/home/other.ts',
105
+ ];
106
+ ```
107
+
108
+ This will tell `esbuild` to build all those files and output them in the `dist` folder for production and in `http://localhost:3000` for development.
109
+
110
+ ### Building CSS files
111
+
112
+ CSS files are also supported by the bundler. When including a CSS file as an entry point, the compiler will generate a minified version in your output folder.
113
+
114
+ You can define a CSS entry point by either:
115
+
116
+ - Manually defining it in the `bin/build.js` config. [See previous section](#building-multiple-files) for reference.
117
+ - Or importing the file inside any of your JavaScript / TypeScript files:
118
+
119
+ ```typescript
120
+ // src/index.ts
121
+ import './index.css';
122
+ ```
123
+
124
+ CSS outputs are also available in `localhost` during [development mode](#serving-files-on-development-mode).
125
+
126
+ ### Setting up a path alias
127
+
128
+ Path aliases are very helpful to avoid code like:
129
+
130
+ ```typescript
131
+ import example from '../../../../utils/example';
132
+ ```
133
+
134
+ Instead, we can create path aliases that map to a specific folder, so the code becomes cleaner like:
135
+
136
+ ```typescript
137
+ import example from '$utils/example';
138
+ ```
139
+
140
+ You can set up path aliases using the `paths` setting in `tsconfig.json`. This template has an already predefined path as an example:
141
+
142
+ ```json
143
+ {
144
+ "paths": {
145
+ "$utils/*": ["src/utils/*"]
146
+ }
147
+ }
148
+ ```
149
+
150
+ To avoid any surprises, take some time to familiarize yourself with the [tsconfig](/tsconfig.json) enabled flags.
151
+
152
+ ## Testing
153
+
154
+ As previously mentioned, this library has [Playwright](https://playwright.dev/) included as an automated testing tool.
155
+
156
+ All tests are located under the `/tests` folder. This template includes a test spec example that will help you catch up with Playwright.
157
+
158
+ After [installing the dependencies](#installing), you can try it out by running `pnpm test`.
159
+ Make sure you replace it with your own tests! Writing proper tests will help improve the maintainability and scalability of your project in the long term.
160
+
161
+ By default, Playwright will also run `pnpm dev` in the background while the tests are running, so [your files served](#serving-files-on-development-mode) under `localhost:3000` will run as usual.
162
+ You can disable this behavior in the `playwright.config.ts` file.
163
+
164
+ If you project doesn't require any testing, you should disable the Tests job in the [CI workflow](#continuous-integration) by commenting it out in the `.github/workflows/ci.yml` file.
165
+ This will prevent the tests from running when you open a Pull Request.
166
+
167
+ ## Contributing guide
168
+
169
+ In general, your development workflow should look like this:
170
+
171
+ 1. Create a new branch where to develop a new feature or bug fix.
172
+ 2. Once you've finished the implementation, [create a Changeset](#continuous-deployment) (or multiple) explaining the changes that you've made in the codebase.
173
+ 3. Open a Pull Request and wait until the [CI workflows](#continuous-integration) finish. If something fails, please try to fix it before merging the PR.
174
+ If you don't want to wait for the CI workflows to run on GitHub to know if something fails, it will be always faster to run them in your machine before opening a PR.
175
+ 4. Merge the Pull Request. The Changesets bot will automatically open a new PR with updates to the `CHANGELOG.md`, you should also merge that one. If you have [automatic npm deployments](#how-to-automatically-deploy-updates-to-npm) enabled, Changesets will also publish this new version on npm.
176
+
177
+ If you need to work on several features before publishing a new version on npm, it is a good practise to create a `development` branch where to merge all the PR's before pushing your code to master.
178
+
179
+ ## Pre-defined scripts
180
+
181
+ This template contains a set of predefined scripts in the `package.json` file:
182
+
183
+ - `pnpm dev`: Builds and creates a local server that serves all files (check [Serving files on development mode](#serving-files-on-development-mode) for more info).
184
+ - `pnpm build`: Builds to the production directory (`dist`).
185
+ - `pnpm lint`: Scans the codebase with ESLint and Prettier to see if there are any errors.
186
+ - `pnpm lint:fix`: Fixes all auto-fixable issues in ESLint.
187
+ - `pnpm check`: Checks for TypeScript errors in the codebase.
188
+ - `pnpm format`: Formats all the files in the codebase using Prettier. You probably won't need this script if you have automatic [formatting on save](https://www.digitalocean.com/community/tutorials/code-formatting-with-prettier-in-visual-studio-code#automatically-format-on-save) active in your editor.
189
+ - `pnpm test`: Will run all the tests that are located in the `/tests` folder.
190
+ - `pnpm test:headed`: Will run all the tests that are located in the `/tests` folder visually in headed browsers.
191
+ - `pnpm release`: This command is defined for [Changesets](https://github.com/changesets/changesets). You don't have to interact with it.
192
+ - `pnpm run update`: Scans the dependencies of the project and provides an interactive UI to select the ones that you want to update.
193
+
194
+ ## CI/CD
195
+
196
+ This template contains a set of helpers with proper CI/CD workflows.
197
+
198
+ ### Continuous Integration
199
+
200
+ When you open a Pull Request, a Continuous Integration workflow will run to:
201
+
202
+ - Lint & check your code. It uses the `pnpm lint` and `pnpm check` commands under the hood.
203
+ - Run the automated tests. It uses the `pnpm test` command under the hood.
204
+
205
+ If any of these jobs fail, you will get a warning in your Pull Request and should try to fix your code accordingly.
206
+
207
+ **Note:** If your project doesn't contain any defined tests in the `/tests` folder, you can skip the Tests workflow job by commenting it out in the `.github/workflows/ci.yml` file. This will significantly improve the workflow running times.
208
+
209
+ ### Continuous Deployment
210
+
211
+ [Changesets](https://github.com/changesets/changesets) allows us to generate automatic changelog updates when merging a Pull Request to the `master` branch.
212
+
213
+ Before starting, make sure to [enable full compatibility with Changesets in the repository](#how-to-enable-continuous-deployment-with-changesets).
214
+
215
+ To generate a new changelog, run:
216
+
217
+ ```bash
218
+ pnpm changeset
219
+ ```
220
+
221
+ You'll be prompted with a few questions to complete the changelog.
222
+
223
+ Once the Pull Request is merged into `master`, a new Pull Request will automatically be opened by a changesets bot that bumps the package version and updates the `CHANGELOG.md` file.
224
+ You'll have to manually merge this new PR to complete the workflow.
225
+
226
+ You can set up Changesets to automatically deploy the new package version to npm.
227
+ See [how to automatically deploy updates to npm](#how-to-automatically-deploy-updates-to-npm) for more info.
228
+
229
+ #### How to enable Continuous Deployment with Changesets
230
+
231
+ Some repositories may not have the required permissions to let Changesets interact with the repository.
232
+
233
+ To enable full compatibility with Changesets, go to the repository settings (`Settings > Actions > General > Workflow Permissions`) and define:
234
+
235
+ - ✅ Read and write permissions.
236
+ - ✅ Allow GitHub Actions to create and approve pull requests.
237
+
238
+ Enabling this setting for your organization account (`Account Settings > Actions > General`) could help streamline the process. By doing so, any new repos created under the org will automatically inherit the setting, which can save your teammates time and effort. This can only be applied to organization accounts at the time.
239
+
240
+ #### How to automatically deploy updates to npm
241
+
242
+ The `Release` GitHub Action uses OpenID Connect to authenticate with npm, allowing automatic deployments without the need to store any secret in your repository.
243
+
244
+ To enable deployments to npm, [configure the GitHub repository as a Trusted Publisher](https://docs.npmjs.com/trusted-publishers) and Changesets will take care of the rest.
245
+
246
+ If this is the first time deploying to npm from this repository, you might need to [manually publish the first version of the package](https://docs.npmjs.com/creating-and-publishing-scoped-public-packages#publishing-scoped-public-packages).
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(()=>{var r=(e=document)=>{let o="Last Published:";for(let t of e.childNodes)if(t.nodeType===Node.COMMENT_NODE&&t.textContent?.includes(o)){let n=t.textContent.trim().split(o)[1];if(n)return new Date(n)}};var s=e=>{let o=r();console.log(`Hello ${e}!`),console.log(`This site was last published on ${o?.toLocaleDateString("en-US",{year:"numeric",month:"long",day:"2-digit"})}.`)};window.Webflow||(window.Webflow=[]);window.Webflow.push(()=>{s("John Doe")});})();
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@initweb-fr/datacamp",
3
+ "version": "0.0.0",
4
+ "description": "Custom Code for Datacamp Webflow Ecosystem.",
5
+ "homepage": "https://github.com/initweb-fr/datacamp#readme",
6
+ "license": "ISC",
7
+ "keywords": [],
8
+ "author": {
9
+ "name": "initWeb",
10
+ "url": "https://initweb.fr/"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/initweb-fr/datacamp.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/initweb-fr/datacamp/issues"
18
+ },
19
+ "type": "module",
20
+ "main": "src/index.ts",
21
+ "module": "src/index.ts",
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "packageManager": "pnpm@10.11.0",
26
+ "scripts": {
27
+ "dev": "cross-env NODE_ENV=development node ./bin/build.js",
28
+ "build": "cross-env NODE_ENV=production node ./bin/build.js",
29
+ "lint": "eslint ./src && prettier --check ./src",
30
+ "lint:fix": "eslint ./src --fix",
31
+ "check": "tsc --noEmit",
32
+ "format": "prettier --write ./src",
33
+ "test": "playwright test",
34
+ "test:ui": "playwright test --ui",
35
+ "release": "changeset publish",
36
+ "update": "pnpm update -i -L -r"
37
+ },
38
+ "devDependencies": {
39
+ "@changesets/changelog-git": "^0.2.0",
40
+ "@changesets/cli": "^2.27.12",
41
+ "@eslint/js": "^9.19.0",
42
+ "@finsweet/eslint-config": "^3.0.3",
43
+ "@finsweet/tsconfig": "^1.4.2",
44
+ "@playwright/test": "^1.50.1",
45
+ "cross-env": "^7.0.3",
46
+ "esbuild": "^0.24.2",
47
+ "eslint": "^9.19.0",
48
+ "eslint-config-prettier": "^10.0.1",
49
+ "eslint-plugin-prettier": "^5.2.3",
50
+ "eslint-plugin-simple-import-sort": "^12.1.1",
51
+ "prettier": "^3.4.2",
52
+ "typescript": "^5.7.3",
53
+ "typescript-eslint": "^8.23.0"
54
+ },
55
+ "dependencies": {
56
+ "@finsweet/ts-utils": "^0.40.0"
57
+ },
58
+ "engines": {
59
+ "pnpm": ">=10"
60
+ },
61
+ "publishConfig": {
62
+ "provenance": false
63
+ }
64
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ window.Webflow ||= [];
2
+ window.Webflow.push(() => {});