From 2fac4792f75ef871179c5ef16e3e892727d95399 Mon Sep 17 00:00:00 2001 From: Matt Potts Date: Sat, 23 Jan 2021 15:01:58 +0000 Subject: [PATCH] Initial commit --- .github/workflows/get-includes.js | 2 + .github/workflows/get-version.js | 2 + .github/workflows/main.yml | 78 +++++++++++++++++++++++++++++++ .gitignore | 1 + LICENSE.MIT | 21 +++++++++ README.md | 47 +++++++++++++++++++ dist/README.md | 38 +++++++++++++++ dist/lang/en.json | 0 dist/module.json | 54 +++++++++++++++++++++ dist/scripts/module.js | 0 dist/styles/module.css | 0 gulpfile.ts | 37 +++++++++++++++ package.json | 20 ++++++++ src/lang/en.json | 0 src/module.json | 55 ++++++++++++++++++++++ src/scripts/module.ts | 0 src/styles/module.css | 0 src/tsconfig.json | 12 +++++ tsconfig.json | 13 ++++++ 19 files changed, 380 insertions(+) create mode 100644 .github/workflows/get-includes.js create mode 100644 .github/workflows/get-version.js create mode 100644 .github/workflows/main.yml create mode 100644 .gitignore create mode 100644 LICENSE.MIT create mode 100644 README.md create mode 100644 dist/README.md create mode 100644 dist/lang/en.json create mode 100644 dist/module.json create mode 100644 dist/scripts/module.js create mode 100644 dist/styles/module.css create mode 100644 gulpfile.ts create mode 100644 package.json create mode 100644 src/lang/en.json create mode 100644 src/module.json create mode 100644 src/scripts/module.ts create mode 100644 src/styles/module.css create mode 100644 src/tsconfig.json create mode 100644 tsconfig.json diff --git a/.github/workflows/get-includes.js b/.github/workflows/get-includes.js new file mode 100644 index 00000000..f1cc6bb2 --- /dev/null +++ b/.github/workflows/get-includes.js @@ -0,0 +1,2 @@ +var fs = require('fs'); +console.log(JSON.parse(fs.readFileSync('dist/module.json', 'utf8')).includes.join(" ")); diff --git a/.github/workflows/get-version.js b/.github/workflows/get-version.js new file mode 100644 index 00000000..f35c4191 --- /dev/null +++ b/.github/workflows/get-version.js @@ -0,0 +1,2 @@ +var fs = require('fs'); +console.log(JSON.parse(fs.readFileSync('dist/module.json', 'utf8')).version); diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..270d2e6d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,78 @@ +name: Module CI/CD + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + # Get the version from 'module.json' + - name: Get Version + shell: bash + id: get-version + run: echo "::set-output name=version::$(node ./.github/workflows/get-version.js)" + + # Get the name from 'module.json' + - name: Get Includes + shell: bash + id: get-includes + run: echo "::set-output name=files::$(node ./.github/workflows/get-includes.js)" + + # create a zip file with all files required by the module to add to the release + - name: Zip Files + working-directory: ./dist #SORRY BUT YOU HAVE TO USE DIST JUST LIKE GET OVER IT OR FIGURE OUT A BETTER WAY + run: zip -r ../module.zip ${{steps.get-includes.outputs.files}} + + #Useful only for the template so we can leave the manifest and download urls empty + - name: Substitute Manifest and Download Links For Versioned Ones + id: sub_manifest_link_latest + uses: microsoft/variable-substitution@v1 + with: + files: './dist/module.json' + env: + url: https://github.com/${{github.repository}} + manifest: https://github.com/${{github.repository}}/releases/latest/download/module.json + download: https://github.com/${{github.repository}}/releases/latest/download/module.zip + + # Update the 'latest' release + - name: Update Latest Release + id: create_latest_release + uses: ncipollo/release-action@v1 + if: endsWith(github.ref, 'master') + with: + allowUpdates: true + name: Latest + draft: false + prerelease: false + token: ${{ secrets.GITHUB_TOKEN }} + artifacts: './dist/module.json, ./module.zip' + tag: latest + + #Substitute the Manifest and Download URLs in the module.json + - name: Substitute Manifest and Download Links For Versioned Ones + id: sub_manifest_link_version + uses: microsoft/variable-substitution@v1 + with: + files: './dist/module.json' + env: + url: https://github.com/${{github.repository}} + manifest: https://github.com/${{github.repository}}/releases/latest/download/module.json + download: https://github.com/${{github.repository}}/releases/download/${{steps.get-version.outputs.version}}/module.zip + + # Create a release for this specific version + - name: Create Version Release + id: create_version_release + uses: ncipollo/release-action@v1 + with: + allowUpdates: true # set this to false if you want to prevent updating existing releases + name: Release ${{ steps.get-version.outputs.version }} + draft: false + prerelease: false + token: ${{ secrets.GITHUB_TOKEN }} + artifacts: './dist/module.json,./module.zip' + tag: ${{ steps.get-version.outputs.version }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..40b878db --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/LICENSE.MIT b/LICENSE.MIT new file mode 100644 index 00000000..38ebca20 --- /dev/null +++ b/LICENSE.MIT @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Spacemandev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 00000000..93c7a91e --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +![](https://img.shields.io/badge/Foundry-v0.7.9-informational) + + + + + + + + +# Changelog +*Please for the love of all that you hold dear, do everyone a favor and include a changelog here rather than making people guess at the capabilities of your module since last release* + +# Description +This is a typescript template to get you started. This is not intended for beginners. + +Please use the javascript template as necessary for your stuff. + + +## Manifest Plus +Adds the following fields to the manifest for package browsers to pick up and show information better: + +``` +- includes: [] # list of files to include in the zip +- icon: "" # link to icon img +- cover: "" #link to cover img +- screenshots: [] #links to screenshot images +- video: "" +- authors: [ + { + "name": "name", + "email": "email", + "discord": "discord" + } +] + +``` + + +## Versioned Releases + +The Github Actions script will automatically create a Latest release which will always have a module.json that points to the latest release, and a versioned release whenever you update the version in your module.json. + +This allows people who depend on a specific version of your module to just install that and be version locked. The versioned releases will *not* auto update. + + +# License +MIT License. Do what you will. PRs welcome. diff --git a/dist/README.md b/dist/README.md new file mode 100644 index 00000000..95077a14 --- /dev/null +++ b/dist/README.md @@ -0,0 +1,38 @@ +# Changelog +*Please for the love of all that you hold dear, do everyone a favor and include a changelog here rather than making people guess at the capabilities of your module since last release* + +# Description +This is a typescript template to get you started. This is not intended for beginners. + +Please use the javascript template as necessary for your stuff. + + +## Manifest Plus +Adds the following fields to the manifest for package browsers to pick up and show information better: + +``` +- includes: [] # list of files to include in the zip +- icon: "" # link to icon img +- cover: "" #link to cover img +- screenshots: [] #links to screenshot images +- video: "" +- authors: [ + { + "name": "name", + "email": "email", + "discord": "discord" + } +] + +``` + + +## Versioned Releases + +The Github Actions script will automatically create a Latest release which will always have a module.json that points to the latest release, and a versioned release whenever you update the version in your module.json. + +This allows people who depend on a specific version of your module to just install that and be version locked. The versioned releases will *not* auto update. + + +# License +MIT License. Do what you will. PRs welcome. diff --git a/dist/lang/en.json b/dist/lang/en.json new file mode 100644 index 00000000..e69de29b diff --git a/dist/module.json b/dist/module.json new file mode 100644 index 00000000..00a77433 --- /dev/null +++ b/dist/module.json @@ -0,0 +1,54 @@ +{ + "name": "foundry-typescript-template", + "title": "Typescript Template", + "description": "", + "authors": [ + { + "name": "spacemandev", + "discord": "spacemandev#6256" + } + ], + "version": "0.0.1", + "minimumCoreVersion": "0.6.0", + "compatibleCoreVersion": "0.7.2", + "url": "", + "manifest": "", + "download": "", + "type": "module", + "includes": [ + "./assets/**", + "./lang/**", + "./scripts/**", + "./styles/**", + "./templates/**", + "./module.json", + "./README.md" + ], + "media": [ + { + "type": "icon", + "location": "" + }, + { + "type": "cover", + "location": "" + }, + { + "type": "screenshot", + "location": "" + } + ], + "esmodules": [ + "scripts/module.js" + ], + "styles": [ + "styles/module.css" + ], + "languages": [ + { + "lang": "en", + "name": "English", + "path": "lang/en.json" + } + ] +} \ No newline at end of file diff --git a/dist/scripts/module.js b/dist/scripts/module.js new file mode 100644 index 00000000..e69de29b diff --git a/dist/styles/module.css b/dist/styles/module.css new file mode 100644 index 00000000..e69de29b diff --git a/gulpfile.ts b/gulpfile.ts new file mode 100644 index 00000000..705e960b --- /dev/null +++ b/gulpfile.ts @@ -0,0 +1,37 @@ +const gulp = require('gulp') +const ts = require('gulp-typescript'); +const project = ts.createProject('tsconfig.json') + + +gulp.task('compile', () => { + return gulp.src('src/**/*.ts') + .pipe(project()) + .pipe(gulp.dest('dist/')) +}) + +gulp.task('copy', async () => { + return new Promise((resolve,reject) => { + gulp.src('README.md').pipe(gulp.dest("dist/")) + gulp.src("src/module.json").pipe(gulp.dest('dist/')) + gulp.src("src/lang/**").pipe(gulp.dest('dist/lang/')) + gulp.src("src/templates/**").pipe(gulp.dest('dist/templates/')) + gulp.src("src/styles/**").pipe(gulp.dest('dist/styles/')) + gulp.src("src/assets/**").pipe(gulp.dest('dist/assets/')) + resolve(); + }) +}) + +gulp.task('build', gulp.parallel('compile', 'copy')); + + +/* +// This is supposed to copy the dist folder into the modules directory for testing. Only works if you've set it up the right way +//This works if development path is FoundryVTT/Data/dev/modules/swade-item-macros +const MODULEPATH = "../../../modules/swade-item-macros/" + +gulp.task('foundry', () => { + return gulp.src('dist/**').pipe(gulp.dest(MODULEPATH)) +}) + +gulp.task("update", gulp.series('build', 'foundry')) +*/ diff --git a/package.json b/package.json new file mode 100644 index 00000000..70c74203 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "foundry-typescript-template", + "version": "1.0.0", + "description": "Foundry VTT Typescript Template", + "main": "index.js", + "scripts": { + "build": "gulp build" + }, + "author": "", + "license": "MIT", + "devDependencies": { + "gulp": "^4.0.2", + "gulp-typescript": "^6.0.0-alpha.1" + }, + "dependencies": { + "@types/node": "^14.10.1", + "foundry-pc-types": "gitlab:foundry-projects/foundry-pc/foundry-pc-types", + "typescript": "^4.0.2" + } +} diff --git a/src/lang/en.json b/src/lang/en.json new file mode 100644 index 00000000..e69de29b diff --git a/src/module.json b/src/module.json new file mode 100644 index 00000000..f74a6d0d --- /dev/null +++ b/src/module.json @@ -0,0 +1,55 @@ +{ + "name": "foundry-typescript-template", + "title": "Typescript Template", + "description": "", + "authors": [ + { + "name": "spacemandev", + "discord": "spacemandev#6256" + } + ], + "version": "0.0.1", + "minimumCoreVersion": "0.7.9", + "compatibleCoreVersion": "0.7.9", + "manifestPlusVersion": "1.0.0", + "url": "", + "manifest": "", + "download": "", + "type": "module", + "includes": [ + "./assets/**", + "./lang/**", + "./scripts/**", + "./styles/**", + "./templates/**", + "./module.json", + "./README.md" + ], + "media": [ + { + "type": "icon", + "location": "" + }, + { + "type": "cover", + "location": "" + }, + { + "type": "screenshot", + "location": "" + } + ], + "esmodules": [ + "scripts/module.js" + ], + "styles": [ + "styles/module.css" + ], + "languages": [ + { + "lang": "en", + "name": "English", + "path": "lang/en.json" + } + ] +} diff --git a/src/scripts/module.ts b/src/scripts/module.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/styles/module.css b/src/styles/module.css new file mode 100644 index 00000000..e69de29b diff --git a/src/tsconfig.json b/src/tsconfig.json new file mode 100644 index 00000000..10a4f65d --- /dev/null +++ b/src/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "moduleResolution": "node", + "target": "ES6", + "lib": ["DOM", "ES6", "ES2017", "ES2018"], + "types": ["foundry-pc-types", "node"], + "allowUmdGlobalAccess": true + }, + "exclude": [ + "node_modules" + ] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..86336fe0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "moduleResolution": "node", + "target": "ES6", + "lib": ["DOM", "ES6", "ES2017", "ES2018"], + "types": ["foundry-pc-types", "node"], + "allowUmdGlobalAccess": true + }, + "files": ["./gulpfile.ts"], + "exclude": [ + "node_modules" + ] +} \ No newline at end of file