Skip to content

Commit

Permalink
feat: update sample project (#260)
Browse files Browse the repository at this point in the history
* feat: repurpose sample-project to exam-project

* chore: rename sample-project folder to exam-project

* chore: rename sample-project in gitignore and test CI
  • Loading branch information
georgi-mateev authored Apr 30, 2024
1 parent a9e80e3 commit e6dcc34
Show file tree
Hide file tree
Showing 29 changed files with 48 additions and 58 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ jobs:

- node-version: 18
os: windows-latest
flag-for-sample-project: '--sampleProject'
flag-for-exam-project: '--exam-project'

runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.os == 'windows-latest' }}
env:
FEATURE_FLAGS: ${{ matrix.flag-for-jsx }} ${{ matrix.flag-for-router }} ${{ matrix.flag-for-pinia }} ${{ matrix.flag-for-e2e }} ${{ matrix.flag-for-sample-project }}
FEATURE_FLAGS: ${{ matrix.flag-for-jsx }} ${{ matrix.flag-for-router }} ${{ matrix.flag-for-pinia }} ${{ matrix.flag-for-e2e }} ${{ matrix.flag-for-exam-project }}
# Sometimes the Linux runner can't verify Cypress in 30s
CYPRESS_VERIFY_TIMEOUT: 60000
steps:
Expand Down Expand Up @@ -147,41 +147,41 @@ jobs:
path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}

- if: ${{ (contains(env.FEATURE_FLAGS, '--')) }}
name: Create the sample project with feature flags
name: Create the exam project with feature flags
working-directory: ../
run: node ./create-vue/outfile.cjs sample-project ${{ env.FEATURE_FLAGS }}
run: node ./create-vue/outfile.cjs exam-project ${{ env.FEATURE_FLAGS }}

- if: ${{ !(contains(env.FEATURE_FLAGS, '--')) }}
name: Create the sample project with default options
name: Create the exam project with default options
working-directory: ../
run: node ./create-vue/outfile.cjs sample-project --default
run: node ./create-vue/outfile.cjs exam-project --default

- name: Install dependencies in the sample project
working-directory: ../sample-project
- name: Install dependencies in the exam project
working-directory: ../exam-project
run: npm install

- if: ${{ contains(matrix.flag-for-vitest, '--') }}
name: Run unit test script
working-directory: ../sample-project
working-directory: ../exam-project
run: npm run test:unit

- name: Run build script
working-directory: ../sample-project
working-directory: ../exam-project
run: npm run build

- name: Download Cypress
if: ${{ contains(matrix.flag-for-e2e, '--cypress') }}
working-directory: ../sample-project
working-directory: ../exam-project
run: |
npm exec cypress cache list
npm exec cypress install
- if: ${{ contains(matrix.flag-for-e2e, '--playwright') }}
name: Install Playwright dependencies
working-directory: ../sample-project
working-directory: ../exam-project
run: npx playwright install --with-deps

- if: ${{ contains(matrix.flag-for-e2e, '--') }}
name: Run e2e test script
working-directory: ../sample-project
working-directory: ../exam-project
run: npm run test:e2e
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ dist

