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

Feature/v2 exploration #2

Merged
merged 17 commits into from
Jun 8, 2024
Merged
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
2 changes: 0 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# EditorConfig is awesome: https://EditorConfig.org

root = true

[*]
Expand Down
35 changes: 35 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"env": {
"node": true,
"es6": true
},
"extends": [
"eslint:recommended"
],
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"ignorePatterns": [
".github/**/*",
".vscode/**/*",
"node_modules/**/*",
"examples/**/*",
"tests/**/*",
"tmp/**/*",
".editorconfig",
".gitignore",
".npmignore",
".nvmrc",
"package-lock.json",
"README.md"
],
"rules": {
"indent": ["error", "tab", { "SwitchCase": 1 }],
"eol-last": ["error", "always"],
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"no-console": ["error", { "allow": ["info", "warn", "error", "clear"] }]
}
}


42 changes: 42 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Publish

on:
release:
types:
- published

jobs:
publish:
name: Publish
runs-on: ubuntu-latest

# Initialize the env variables. These get set after the repo is checked out
# because they depend on files in the repo.
env:
NODE_VERSION: ''

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it.
- name: Checkout Repo
id: checkout_repo
uses: actions/checkout@v4

# Sets the environment variables from the env.sh script.
- name: Set Environment Variables
id: set_env_vars
run: .github/workflows/scripts/env.sh

# Setup Node.
- name: Setup Node
id: setup_node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'

# Publish public package to NPM.
- name: Publish
id: publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Release

on:
push:
branches:
- main

jobs:
release:
name: Release
runs-on: ubuntu-latest

# Initialize the env variables. These get set after the repo is checked out
# because they depend on files in the repo.
env:
MODULE_VERSION: ''

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it.
- name: Checkout Repo
id: checkout_repo
uses: actions/checkout@v4

# Sets the environment variables from the env.sh script.
- name: Set Environment Variables
id: set_env_vars
run: .github/workflows/scripts/env.sh

# Creates a release draft.
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
with:
name: ${{ env.MODULE_VERSION }}
tag: ${{ env.MODULE_VERSION }}
commit: main
draft: true
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}
generateReleaseNotes: true
skipIfReleaseExists: true
18 changes: 18 additions & 0 deletions .github/workflows/scripts/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# This file must have permissions to run in a GitHub action.
# To do this cross-env, use the following command from the project root:
# git update-index --chmod=+x .github/workflows/scripts/env.sh

# Get the node version from the .nvmrc file.

NODE_VERSION=$(cat .nvmrc)

# Get the module version from the package.json file.

MODULE_VERSION=$(jq -r ".version" package.json)

# Set environment variables on $GITHUB_ENV.

echo "NODE_VERSION=$(echo $NODE_VERSION)" >> $GITHUB_ENV
echo "MODULE_VERSION=$(echo $MODULE_VERSION)" >> $GITHUB_ENV
50 changes: 50 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Test

on:
pull_request:
branches:
- main

jobs:
test:
name: Test
runs-on: ubuntu-latest

# Initialize the env variables. These get set after the repo is checked out
# because they depend on files in the repo.
env:
NODE_VERSION: ''

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it.
- name: Checkout Repo
id: checkout_repo
uses: actions/checkout@v4

# Sets the environment variables from the env.sh script.
- name: Set Environment Variables
id: set_env_vars
run: .github/workflows/scripts/env.sh

# Setup Node.
- name: Setup Node
id: setup_node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

# Installs npm and composer dependencies.
- name: Install
id: install
run: npm ci

# Lint all files.
- name: Lint
id: lint
run: npm run lint

# Runs a test component creation with the `verbose`
# option to true for debugging.
- name: Create Component
id: create_component
run: npm test TestComponent -- -v
16 changes: 14 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Deps

node_modules/
examples/components/*
!examples/components/_Template/

# Tests

tests/

# Temp

tmp/

# Logs

logs/
19 changes: 18 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Config

.github/
.vscode/
.editorconfig
.eslintrc
.gitignore
.npmignore
README.md
.nvmrc

# Deps

node_modules/

# Tests

examples/
tests/

# Logs

logs/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"editorconfig.editorconfig",
"dbaeumer.vscode-eslint",
"github.vscode-github-actions"
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"[javascript][typescript][javascriptreact][typescriptreact]": {
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
}
},
"files.insertFinalNewline": true,
"files.eol": "\n",
"eslint.validate": ["js", "jsx", "ts", "tsx", "mjs"],
"eslint.enable": true,
}
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ The scripts `name` arg can be passed through to the script when running it throu
}
```

> **Note:** If your templates live outside of the directory you want them to be created in, use the `-o` or `--outputPath` option to set the output path.

### 3. Run the scripts

Given the scripts created in step #2 above, run them as follows ― being sure to provide a component name after the script name. These commands will clone the `_Template` directory in each of the corresponding project directories and will perform replacements both on the file names themselves as well as on the text content within the files.
Expand Down Expand Up @@ -112,12 +114,17 @@ npx @dreamsicle.io/create-component --help
**The above would ouput the following help information:**

```
Usage: npx @dreamsicle.io/create-component [options] <name>
Usage: npx @dreamsicle.io/create-component [options] <name>

Create a templated component structure.

Create a React component in the appropriate components directory.
Arguments:
name The name of the component

Options:
-V, --version output the version number
-p, --path <path> The relative path where the template to be used lives.
-h, --help display help for command
-V, --version output the version number
-p, --path <path> The relative path where the template to be used lives
-o, --outputPath [path] The relative path where the component should be placed, if different from the template path
-v, --verbose Output extra information to the console (default: false)
-h, --help display help for command
```
6 changes: 6 additions & 0 deletions examples/components/_Template/unmodified.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* This tests an unmodified file.
*/
function testUnmodified() {
console.log('Hello from unmodified!');
}
1 change: 0 additions & 1 deletion examples/components/_Template/utils/_Template.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* This is a test `_Template` util class file.
*
Expand Down
6 changes: 6 additions & 0 deletions examples/components/_Template/utils/nested-unmodified.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* This tests a nested unmodified file.
*/
function testNestedUnmodified() {
console.log('Hello from nested unmodified!');
}
Loading