Skip to content

Commit

Permalink
improve: Add a script for scaffolding default files & components. (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtlBbx authored May 10, 2023
1 parent 30bd88f commit 5b9ae04
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export default defineNuxtConfig({

The module defaults work well with [Lupus Decoupled Drupal](https://www.drupal.org/project/lupus_decoupled), so setting the `baseURL` is usually enough.

3. Get started quickly by scaffolding initial files:
```bash
rm -f app.vue && npx nuxt-drupal-ce-init
```


## Features

Expand Down
38 changes: 38 additions & 0 deletions bin/nuxt-drupal-ce-init.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env node

const fs = require('fs')
const path = require('path')
const scaffoldDir = path.join(__dirname, '/../playground')
const target = '.'

function copyFile (source, target) {
const targetFile = target + '/' + path.basename(source)

// If target is a directory, a new file with the same name will be created
if (!fs.existsSync(targetFile)) {
// eslint-disable-next-line no-console
console.log(targetFile + ' - Created.')
fs.writeFileSync(targetFile, fs.readFileSync(source))
} else {
// eslint-disable-next-line no-console
console.log(targetFile + ' - Existing, skipped.')
}
}

function syncDir (directory) {
fs.readdirSync(scaffoldDir + '/' + directory).forEach(function (item) {
if (fs.lstatSync(scaffoldDir + '/' + directory + '/' + item).isDirectory()) {
syncDir(directory + '/' + item)
} else {
copyFile(scaffoldDir + '/' + directory + '/' + item, target + '/' + directory)
}
})
}

// Here we want to make sure our directories exist.
fs.mkdirSync('./components/global', { recursive: true })
fs.mkdirSync('./pages', { recursive: true })

syncDir('pages')
syncDir('components')
copyFile(scaffoldDir + '/app.vue', target)
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "nuxtjs-drupal-ce",
"version": "2.0.0",
"license": "MIT",
"bin": {
"nuxt-drupal-ce-init": "bin/nuxt-drupal-ce-init.cjs"
},
"type": "module",
"exports": {
".": {
Expand All @@ -12,7 +15,10 @@
"main": "./dist/module.cjs",
"types": "./dist/types.d.ts",
"files": [
"dist"
"dist",
"playground/components",
"playground/pages",
"playground/app.vue"
],
"scripts": {
"prepack": "nuxt-module-build",
Expand Down

0 comments on commit 5b9ae04

Please sign in to comment.