Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1054f7f
Replace instances of require() with import
agibson-godaddy Feb 28, 2025
f1be39f
Move config to separate file that we can export
agibson-godaddy Mar 12, 2025
67e1f65
Initialize config from inside sake file
agibson-godaddy Mar 12, 2025
ea38b7a
Refactor replacement pipes
agibson-godaddy Mar 12, 2025
b9ad28d
Export scripts
agibson-godaddy Mar 12, 2025
d05267b
Refactor validation task
agibson-godaddy Mar 12, 2025
95ae9ed
Refactor bump task
agibson-godaddy Mar 12, 2025
d6cb231
Rework wc tasks
agibson-godaddy Mar 13, 2025
a6a6826
Only import the fs function we use
agibson-godaddy Mar 13, 2025
742c38a
Rework config task
agibson-godaddy Mar 13, 2025
b20d287
Rework linting
agibson-godaddy Mar 13, 2025
c87cc19
Rework imagemin
agibson-godaddy Mar 13, 2025
a8d9bd3
Adjust gulpif import
agibson-godaddy Mar 14, 2025
8f118fe
Rework shell tasks
agibson-godaddy Mar 14, 2025
47a4296
Rework watch
agibson-godaddy Mar 14, 2025
6e429df
Rework styles
agibson-godaddy Mar 14, 2025
975f55e
Rework makepot
agibson-godaddy Mar 14, 2025
0a99b85
Rework decaffeinate
agibson-godaddy Mar 14, 2025
08d14e1
Rework clean tasks
agibson-godaddy Mar 14, 2025
2182c87
Rework compile task
agibson-godaddy Mar 14, 2025
f1ff8e8
Rework scripts
agibson-godaddy Mar 14, 2025
0f20169
Rework github tasks
agibson-godaddy Mar 14, 2025
d235325
Rework zip
agibson-godaddy Mar 14, 2025
75f1ebb
Rework prompt
agibson-godaddy Mar 14, 2025
40a5a55
Rework bundle
agibson-godaddy Mar 14, 2025
06141a6
Use task suffix in constants
agibson-godaddy Mar 14, 2025
beafea5
Use task suffix
agibson-godaddy Mar 14, 2025
5c517b0
Use task suffix
agibson-godaddy Mar 14, 2025
e1c28d6
Use task suffix
agibson-godaddy Mar 14, 2025
a68bfe0
Use task suffix
agibson-godaddy Mar 14, 2025
0370715
Start reworking deploy
agibson-godaddy Mar 14, 2025
59a5cca
Rework deploy tasks
agibson-godaddy Mar 17, 2025
d0bae0f
Update prerelease tasks
agibson-godaddy Mar 17, 2025
c0a821b
Update upfw tasks
agibson-godaddy Mar 17, 2025
1291ccd
Update naming
agibson-godaddy Mar 17, 2025
0212867
Update naming
agibson-godaddy Mar 17, 2025
c79a6e0
Fix import
agibson-godaddy Mar 17, 2025
c1ccfcf
Update deprecated sass import
agibson-godaddy Mar 17, 2025
2b08904
Remove console log
agibson-godaddy Mar 19, 2025
df04967
Rework how series is created
agibson-godaddy Mar 19, 2025
d72c2ba
Add force option
agibson-godaddy Mar 25, 2025
54ba0b3
Fix conflicts
agibson-godaddy Aug 22, 2025
bc3f35d
Apply changes from master
agibson-godaddy Aug 22, 2025
4828df1
Apply suggestions from code review
agibson-godaddy Aug 22, 2025
b7ba4da
Execute codename as a function
agibson-godaddy Aug 22, 2025
2bb4f13
Fix typo
agibson-godaddy Aug 22, 2025
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
10 changes: 7 additions & 3 deletions bin/sake.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env node
const { spawn } = require('child_process')
const path = require('path')
import { spawn } from 'node:child_process'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import resolve from 'resolve-bin'
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