playground/
.idea/**
/template/sample-project/package-lock.json
/template/exam-project/package-lock.json
78 changes: 34 additions & 44 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async function init() {
const cwd = process.cwd()
// possible options:
// --default
// --sampleProject
// --exam-project/exam
// --typescript / --ts (always true)
// --jsx
// --router / --vue-router
Expand All @@ -88,7 +88,8 @@ async function init() {

// alias is not supported by parseArgs
const options = {
sampleProject: { type: 'boolean' },
exam: { type: 'boolean' },
'exam-project': { type: 'boolean' },
typescript: { type: 'boolean' },
ts: { type: 'boolean' },
'with-tests': { type: 'boolean' },
Expand All @@ -107,7 +108,7 @@ async function init() {
const isFeatureFlagsUsed =
typeof (
argv.default ??
argv.sampleProject ??
(argv.exam || argv['exam-project']) ??
(argv.ts || argv.typescript) ??
argv.jsx ??
(argv.router || argv['vue-router']) ??
Expand All @@ -134,7 +135,6 @@ async function init() {
projectName?: string
shouldOverwrite?: boolean
packageName?: string
needsSampleProject?: boolean
needsTypeScript?: boolean
needsJsx?: boolean
needsRouter?: boolean
Expand All @@ -154,7 +154,6 @@ async function init() {
// - Project name:
// - whether to overwrite the existing directory or not?
// - enter a valid package name for package.json
// - Create a sample project using Pinia, Vue-router and Vitest?
// - Project language: JavaScript / TypeScript
// - Add JSX Support?
// - Install Vue Router for SPA development?
Expand Down Expand Up @@ -208,14 +207,6 @@ async function init() {
initial: () => toValidPackageName(targetDir),
validate: (dir) => isValidPackageName(dir) || language.packageName.invalidMessage
},
{
name: 'needsSampleProject',
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
message: 'Create a sample project using Pinia, Vue-router and Vitest?',
initial: false,
active: language.defaultToggleOptions.active,
inactive: language.defaultToggleOptions.inactive
},
{
name: 'needsJsx',
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
Expand All @@ -226,17 +217,15 @@ async function init() {
},
{
name: 'needsRouter',
type: (prev, values) =>
isFeatureFlagsUsed || values.needsSampleProject ? null : 'toggle',
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
message: language.needsRouter.message,
initial: false,
active: language.defaultToggleOptions.active,
inactive: language.defaultToggleOptions.inactive
},
{
name: 'needsPinia',
type: (prev, values) =>
isFeatureFlagsUsed || values.needsSampleProject ? null : 'toggle',
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
message: language.needsPinia.message,
initial: false,
active: language.defaultToggleOptions.active,
Expand Down Expand Up @@ -336,7 +325,6 @@ async function init() {
projectName,
packageName = projectName ?? defaultProjectName,
shouldOverwrite = argv.force,
needsSampleProject = argv.sampleProject,
needsJsx = argv.jsx,
needsTypeScript = true, // prefer TS as a solution
needsRouter = argv.router || argv['vue-router'],
Expand Down Expand Up @@ -381,10 +369,11 @@ async function init() {
renderTemplate(templateDir, root, callbacks)
}

// Sample project has its own structure, to avoid overriding
// render base + configs only if sample is not selected
if (needsSampleProject) {
render('sample-project')
// Exam project to be used for Vue assesment
const isExamProjectSelected = argv['exam-project'] || argv.exam

if (isExamProjectSelected) {
render('exam-project')
} else {
// Render base template
render('base')
Expand Down Expand Up @@ -617,26 +606,29 @@ async function init() {
? 'bun'
: 'npm'

// README generation
fs.writeFileSync(
path.resolve(root, 'README.md'),
generateReadme({
projectName: result.projectName ?? result.packageName ?? defaultProjectName,
packageManager,
needsTypeScript,
needsVitest,
needsCypress,
needsNightwatch,
needsPlaywright,
needsNightwatchCT,
needsCypressCT,
needsVueUse,
needsI18n,
needsSonarQube,
needsTanStackQuery,
needsTailwind
})
)
// README generation - should happen unless exam-project is
// rendered since this case has its own README
if (!isExamProjectSelected) {
fs.writeFileSync(
path.resolve(root, 'README.md'),
generateReadme({
projectName: result.projectName ?? result.packageName ?? defaultProjectName,
packageManager,
needsTypeScript,
needsVitest,
needsCypress,
needsNightwatch,
needsPlaywright,
needsNightwatchCT,
needsCypressCT,
needsVueUse,
needsI18n,
needsSonarQube,
needsTanStackQuery,
needsTailwind
})
)
}

console.log(`\n${language.infos.done}\n`)
if (root !== cwd) {
Expand All @@ -645,8 +637,6 @@ async function init() {
` ${bold(green(`cd ${cdProjectName.includes(' ') ? `"${cdProjectName}"` : cdProjectName}`))}`
)
}
console.log(` ${bold(yellow('In order to use husky you need to initialize git'))}`)
console.log(` ${bold(green('git init'))}`)
console.log(` ${bold(green(getCommand(packageManager, 'install')))}`)
console.log(` ${bold(green(getCommand(packageManager, 'format')))}`)
if (needsStorybook) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e6dcc34

Please sign in to comment.