-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for generating a d2l.dev app
- Loading branch information
1 parent
dfe93bc
commit 1083378
Showing
17 changed files
with
487 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import path from 'path'; | ||
import { copyAndProcessDir, getDestinationPath, replaceTextPlugin, movePlugin } from '../../helper.js'; | ||
Check failure on line 2 in src/generators/d2ldev/index.js GitHub Actions / Test
|
||
|
||
export function run(templateData) { | ||
const templateRoot = path.join(__dirname, 'templates'); | ||
const destinationRoot = getDestinationPath(templateData.hyphenatedName); | ||
|
||
const elementFile = `${templateData.hyphenatedName}.js`; | ||
copyAndProcessDir(templateRoot, destinationRoot, [ | ||
movePlugin({ | ||
'_package.json': 'package.json', | ||
'_gitignore': '.gitignore', | ||
'_CODEOWNERS': 'CODEOWNERS', | ||
'_README.md': 'README.md', | ||
'src/components/_element.js': `src/components/${elementFile}` | ||
}), | ||
replaceTextPlugin({ | ||
'_package.json': templateData, | ||
'_CODEOWNERS': templateData, | ||
'_README.md': templateData, | ||
'.github/workflows/publish.yml': templateData, | ||
'src/index.html': templateData, | ||
'src/index.js': { | ||
...templateData, | ||
elementFile | ||
}, | ||
'src/components/_element.js': templateData, | ||
}) | ||
]); | ||
} |
40 changes: 40 additions & 0 deletions
40
src/generators/d2ldev/templates/.github/workflows/publish.yml
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,40 @@ | ||
name: Publish | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- '[0-9]+.x' | ||
- '[0-9]+.[0-9]+.x' | ||
jobs: | ||
publish: | ||
name: Publish | ||
runs-on: [self-hosted, AWS, Linux] | ||
timeout-minutes: 10 | ||
steps: | ||
- name: Checkout | ||
uses: Brightspace/third-party-actions@actions/checkout | ||
- name: Setup Node | ||
uses: Brightspace/third-party-actions@actions/setup-node | ||
with: | ||
node-version-file: .nvmrc | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Build | ||
run: npm run build | ||
|
||
- name: Assume role | ||
if: github.ref == 'refs/heads/main' | ||
uses: Brightspace/third-party-actions@aws-actions/configure-aws-credentials | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} | ||
role-to-assume: "arn:aws:iam::022062736489:role/r+<%= githubOrg %>+<%= repoName %>+repo" | ||
role-duration-seconds: 3600 | ||
aws-region: ca-central-1 | ||
|
||
- name: Publish | ||
uses: BrightspaceUI/actions/publish-to-s3@main | ||
with: | ||
bucket-path: s3://d2l.dev/<%= subdomain %>/main | ||
publish-directory: ./dist/ |
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 @@ | ||
20 |
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 @@ | ||
* <%= codeowners %> |
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,12 @@ | ||
# <%= hyphenatedName %> | ||
|
||
## Developing and Contributing | ||
|
||
* Clone the repo | ||
* Run `npx d2l-npm-login` to support private npm packages (note: this requires your Okta credentials) | ||
* Run `npm install` to install dependencies | ||
* Run `npm start` to run the local web-dev-server | ||
|
||
## Releasing | ||
|
||
After merging your code changes to the `main` branch, the `Publish` Github action will run and publish your changes to [<%= subdomain %>.d2l.dev](https://<%= subdomain %>.d2l.dev/). |
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,3 @@ | ||
node_modules/ | ||
package-lock.json | ||
dist/ |
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,28 @@ | ||
{ | ||
"name": "<%= hyphenatedName %>", | ||
"description": "<%= description %>", | ||
"type": "module", | ||
"repository": "https://github.com/<%= githubOrg %>/<%= repoName %>.git", | ||
"scripts": { | ||
"start": "web-dev-server --watch", | ||
"build": "rimraf dist && rollup -c rollup.config.js" | ||
}, | ||
"keywords": [], | ||
"author": "D2L Corporation", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@brightspace-ui/core": "^3", | ||
"lit": "^3" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-dynamic-import-vars": "^2", | ||
"@rollup/plugin-node-resolve": "^15", | ||
"@rollup/plugin-replace": "^5", | ||
"@rollup/plugin-terser": "^0", | ||
"@web/dev-server": "^0", | ||
"@web/dev-server-rollup": "^0", | ||
"@web/rollup-plugin-html": "^2", | ||
"rimraf": "^5", | ||
"rollup": "^4" | ||
} | ||
} |
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,40 @@ | ||
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars'; | ||
import replace from '@rollup/plugin-replace'; | ||
import resolve from '@rollup/plugin-node-resolve'; | ||
import { rollupPluginHTML as html } from '@web/rollup-plugin-html'; | ||
import terser from '@rollup/plugin-terser'; | ||
|
||
import { prodConfig } from './shared.config.js'; | ||
|
||
export default { | ||
input: './src/index.html', | ||
output: { | ||
dir: 'dist', | ||
entryFileNames: '[hash].js', | ||
chunkFileNames: '[hash].js', | ||
assetFileNames: '[hash][extname]', | ||
}, | ||
plugins: [ | ||
replace({ | ||
// The buildConfig replace is set up to only work in the buildConfig.js file in order to limit the use of undefined (i.e. magic-y) variables | ||
include: ['./src/**/buildConfig.js'], | ||
preventAssignment: true, | ||
values: { | ||
__buildConfig__: JSON.stringify(prodConfig), | ||
}, | ||
}), | ||
resolve(), | ||
html({ | ||
minify: true, | ||
input: './src/index.html', | ||
}), | ||
|
||
/* | ||
dynamicImportVars is required in order to properly handle | ||
dynamic imports for @brightspace-ui/core's localization. | ||
*/ | ||
dynamicImportVars(), | ||
|
||
terser(), | ||
], | ||
}; |
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,7 @@ | ||
export const devConfig = { | ||
development: true, | ||
}; | ||
|
||
export const prodConfig = { | ||
development: false, | ||
}; |
36 changes: 36 additions & 0 deletions
36
src/generators/d2ldev/templates/src/components/_element.js
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 { css, html, LitElement } from 'lit'; | ||
import '@brightspace-ui/core/components/alert/alert.js'; | ||
import buildConfig from '../utilities/buildConfig.js'; | ||
|
||
class <%= className %> extends LitElement { | ||
|
||
static get properties() { | ||
return { | ||
prop1: { type: String }, | ||
}; | ||
} | ||
|
||
static get styles() { | ||
return css` | ||
:host([hidden]) { | ||
display: none; | ||
} | ||
`; | ||
} | ||
|
||
constructor() { | ||
super(); | ||
|
||
this.prop1 = '<%= hyphenatedName %>'; | ||
} | ||
|
||
render() { | ||
return html` | ||
Hello ${this.prop1}! | ||
<d2l-alert type="default"> | ||
Development: ${buildConfig.development ? 'True' : 'False'} | ||
</d2l-alert> | ||
`; | ||
} | ||
} | ||
customElements.define('<%= tagName %>', <%= className %>); |
Oops, something went wrong.