Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import chokidar from 'chokidar'
import { constants, log } from '@create-figma-plugin/common'
import { build } from './build'
const ignoreRegex = new RegExp(
[
'(^|\\/)', // beginning of string or '/'
'\\.', // '.'
'[^.]+', // one or more characters that isn't '.'
`|${constants.build.directoryName}`,
`|${constants.build.manifestFilePath}`,
'|node_modules'
].join('')
)
export function watch () {
const watcher = chokidar.watch('.', {
ignored: function (path) {
return ignoreRegex.test(path)
}
})
async function run () {
await build(true, false)
log.info('Watching...')
}
watcher.on('ready', run)
watcher.on('change', async function (file) {
import chokidar from 'chokidar'
import { constants, log } from '@create-figma-plugin/common'
import { build } from './build'
const ignoreRegex = new RegExp(
[
'(^|\\/)', // beginning of string or '/'
'\\.', // '.'
'[^.]+', // one or more characters that isn't '.'
`|${constants.build.directoryName}`,
`|${constants.build.manifestFilePath}`,
'|node_modules'
].join('')
)
export function watch () {
const watcher = chokidar.watch('.', {
ignored: function (path) {
return ignoreRegex.test(path)
}
})
async function run () {
await build(true, false)
log.info('Watching...')
}
watcher.on('ready', run)
export function createWebpackConfig (entry, isDevelopment) {
const mode = isDevelopment ? 'development' : 'production'
return {
mode,
entry,
output: {
filename: '[name].js',
path: join(process.cwd(), constants.build.directoryName)
},
module: {
rules: [
{
test: /\.js?$/,
exclude: /node_modules\/(?!@create-figma-plugin)/,
use: {
loader: 'babel-loader',
options: {
plugins: [
'@babel/plugin-proposal-object-rest-spread',
[
'@babel/plugin-transform-template-literals',
{
loose: true
}
name: config.name,
id: config.id,
api: config.apiVersion
}
if (hasBundle(config, 'command') === true) {
result.main = constants.build.pluginCodeFilePath
}
if (hasBundle(config, 'ui') === true) {
result.ui = constants.build.pluginUiFilePath
}
const menu = config.menu
if (typeof menu !== 'undefined') {
result.menu = normaliseMenu(menu)
}
const string = JSON.stringify(result) + '\n'
return outputFile(constants.build.manifestFilePath, string)
}
export async function buildBundle (config, isDevelopment) {
const entry = {}
const commandEntryFile = await createCommandEntryFile(config)
if (commandEntryFile !== null) {
const key = extractBasename(constants.build.pluginCodeFilePath)
entry[key] = commandEntryFile
}
const uiEntryFile = await createUiEntryFile(config)
if (uiEntryFile !== null) {
const key = extractBasename(constants.build.pluginUiFilePath)
entry[key] = uiEntryFile
}
let webpackConfig = createWebpackConfig(entry, isDevelopment)
const customWebpackConfigPath = await findUp(constants.configFileName)
if (typeof customWebpackConfigPath !== 'undefined') {
webpackConfig = require(customWebpackConfigPath)(webpackConfig)
}
return new Promise(function (resolve, reject) {
webpack(webpackConfig, async function (error, stats) {
if (stats.hasErrors() === true) {
reject(stats.toJson().errors.join('\n'))
return
}
if (error) {
reject(error)
return