/**
* `sake` is simply a nice wrapper around `gulp`, designed to simplify using gulp
Expand All @@ -17,7 +21,7 @@ const path = require('path')
// The concat portion passes in any optional CLI args as well as the gulpfile from sake and
// current workind directory.
const args = [
require('resolve-bin').sync('gulp')
resolve.sync('gulp')
].concat(process.argv.splice(2).concat([
'--gulpfile', path.join(__dirname, '../gulpfile.js'),
'--cwd', process.cwd()
Expand Down
161 changes: 43 additions & 118 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
'use strict'

const gulp = require('gulp')
const path = require('path')
const fs = require('fs')
const minimist = require('minimist')
const log = require('fancy-log')
const _ = require('lodash')
const ForwardReference = require('undertaker-forward-reference')
import gulp from 'gulp'
import path from 'node:path'
import fs from 'node:fs'
import log from 'fancy-log'
import ForwardReference from 'undertaker-forward-reference'
import dotenv from 'dotenv'
import gulpPlugins from 'gulp-load-plugins'
import notifier from 'node-notifier'
import stripAnsi from 'strip-ansi'
import { fileURLToPath } from 'node:url'
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// local .env file, overriding any global env variables
let parentEnvPath = path.join('..', '.env')
let envPath = fs.existsSync('.env') ? '.env' : (fs.existsSync(parentEnvPath) ? parentEnvPath : null)

if (envPath) {
let result = require('dotenv').config({ path: envPath })
let result = dotenv.config({ path: envPath })

log.warn(`Loading ENV variables from ${path.join(process.cwd(), envPath)}`)

Expand All @@ -25,7 +28,7 @@ if (envPath) {
// development .env file, overriding any global env variables, or repo/plugin specific variables
let devEnv = path.join(__dirname, '.env')
if (fs.existsSync(devEnv)) {
let result = require('dotenv').config({path: devEnv})
let result = dotenv.config({path: devEnv})

log.warn('LOADING DEVELOPMENT ENV VARIABLES FROM ' + devEnv)

Expand All @@ -37,116 +40,12 @@ if (fs.existsSync(devEnv)) {
// enable forward-referencing tasks, see https://github.com/gulpjs/gulp/issues/1028
gulp.registry(ForwardReference())

// define default config
let defaults = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config was moved to new, separate file lib/config.js so that it can now be imported where required, instead of passing it around function parameters.

// sets up the plugin folder structure
paths: {
// Path to plugin source files - this is where the main plugin entry file is located. Set this to a dot (.) if the
// main plugin file and sake.config.js are in teh same directory. The path is relative to the current working directory.
// Mostly, this is the only path a plugin/repo needs to explicitly set
src: '.',
// where plugin assets are located, relative to `src`
assets: 'assets',
// where plugin CSS/SCSS assets are located, relative to `src`
css: 'assets/css',
// where plugin JS/COFFEE assets are located, relative to `src`
js: 'assets/js',
// where plugin image assets are located, relative to `src`
images: 'assets/img',
// where plugin font assets are located, relative to `src`
fonts: 'assets/fonts',
// the directory where plugin files are copied during the build task, relative to current working directory
build: 'build',
// path to the directory where production (WC and WP.org SVN) repos are cloned, may be an absolute path or relative to current working directory
tmp: '/tmp/sake',
// array of paths that should be excluded from the build
exclude: []
},

// Task-specific settings, set the key to task name and provide any settings as needed. Since sake uses Gulp behind the scenes
// and Gulp prefers code over configuration, there isn't a lot to do here. As you can see, some of these values can be defined
// as environment variables, as this makes more sense - ie whether you want to use browsersync or not is specific tp your local
// dev environment and workflow, not to a particular repo.
tasks: {
makepot: {
reportBugsTo: 'https://woocommerce.com/my-account/marketplace-ticket-form/',
domainPath: 'i18n/languages'
},
watch: {
useBrowserSync: process.env.USE_BROWSERSYNC || false
},
browserSync: {
url: process.env.BROWSERSYNC_URL || 'plugins-skyverge.test'
}
},

// which framework version this plugin uses - valid values: 'v5', 'v4', or pass boolean `false` to indicate a non-frameworked plugin
framework: 'v5',
// which deploy type does this plugin use - either 'wc' or 'wp', defaults to 'wc', specify `null` or `false` for no automated deploy
deploy: 'wc',
// the e-commerce platform this plugin is for, 'wc' or 'edd'
platform: 'wc'
}

// load local configuration
// TODO: allow passing in config file path or config as string (for multi-plugin repos?)
let localConfig = {}

// support supplying a single / parent config file in multi-plugin repos
let parentConfigPath = path.join(process.cwd(), '../sake.config.js')
let found = false

if (fs.existsSync(parentConfigPath)) {
log.warn('Found config file in parent folder')
localConfig = require(parentConfigPath)
found = true
}

// load local, plugin-specific config file
let configFilePath = path.join(process.cwd(), 'sake.config.js')

if (fs.existsSync(configFilePath)) {
localConfig = _.merge(localConfig, require(configFilePath))
found = true
}

if (!found) {
log.warn('Could not find local config file, using default config values.')
}

let config = _.merge(defaults, localConfig)

// parse CLI options
let options = minimist(process.argv.slice(2), {
boolean: ['minify'],
default: {
minify: true,
debug: false
}
})

const sake = require('./lib/sake')(config, options)

sake.initConfig()

let plugins = require('gulp-load-plugins')()

// Attach browsersync as a plugin - not really a plugin, but it helps to
// pass around the browsersync instance between tasks. Unfortunately, we
// always have to load and create an instance of it, because gulp-if does not
// support lazy evaluation yet: https://github.com/robrich/gulp-if/issues/75
plugins.browserSync = require('browser-sync').create()

// load gulp plugins and tasks
require('fs').readdirSync(path.join(__dirname, 'tasks')).forEach((file) => {
require(path.join(__dirname, 'tasks', file))(gulp, plugins, sake)
// @link https://github.com/jackfranklin/gulp-load-plugins/issues/141#issuecomment-2373391177
let plugins = gulpPlugins({
config: path.resolve(__dirname, 'package.json')
})

gulp.task('default', gulp.series('compile'))

// show notification on task errors
const notifier = require('node-notifier')
const stripAnsi = require('strip-ansi')
let loggedErrors = []

gulp.on('error', (event) => {
Expand All @@ -161,3 +60,29 @@ gulp.on('error', (event) => {
loggedErrors.push(event.error)
}
})

/************** Task Exports */

