Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const project = rushConfig.tryGetProjectForPath(packageDir);
if (!project) {
console.error(`Unable to find project for '${packageDir}' in 'rush.json'.`);
throw Error();
}
//REVIEW: Better way to detect deployable projects?
// Since extension .js files are deployed to 'dist//out', and libraries are deployed to
// 'dist//node_modules//out'.
const pathToRoot = (path.dirname(project.projectRelativeFolder) === 'extensions') ?
'../../..' : '../../../../..';
return tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject(goodReporter()))
.pipe(sourcemaps.mapSources((sourcePath, _file) => {
// The source path is kind of odd, because it's relative to the `tsconfig.json` file in the
// `typescript-config` package, which lives in the `node_modules` directory of the package
// that is being built. It starts out as something like '../../../src/foo.ts', and we need to
// strip out the leading '../../../'.
return path.join('a/b/c', sourcePath);
}))
.pipe(sourcemaps.write('.', {
includeContent: false,
sourceRoot: path.join(pathToRoot, project.projectRelativeFolder)
}))
.pipe(gulp.dest('out'));
}
]
};
return gulp.src([
'entrypoints/*.js',
'src/*.js',
'node_modules/get-own-property-symbols/build/get-own-property-symbols.max.js',
'node_modules/promise-polyfill/src/**/*.js',
'node_modules/@webcomponents/**/*.js',
'!node_modules/@webcomponents/*/externs/*.js',
'!node_modules/@webcomponents/*/node_modules/**'
], {base: './', follow: true})
.pipe(sourcemaps.init())
.pipe(closure(closureOptions))
.pipe(sourcesContent())
.pipe(sourcemaps.mapSources(
// We load from node_modules, but the other polyfills are technically siblings of us.
// Therefore, rewrite the sourcemap files to fixup the directory location
sourcePath => sourcePath
.replace(/node_modules\/@webcomponents/, smPrefix + '..')
.replace(/node_modules/, smPrefix + '../..')
.replace(/^src/, smPrefix + 'src')
))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(outDir));
}
gulp.task('build', () => {
del.sync(['bin/**/*.*']);
const tsCompile = gulp.src('src/**/*.ts')
.pipe(gulp_sourcemaps.init({ base: 'src' }))
.pipe(project());
tsCompile.pipe(gulp.dest('bin/'));
gulp.src('src/**/*.js').pipe(gulp.dest('bin/'));
gulp.src('src/**/*.json').pipe(gulp.dest('bin/'));
gulp.src('src/**/*.lang').pipe(gulp.dest('bin/'));
return tsCompile.js
.pipe(gulp_sourcemaps.mapSources(sourcePath => path.join(__dirname, 'src', sourcePath)))
.pipe(gulp_sourcemaps.write())
.pipe(gulp.dest('bin/'));
});
gulp.task(module + ':dev', () => {
return packages[module]
.src()
.pipe(sourcemaps.init())
.pipe(packages[module]())
.pipe(
sourcemaps.mapSources(sourcePath => './' + sourcePath.split('/').pop()),
)
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${dist}/${module}`));
});
});
gulp.task('shop-js', function () {
return gulp.src(paths.shop.js, { base: './' })
.pipe(gulpif(env !== 'prod', sourcemaps.init()))
.pipe(concat('app.js'))
.pipe(gulpif(env === 'prod', uglify()))
.pipe(gulpif(env !== 'prod', sourcemaps.mapSources(mapSourcePath)))
.pipe(gulpif(env !== 'prod', sourcemaps.write('./')))
.pipe(gulp.dest(shopRootPath + 'js/'))
;
});
gulp.task(module + ':dev', () => {
return packages[module]
.src()
.pipe(sourcemaps.init())
.pipe(packages[module]())
.pipe(
sourcemaps.mapSources(sourcePath => './' + sourcePath.split('/').pop()),
)
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${dist}/${module}`));
});
});
const cssStream = gulp.src(paths.admin.css, { base: './' })
.pipe(gulpif(options.sourcemaps, sourcemaps.init()))
.pipe(concat('css-files.css'));
const sassStream = gulp.src(paths.admin.sass, { base: './' })
.pipe(gulpif(options.sourcemaps, sourcemaps.init()))
.pipe(sass())
.pipe(concat('sass-files.scss'));
return merge(
copyStream,
merge(cssStream, sassStream)
.pipe(order(['css-files.css', 'sass-files.scss']))
.pipe(concat('style.css'))
.pipe(gulpif(options.minify, uglifycss()))
.pipe(gulpif(options.sourcemaps, sourcemaps.mapSources(mapSourcePath)))
.pipe(gulpif(options.sourcemaps, sourcemaps.write('./')))
.pipe(gulp.dest(upath.joinSafe(adminRootPath, 'css')))
.pipe(livereload()),
);
};
buildAdminCss.description = 'Build admin css assets.';
function compile() {
var project = ts.createProject('tsconfig.json');
return project.src()
.pipe(sourcemaps.init())
.pipe(project())
.pipe(sourcemaps.mapSources((sourcePath, file) => {
let relativeLocation = path.join(path.relative(path.join('out', path.dirname(file.relative)), '.'), 'src/');
let relativeLocationToFile = path.join(relativeLocation, sourcePath);
return relativeLocationToFile;
}))
.pipe(sourcemaps.write('.', {
includeContent: false
}))
.pipe(gulp.dest('out'));
}
gulp.task(compile);
gulp.task('e2e-build', ['e2e-build-common'], function () {
var tsProject = ts.createProject(__dirname + config.e2e.src + '/tsconfig.json');
return gulp.src([__dirname + config.e2e.src + '/**/*.ts', '!' + __dirname + config.e2e.src + '/**/*.d.ts'])
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(sourcemaps.mapSources(function (sourcePath, file) {
var sourcePath = sourcePath.replace('../../', '');
var folderDepth = sourcePath.split('/').length;
var newPath = '';
for (var i = 0; i < folderDepth; i++) {
newPath += '../';
}
newPath += '..' + config.e2e.src + '/' + sourcePath;
return newPath;
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(__dirname + config.e2e.dest));
});
gulp.task('compileBin', () =>
gulpBin()
.pipe(gulpSourcemaps.init())
.pipe(binProject())
.pipe(gulpBanner(binBanner))
.pipe(gulpSourcemaps.mapSources(mapSources))
.pipe(gulpSourcemaps.write())
.pipe(gulp.dest(getDest(MAIN_FORMAT))),
);