Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Sparky.task("copy-html", () => {
return Sparky.src("src/app/index.html").dest(`${OUTPUT_DIR}/$name`)
})
Sparky.task('copy-pkg', (context) => Sparky.src('./package.json', { base: `./packages/${context.pkg}` }).dest(`./packages/${context.pkg}/dist/`));
Sparky.task('copy-md', (context) => Sparky.src('./*.md', { base: `./packages/${context.pkg}` }).dest(`./packages/${context.pkg}/dist/`));
Sparky.task('jest.zone.fix', () =>
Sparky.src('node_modules/jest-preset-angular/**').file(
'setupJest.js',
(file: SparkyFile) => {
file.read()
const text = (file.contents as Buffer).toString()
const regex = new RegExp(/require\('zone.js\/dist\/zone.js'\);/, 'g')
const replacedText = text.replace(regex, "require('zone.js');")
file.setContent(replacedText)
file.save()
}
)
)
Sparky.task(taskName(__filename), () => {
const css = glob('./dist/css/**/*.css').map(a => {
return {
hash: hash(readFileSync(a).toString()),
name: a.replace('./dist', '')
}
})
return Sparky.src('./dist/index.html').file('index.html', (file: SparkyFile) => {
file.read()
const transformer = new ConfigurationTransformer()
const deps: Dependency[] = css.map(c => {
return {
inHead: true,
order: 1,
element: 'link',
attributes: {
rel: 'stylesheet',
href: `${c.name}`
}
} as Dependency
})
const html = transformer.applyTransform(deps, file.contents.toString())
Sparky.task(taskName(__filename), () => {
return Sparky.src(['./dist/ngsw-worker.js']).file(
'ngsw-worker.js',
(file: SparkyFile) => {
file.read()
const result = uglifyJS.minify(file.contents.toString())
file.setContent(result.code)
file.save()
}
)
})
Sparky.task("clean", () => Sparky.src("out/").clean("out/"));
Sparky.task('clean', _ => Sparky.src('dist/').clean('dist/'))
Sparky.task('env', _ => (isProduction = true))
Sparky.task(taskName(__filename), () =>
Sparky.src('web/**/*.*', { base: `${BUILD_CONFIG.toolsDir}` })
.dest(`./${BUILD_CONFIG.outputDir}`))
Sparky.task(taskName(__filename), () =>
Sparky.src(`${BUILD_CONFIG.outputDir}`)
.clean(`${BUILD_CONFIG.outputDir}`)
.clean('.fusebox')
.clean('.ngc')
.clean('src/client/.aot'))
async function build(context, pkg, targets) {
context.pkg = pkg;
await Sparky.exec('copy-src', 'copy-pkg', 'copy-md');
await Sparky.src(`./packages/${context.pkg}/dist/*.json`).file('package.json', (file) => {
file.json(json => {
json.typings = './index.ts';
json['ts:main'] = './index.ts';
});
file.save();
}).exec();
for (const target of targets) {
context.bundleName = `${target}-lib`;
context.home = `./packages/${pkg}/dist/`;
context.target = `browser@${target}`;
await Sparky.resolve('config');
await fuse.run();
}
}