Skip to content

Commit

Permalink
merge from template
Browse files Browse the repository at this point in the history
  • Loading branch information
noogen committed Jan 31, 2022
1 parent b8c6055 commit b095438
Show file tree
Hide file tree
Showing 24 changed files with 1,650 additions and 820 deletions.
8 changes: 2 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8

# 4 space indentation
[*.php]
indent_style = tab
Expand All @@ -22,6 +17,7 @@ indent_size = 4
indent_style = tab

# Rest
[*.{js,ts,scss,vue,yml,json.html}]
[*.{js,ts,jsx,tsx,scss,vue,yml,json,html,py,sh,css,pcss}]
charset = utf-8
indent_style = space
indent_size = 2
46 changes: 25 additions & 21 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,39 @@
*.css linguist-vendored
*.scss linguist-vendored
*.js linguist-vendored
.docker export-ignore
.docker/ export-ignore
.docker/**/* export-ignore
tests export-ignore
tests/ export-ignore
tests/**/* export-ignore
storage/docs/**/* export-ignore

.docker/** export-ignore
.git/** export-ignore
assets/** export-ignore
bin/** export-ignore
node_modules/** export-ignore
tests/** export-ignore
src/** export-ignore
public/*.html export-ignore

.DS_Store export-ignore
.env export-ignore
.babelrc export-ignore
.editorconfig export-ignore
.eslintignore export-ignore
.eslintrc.js export-ignore
.gitignore export-ignore
.gitkeep export-ignore
.gitattributes export-ignore
.php*.cache export-ignore
.python-version export-ignore
.scrutinizer.yml export-ignore
.stylelintrc export-ignore
.travis.yml export-ignore
.vuebeautifyrc export-ignore
*.config.js export-ignore
*.gif export-ignore
*.js export-ignore
*.json export-ignore
*.lock export-ignore
*.sh export-ignore
*.zip export-ignore
index.html export-ignore
LICENSE.md export-ignore
package-lock.json export-ignore
phpcs.xml export-ignore
Expand All @@ -30,18 +45,7 @@ CHANGELOG.md export-ignore
README.md export-ignore
webpack.mix.js export-ignore
yarn.lock export-ignore
vue-wp-plugin-starter.php export-ignore

babel.config.js export-ignore
jest.config.js export-ignore
package-lock.json export-ignore
tsconfig.json export-ignore
tsconfig.test.json export-ignore
tslint.json export-ignore
assets/ export-ignore
assets/**/* export-ignore
src/ export-ignore
src/**/* export-ignore
index.html export-ignore
public/*.html export-ignore
tailwind.config.js export-ignore

**/*(.gitkeep) export-ignore
**/*(.DS_Store) export-ignore
92 changes: 92 additions & 0 deletions bin/makearchive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env node
// this is use to make deployment zip file

const fs = require('fs')
const path = require('path')
const archiver = require('archiver')

const IGNORE_LIST_FILENAME = '.gitattributes'
const CURRENT_PATH = path.resolve(process.cwd())

const loadIgnoreFile = () => {
try {
const fileList = fs.readFileSync(CURRENT_PATH + `/${IGNORE_LIST_FILENAME}`).toString().split('\n')
// .replace(/^(?=\n)$|^\s*|\s*$|\n\n+/gm, "")
const result = []
fileList.forEach(f => {
if (f.indexOf(' export-ignore') > 0) {
const patterns = f.split(' ')
result.push(patterns[0].trim())
}
})

return result
} catch (err) {
return []
}
}

const archive = archiver('zip', {
zlib: {
level: 9
}
})
const dirName = path.basename(CURRENT_PATH)
const outFile = './' + dirName + '.zip'

if (fs.existsSync(outFile)) {
fs.unlinkSync(outFile)
}
console.time(`${outFile} zipped in`)

const output = fs.createWriteStream(outFile)
const ignoreList = loadIgnoreFile()
ignoreList.push(outFile)

// listen for all archive data to be written
// 'close' event is fired only when a file descriptor is involved
output.on('close', function() {
console.log('>', (archive.pointer() / 1000000) + ' megabytes')
})

// This event is fired when the data source is drained no matter what was the data source.
// It is not part of this library but rather from the NodeJS Stream API.
// @see: https://nodejs.org/api/stream.html#stream_event_end
output.on('end', function() {
console.log('Data has been drained')
})

output.on('finish', () => console.timeEnd(`${outFile} zipped in`))

archive.on('entry', function (entry) {
console.log('adding', entry.name)
})

archive.on('warning', function (err) {
if (err.code === 'ENOENT') {
console.log('WARNING', err)
} else {
// throw error
throw err
}
})

// good practice to catch this error explicitly
archive.on('error', function(err) {
throw err
})

archive.pipe(output)

archive.glob('**/*',
{
expand: true,
cwd: CURRENT_PATH,
ignore: ignoreList,
dot: true
},
{
prefix: dirName
})

