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)
loader: 'css-loader',
options: {
importLoaders: 1,
modules: true
}
},
{
loader: 'sass-loader'
}
]
}
]
},
resolve: {
modules: [
join(process.cwd(), constants.src.directory),
join(process.cwd(), 'node_modules'),
resolve(process.cwd(), '..', '..', 'node_modules'), // Lerna monorepo
process.cwd(),
'node_modules'
],
extensions: ['.js', '.json']
},
devtool: isDevelopment ? 'inline-cheap-module-source-map' : 'none',
stats: 'errors-only',
plugins: [
new webpack.EnvironmentPlugin({
NODE_ENV: mode
})
],
optimization: {
minimizer: [
export async function build (isDevelopment, exitOnError) {
log.info('Building plugin...')
const config = await readConfig()
try {
await buildBundle(config, isDevelopment)
await buildManifest(config)
} catch (error) {
log.error(error)
if (exitOnError === true) {
process.exit(1)
}
return
}
log.success('Done')
}
export async function build (isDevelopment, exitOnError) {
log.info('Building plugin...')
const config = await readConfig()
try {
await buildBundle(config, isDevelopment)
await buildManifest(config)
} catch (error) {
log.error(error)
if (exitOnError === true) {
process.exit(1)
}
return
}
log.success('Done')
}
export async function build (isDevelopment, exitOnError) {
log.info('Building plugin...')
const config = await readConfig()
try {
await buildBundle(config, isDevelopment)
await buildManifest(config)
} catch (error) {
log.error(error)
if (exitOnError === true) {
process.exit(1)
}
return
}
log.success('Done')
}
export async function build (isDevelopment, exitOnError) {
log.info('Building plugin...')
const config = await readConfig()
try {
await buildBundle(config, isDevelopment)
await buildManifest(config)
} catch (error) {
log.error(error)
if (exitOnError === true) {
process.exit(1)
}
return
}
log.success('Done')
}
export async function createFigmaPlugin (options, useDefault) {
if (typeof options.name !== 'undefined') {
await throwIfDirectoryExists(join(process.cwd(), options.name))
}
log.info('Scaffolding a new plugin...')
const config = useDefault
? createDefaultConfig(options)
: await promptForUserInput(options)
const pluginDirectoryPath = join(process.cwd(), config.name)
await throwIfDirectoryExists(pluginDirectoryPath)
log.info('Cloning template...')
await cloneFromTemplate(pluginDirectoryPath, config.template)
await interpolateValuesIntoFiles(pluginDirectoryPath, config)
log.info('Installing dependencies...')
await installDependencies(pluginDirectoryPath)
log.success('Done')
}
async function run () {
await build(true, false)
log.info('Watching...')
}
watcher.on('ready', run)
watcher.on('change', async function (file) {
log.info(`Changed: ${file}`)
await run()
})
}