export * from './tasks/build.js'
export * from './tasks/bump.js'
export * from './tasks/bundle.js'
export * from './tasks/clean.js'
export * from './tasks/compile.js'
export * from './tasks/config.js'
export * from './tasks/copy.js'
export * from './tasks/decaffeinate.js'
export * from './tasks/deploy.js'
export * from './tasks/github.js'
export * from './tasks/imagemin.js'
export * from './tasks/lint.js'
export * from './tasks/makepot.js'
export * from './tasks/prerelease.js'
export * from './tasks/prompt.js'
export * from './tasks/scripts.js'
export * from './tasks/shell.js'
export * from './tasks/styles.js'
export * from './tasks/upfw.js'
export * from './tasks/validate.js'
export * from './tasks/watch.js'
export * from './tasks/wc.js'
export * from './tasks/zip.js'
91 changes: 91 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import path from 'node:path'
import { existsSync } from 'node:fs'
import log from 'fancy-log'
import _ from 'lodash'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url);

const buildSakeConfig = () => {
// define default config
let defaults = {
// sets up the plugin folder structure
paths: {
// Path to plugin source files - this is where the main plugin entry file is located. Set this to a dot (.) if the
// main plugin file and sake.config.js are in teh same directory. The path is relative to the current working directory.
// Mostly, this is the only path a plugin/repo needs to explicitly set
src: '.',
// where plugin assets are located, relative to `src`
assets: 'assets',
// where plugin CSS/SCSS assets are located, relative to `src`
css: 'assets/css',
// where plugin JS/COFFEE assets are located, relative to `src`
js: 'assets/js',
// where plugin image assets are located, relative to `src`
images: 'assets/img',
// where plugin font assets are located, relative to `src`
fonts: 'assets/fonts',
// the directory where plugin files are copied during the build task, relative to current working directory
build: 'build',
// path to the directory where production (WC and WP.org SVN) repos are cloned, may be an absolute path or relative to current working directory
tmp: '/tmp/sake',
// array of paths that should be excluded from the build
exclude: []
},

// Task-specific settings, set the key to task name and provide any settings as needed. Since sake uses Gulp behind the scenes
// and Gulp prefers code over configuration, there isn't a lot to do here. As you can see, some of these values can be defined
// as environment variables, as this makes more sense - ie whether you want to use browsersync or not is specific tp your local
// dev environment and workflow, not to a particular repo.
tasks: {
makepot: {
reportBugsTo: 'https://woocommerce.com/my-account/marketplace-ticket-form/',
domainPath: 'i18n/languages'
},
watch: {
useBrowserSync: process.env.USE_BROWSERSYNC || false
},
browserSync: {
url: process.env.BROWSERSYNC_URL || 'plugins-skyverge.test'
}
},

// which framework version this plugin uses - valid values: 'v5', 'v4', or pass boolean `false` to indicate a non-frameworked plugin
framework: 'v5',
// which deploy type does this plugin use - either 'wc' or 'wp', defaults to 'wc', specify `null` or `false` for no automated deploy
deploy: 'wc',
// the e-commerce platform this plugin is for, 'wc' or 'edd'
platform: 'wc'
}

// load local configuration
// TODO: allow passing in config file path or config as string (for multi-plugin repos?)
let localConfig = {}

// support supplying a single / parent config file in multi-plugin repos
let parentConfigPath = path.join(process.cwd(), '../sake.config.js')
let found = false

if (existsSync(parentConfigPath)) {
log.warn('Found config file in parent folder')
localConfig = require(parentConfigPath)
found = true
}

// load local, plugin-specific config file
let configFilePath = path.join(process.cwd(), 'sake.config.js')

if (existsSync(configFilePath)) {
localConfig = _.merge(localConfig, require(configFilePath))
found = true
}

if (!found) {
log.warn('Could not find local config file, using default config values.')
}

return _.merge(defaults, localConfig)
}