archive.finalize()
128 changes: 128 additions & 0 deletions bin/makeplugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/env node
// init plugin

const fs = require('fs')
const path = require('path')
const readline = require('node:readline/promises')
const glob = require('glob')

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})

const base_path = path.resolve(process.cwd())
const template_file = 'vue-wp-plugin-starter.php'

const options = {
PluginName: '',
PluginSlug: '',
PluginPrefix: '',
PluginSpace: '',
PluginFileName: ''
}

if (!fs.existsSync(template_file)) {
rl.write(`!!! Unexpected error. Failed to locate template file ${template_file}`)
process.exit(1)
}

const getPluginName = async () => {
const answer = await rl.question('To begin, input your plugin name and press [ENTER]: ')

if (!/^[A-Z][A-Za-z0-9]*( [A-Z][A-Za-z0-9]*)*$/.test(answer)) {
rl.write(`Malformed name ${answer}. Please use title-case words separated by spaces. No hyphens. For example, 'Hello World'.`)
return await getPluginName()
}

options.PluginName = answer
}

rl.on('close', async () => {
const files = glob.sync('**/*.php',
{
expand: true,
dot: false,
cwd: base_path,
ignore: [
'.git/**',
'assets/**',
'bin/**',
'node_modules/**',
'public/**',
'src/**',
'vendor/**'
]
})
files.push('readme.txt')
files.push('composer.json')
files.push('package.json')
files.push('tailwind.js')
files.push('assets/admin.html')
files.push('assets/frontend.html')
files.push('assets/frontview.html')
console.log('applying options: ', options)
applyOptions(options, files)


console.log('Removing template files')
rename(template_file, `${PluginFileName}.php`)
fs.unlinkSync('composer.lock')
fs.unlinkSync('package-lock.json')
process.exit(0)
})

function applyOptions(options, files) {
files.forEach((file) => {
console.log('applying to file', file)
let file_path = path.resolve(base_path, file)
let data = fs.readFileSync(file_path, 'utf8')

for (const [key, value] of Object.entries(options)) {
// let find = '\\$\\{' + key + '\\}';
const find = key
let re = new RegExp(find, 'g')

data = data.replace(re, value)
}

fs.writeFileSync(file_path, data, 'utf8')
})
}

function rename(from_path, to_path) {
fs.renameSync(
path.resolve(base_path, from_path),
path.resolve(base_path, to_path)
)
}

function createSlug(str) {
str = str.replace(/['\.]/g, '')
return str.toLowerCase().split(' ').join('-')
}

function createPrefix(str) {
str = str.replace(/['\.]/g, '')
return str.toLowerCase().split(' ').join('_')
}

function createNamespace(str) {
str = str.replace(/['\.]/g, '')
return str.replace(/\s+/g, '')
}

(async () => {
await getPluginName()

options.PluginSlug = createSlug(options.PluginName)
options.PluginPrefix = createPrefix(options.PluginName)
options.PluginSpace = createNamespace(options.PluginName)
options.PluginFileName = options.PluginSlug
const prepend = await rl.question('Do you want to prepend \'wp-\' to your plugin file name? [y/n]: ')
if (prepend.toLowerCase() === 'y') {
options.PluginFileName = 'wp-' + options.PluginSlug
}

rl.close()
})()
8 changes: 4 additions & 4 deletions bin/makepot.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node
const wpi18n = require('node-wp-i18n')
const pkg = require('../package.json');
const pkg = require('../package.json')

const headers = {
poedit: true,
"x-poedit-basepath": "..",
'x-poedit-basepath': '..',
'x-generator': 'node-wp-i18n ' + pkg.version
};
}

// update options below appropriately
const options = {
Expand All @@ -18,7 +18,7 @@ const options = {
},
type: 'wp-plugin',
updateTimestamp: false,
domainPath: "languages",
domainPath: 'languages',
potHeaders: headers,
}

Expand Down
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
"npm run production",
"composer update",
"composer install --no-dev --optimize-autoloader",
"rm -f dist.zip",
"deployStash=`git stash create`; git archive --worktree-attributes --format=zip -o dist.zip ${deployStash:-HEAD}",
"zip -ur dist.zip ./vendor",
"npm run make-archive",
"composer update"
],
"test": [
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b095438

Please sign in to comment.