Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(raw-helper): raw blocks to handle unprocessed blocks #58

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

<!-- START mdmod {use: 'toc'} -->


- [✨ Create Create App](#-create-create-app)
- [Why?](#why)
- [Table of contents](#table-of-contents)
Expand All @@ -40,6 +39,7 @@
- [`kebab`](#kebab)
- [`space`](#space)
- [`uuid`](#uuid)
- [`raw-helper`](#raw-helper)
- [Config](#config)
- [templateRoot (required)](#templateroot-required)
- [modifyName (default: `undefined`)](#modifyname-default-undefined)
Expand Down Expand Up @@ -188,6 +188,22 @@ Generates unique UUID string.
{{upper (uuid)}} // => A5DF7100-DA46-47A6-907E-AFE861F48B39
```

#### `raw`

Raw blocks to handle unprocessed blocks.

```
{{{{raw}}}}
{{bar}}
{{{{/raw}}}}
```

will render

```
{{bar}}
```

## Config

The app configuration can be found in `src/cli.js` (or `src/cli.ts` if you choose the `typescript` template).
Expand Down
10 changes: 10 additions & 0 deletions src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ function uuid() {
}
Handlebars.registerHelper('uuid', uuid);

function rawHelper(options: Handlebars.HelperDeclareSpec) {
return options.fn();
}
Handlebars.registerHelper('raw-helper', rawHelper);

function raw(option: Handlebars.HelperDeclareSpec) {
return option.fn();
}
Handlebars.registerHelper('raw', raw);

function format<T>(text: Buffer | string, view: T) {
const template = Handlebars.compile(text.toString(), { noEscape: true });
return template(view);
Expand Down
83 changes: 83 additions & 0 deletions templates/default/.github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{{{{raw-helper}}}}
name: Unit Test
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
build:
environment: dev
runs-on: ubuntu-latest
env:
MY_KEY: hello_ci # ${{ secrets.MY_KEY }}
strategy:
matrix:
node-version: [16.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "command=install" >> $GITHUB_OUTPUT
echo "runner=yarn" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/package.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
exit 0
else
echo "Unable to determine packager manager"
exit 1
fi
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: Restore cache
uses: actions/cache@v3
with:
path: |
node_modules
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
restore-keys: |
${{ runner.os }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
- name: Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: Type Check
env:
NODE_OPTIONS: "--max_old_space_size=4096"
run: ${{ steps.detect-package-manager.outputs.runner }} typecheck
- name: Unit Test
env:
NODE_OPTIONS: "--max_old_space_size=4096"
run: ${{ steps.detect-package-manager.outputs.runner }} test --collectCoverage
- name: Code Coverage Summary
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: coverage/cobertura-coverage.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: "60 80"
- name: Build
env:
CI: false
run: ${{ steps.detect-package-manager.outputs.runner }} build
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
append: true
path: code-coverage-results.md
{{{{/raw-helper}}}}
82 changes: 82 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,88 @@ 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.
`);
const newRawHelper = readFileSync(`${tmpDir}/create-greet/.github/workflows/unit-test.yml`, 'utf-8');
expect(newRawHelper).toBe('name: Unit Test\n' +
'on:\n' +
' push:\n' +
' branches: ["main"]\n' +
' pull_request:\n' +
' branches: ["main"]\n' +
'jobs:\n' +
' build:\n' +
' environment: dev\n' +
' runs-on: ubuntu-latest\n' +
' env:\n' +
' MY_KEY: hello_ci # ${{ secrets.MY_KEY }}\n' +
' strategy:\n' +
' matrix:\n' +
' node-version: [16.x]\n' +
' steps:\n' +
' - name: Checkout\n' +
' uses: actions/checkout@v3\n' +
' - name: Detect package manager\n' +
' id: detect-package-manager\n' +
' run: |\n' +
' if [ -f "${{ github.workspace }}/yarn.lock" ]; then\n' +
' echo "manager=yarn" >> $GITHUB_OUTPUT\n' +
' echo "command=install" >> $GITHUB_OUTPUT\n' +
' echo "runner=yarn" >> $GITHUB_OUTPUT\n' +
' exit 0\n' +
' elif [ -f "${{ github.workspace }}/package.json" ]; then\n' +
' echo "manager=npm" >> $GITHUB_OUTPUT\n' +
' echo "command=ci" >> $GITHUB_OUTPUT\n' +
' echo "runner=npx --no-install" >> $GITHUB_OUTPUT\n' +
' exit 0\n' +
' else\n' +
' echo "Unable to determine packager manager"\n' +
' exit 1\n' +
' fi\n' +
' - name: Use Node.js ${{ matrix.node-version }}\n' +
' uses: actions/setup-node@v3\n' +
' with:\n' +
' node-version: ${{ matrix.node-version }}\n' +
' cache: ${{ steps.detect-package-manager.outputs.manager }}\n' +
' - name: Restore cache\n' +
' uses: actions/cache@v3\n' +
' with:\n' +
' path: |\n' +
' node_modules\n' +
" key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}\n" +
' restore-keys: |\n' +
" ${{ runner.os }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-\n" +
' - name: Install dependencies\n' +
' run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}\n' +
' - name: Type Check\n' +
' env:\n' +
' NODE_OPTIONS: "--max_old_space_size=4096"\n' +
' run: ${{ steps.detect-package-manager.outputs.runner }} typecheck\n' +
' - name: Unit Test\n' +
' env:\n' +
' NODE_OPTIONS: "--max_old_space_size=4096"\n' +
' run: ${{ steps.detect-package-manager.outputs.runner }} test --collectCoverage\n' +
' - name: Code Coverage Summary\n' +
' uses: irongut/CodeCoverageSummary@v1.3.0\n' +
' with:\n' +
' filename: coverage/cobertura-coverage.xml\n' +
' badge: true\n' +
' fail_below_min: true\n' +
' format: markdown\n' +
' hide_branch_rate: false\n' +
' hide_complexity: true\n' +
' indicators: true\n' +
' output: both\n' +
' thresholds: "60 80"\n' +
' - name: Build\n' +
' env:\n' +
' CI: false\n' +
' run: ${{ steps.detect-package-manager.outputs.runner }} build\n' +
' - name: Add Coverage PR Comment\n' +
' uses: marocchino/sticky-pull-request-comment@v2\n' +
" if: github.event_name == 'pull_request'\n" +
' with:\n' +
' recreate: true\n' +
' append: true\n' +
' path: code-coverage-results.md\n')
}, 300000);

test('create typescript project', async () => {
Expand Down