Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import Parcel from 'parcel-bundler'
import path from 'path'
import electron from 'electron'
const option = {
watch: true,
// target: 'electron',
publicUrl: './',
cache: true,
hmr: false
}
let index = new Parcel(path.join(__dirname, '../src/index.html'), option)
index.bundle().then(() => {
console.log('>> done')
var proc = require('child_process')
var child = proc.spawn(electron, ['.', '--debug'], {
stdio: 'inherit'
})
child.on('close', function (code) {
process.exit(code)
})
})
const tempDir = path.join(os.tmpdir(), uniqueId());
const tempFileName = 'remirror-webview.js';
const tempFilePath = path.join(tempDir, tempFileName);
const outDir = workingDirectory;
const isTs = bool(source.match(/\.tsx?$/));
const outFilePath = path.join(outDir, isTs ? 'file.ts' : 'file.js');
// Parcel config
const options: ParcelOptions = {
outDir: tempDir,
outFile: tempFileName,
sourceMaps: false,
minify: true,
watch: false,
logLevel: 1,
};
const parcel = new Bundler(entryFile, options);
async function build(bundler: Bundler) {
try {
// create the bundle
await bundler.bundle();
// Read the bundle and insert it into script template
const script = await readFile(tempFilePath, 'utf-8');
const finalOutput = isTs ? createTSFile(script) : createJSFile(script);
await writeFile(outFilePath, finalOutput, 'utf-8');
// Remove junk
await clearPath(`${tempDir}/*`);
} catch (error) {
console.error(error);
}
}
import Parcel from 'parcel-bundler'
import path from 'path'
import fs from 'fs-extra'
const builder = require('electron-builder')
const option = {
watch: false,
cache: false,
// target: 'electron',
publicUrl: './',
hmr: false
}
let index = new Parcel(path.join(__dirname, '../src/index.html'), option)
index.bundle().then(() => {
fs.copySync(path.join(__dirname, '../logo.png'), path.join(__dirname, '../dist/logo.png'))
fs.copySync(path.join(__dirname, '../logo.svg'), path.join(__dirname, '../dist/logo.svg'))
fs.copySync(path.join(__dirname, '../src/index.js'), path.join(__dirname, '../dist/index.js'))
fs.copySync(path.join(__dirname, '../src/auto-updater.js'), path.join(__dirname, '../dist/auto-updater.js'))
fs.copySync(path.join(__dirname, '../src/services'), path.join(__dirname, '../dist/services'))
fs.copySync(path.join(__dirname, '../package.json'), path.join(__dirname, '../dist/package.json'))
console.log('>> done')
console.log('>> start pack...')
builder.build({
config: {
'appId': 'com.mark.app',
'productName': 'Mark',
'directories': {
watch: this.options.watch || false
};
const config = {
...defaults,
...options
};
if (this.options.watch) {
this.isWatching = true;
}
if (this.entries.length === 1) {
// watch single function
const entry = this.entries[0];
const bundler = new Bundler(entry, {
...config,
outDir: path.relative(
this.originalServicePath,
path.join(this.buildPath, path.dirname(entry))
)
});
this.invokeBundle = await bundler.bundle();
if (this.isWatching) {
(bundler as any).on('buildEnd', () => {
this.sls.pluginManager.spawn('invoke:local');
});
}
} else {
for (const entry of this.entries) {
async function compileAssets () {
let pugTemplate = join(SRC, 'uikit.pug')
let uikitBundler = new Bundler(pugTemplate, {
sourceMaps: false,
logLevel: 2
})
let bundle = await uikitBundler.bundle()
let assets = findAssets(bundle)
let hashes = { }
return {
map (fn) {
return assets.map(fn)
},
get (regexp) {
return assets.filter(i => regexp.test(i))
},
find (regexp) {
return assets.find(i => regexp.test(i))
},
export const createBundle = async (html: string, main: string) => {
await trash(DIST_PATH)
await trash(THEME_PATH)
await tempFile(INDEX_JS, main)
await tempFile(INDEX_HTML, html)
const bundler = new Bundler(INDEX_HTML, {
cacheDir: CACHE_PATH,
outDir: DIST_PATH,
publicURL: '/',
outFile: 'index',
})
try {
return await bundler.bundle()
} catch (err) {
console.log(err)
return null
}
}
outDir: path.relative(
this.originalServicePath,
path.join(this.buildPath, path.dirname(entry))
)
});
this.invokeBundle = await bundler.bundle();
if (this.isWatching) {
(bundler as any).on('buildEnd', () => {
this.sls.pluginManager.spawn('invoke:local');
});
}
} else {
for (const entry of this.entries) {
const bundler = new Bundler(entry, {
...config,
outDir: path.relative(
this.originalServicePath,
path.join(this.buildPath, path.dirname(entry))
)
});
await bundler.bundle();
}
}
}
const bundlePromises = pages.map(page => {
const entryFile = path.join(__dirname, '..', 'src', 'pages', page)
const bundler = new Bundler(entryFile)
return bundler.bundle()
})
export const getBundler = async options => {
let bundler = new Bundler(template, options)
await SveltePlugin(bundler)
return bundler
}