const sakeConfig = buildSakeConfig();

export default sakeConfig;
45 changes: 32 additions & 13 deletions lib/sake.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
const fs = require('fs')
const path = require('path')
const semver = require('semver')
const parseGitConfig = require('parse-git-config')
const parseGitHubUrl = require('parse-github-url')
const _ = require('lodash')
const _str = require('underscore.string')
const log = require('fancy-log')
const chalk = require('chalk')
const dottie = require('dottie')

module.exports = (config, options) => {
import fs from 'node:fs';
import path from 'node:path';
import semver from 'semver';
import parseGitConfig from 'parse-git-config';
import parseGitHubUrl from 'parse-github-url';
import _ from 'lodash';
import _str from 'underscore.string';
import log from 'fancy-log';
import chalk from 'chalk';
import dottie from 'dottie';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
import sakeConfig from './config.js'
import minimist from 'minimist'

// parse CLI options
let options = minimist(process.argv.slice(2), {
boolean: ['minify'],
default: {
minify: true,
debug: false
}
})


const sake = initializeSake(sakeConfig, options);
sake.initConfig();

export default sake;

function initializeSake(config, options) {
const exports = {}
// current task(s) from CLI, ie for `npx sake clean build` this will result in ['clean', 'build']
const cliTasks = process.argv.slice(2, -4)
Expand Down Expand Up @@ -363,7 +382,7 @@ module.exports = (config, options) => {
lines = contents.split('== Changelog ==')[1].trim().split('\n')
}

// get the plugin name from changelog - asuuming it will be on the 1st line
// get the plugin name from changelog - assuming it will be on the 1st line
if (fileName === 'changelog.txt') {
changelog.plugin_name = lines[0].replace(/\*/g, '').replace(/Changelog/, '').trim()
} else {
Expand Down
Loading