avances en plantillas
This commit is contained in:
parent
0f84beacf1
commit
da0530d79b
2062 changed files with 598814 additions and 22 deletions
216
storage/public/dist/libs/plyr/tasks/build.js
vendored
Normal file
216
storage/public/dist/libs/plyr/tasks/build.js
vendored
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
import { readFileSync } from 'node:fs';
|
||||
import path, { join } from 'node:path';
|
||||
import babel from '@rollup/plugin-babel';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import resolve from '@rollup/plugin-node-resolve';
|
||||
import autoprefixer from 'autoprefixer';
|
||||
import browserSync from 'browser-sync';
|
||||
import cssnano from 'cssnano';
|
||||
import { deleteAsync } from 'del';
|
||||
import gulp from 'gulp';
|
||||
import rollup from 'gulp-better-rollup';
|
||||
import filter from 'gulp-filter';
|
||||
import header from 'gulp-header';
|
||||
import gulpIf from 'gulp-if';
|
||||
import imagemin from 'gulp-imagemin';
|
||||
import plumber from 'gulp-plumber';
|
||||
import postcss from 'gulp-postcss';
|
||||
import rename from 'gulp-rename';
|
||||
import sass from 'gulp-sass';
|
||||
import size from 'gulp-size';
|
||||
import sourcemaps from 'gulp-sourcemaps';
|
||||
import svgstore from 'gulp-svgstore';
|
||||
import terser from 'gulp-terser';
|
||||
import imageminSvgo from 'imagemin-svgo';
|
||||
import customprops from 'postcss-custom-properties';
|
||||
import * as dartSass from 'sass';
|
||||
|
||||
const jobs = JSON.parse(readFileSync(join(path.resolve(), 'build.json'), 'utf-8'));
|
||||
|
||||
const bs = browserSync.create();
|
||||
const sassCompiler = sass(dartSass);
|
||||
const minSuffix = '.min';
|
||||
|
||||
// Paths
|
||||
const root = path.resolve();
|
||||
const paths = {
|
||||
plyr: {
|
||||
src: {
|
||||
sass: path.join(root, 'src/sass/**/*.scss'),
|
||||
js: path.join(root, 'src/js/**/*.js'),
|
||||
sprite: path.join(root, 'src/sprite/*.svg'),
|
||||
},
|
||||
output: path.join(root, 'dist/'),
|
||||
},
|
||||
demo: {
|
||||
src: {
|
||||
sass: path.join(root, 'demo/src/sass/**/*.scss'),
|
||||
js: path.join(root, 'demo/src/js/**/*.js'),
|
||||
},
|
||||
output: path.join(root, 'demo/dist/'),
|
||||
root: path.join(root, 'demo/'),
|
||||
},
|
||||
};
|
||||
|
||||
// Task lists
|
||||
const tasks = {
|
||||
css: [],
|
||||
js: [],
|
||||
sprite: [],
|
||||
};
|
||||
|
||||
// Size plugin options
|
||||
const sizeOptions = { showFiles: true, gzip: true };
|
||||
|
||||
// Clean task
|
||||
export async function clean() {
|
||||
const dirs = [paths.plyr.output, paths.demo.output].map(dir => path.join(dir, '**/*'));
|
||||
dirs.push(`!${path.join(paths.plyr.output, '**/*.mp4')}`);
|
||||
return await deleteAsync(dirs);
|
||||
};
|
||||
|
||||
// JavaScript tasks
|
||||
Object.entries(jobs.js).forEach(([filename, entry]) => {
|
||||
const { dist, formats, namespace, polyfill, src } = entry;
|
||||
|
||||
formats.forEach((format) => {
|
||||
const name = `js:${filename}:${format}`;
|
||||
const extension = format === 'es' ? 'mjs' : 'js';
|
||||
tasks.js.push(name);
|
||||
|
||||
gulp.task(name, () =>
|
||||
gulp
|
||||
.src(src)
|
||||
.pipe(plumber())
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(
|
||||
rollup(
|
||||
{
|
||||
plugins: [
|
||||
resolve(),
|
||||
commonjs(),
|
||||
babel({
|
||||
babelHelpers: 'bundled',
|
||||
presets: [
|
||||
[
|
||||
'@babel/env',
|
||||
{
|
||||
useBuiltIns: polyfill ? 'usage' : false,
|
||||
corejs: polyfill ? 3 : undefined,
|
||||
bugfixes: true,
|
||||
},
|
||||
],
|
||||
],
|
||||
plugins: [
|
||||
'@babel/plugin-proposal-class-properties',
|
||||
'@babel/plugin-transform-nullish-coalescing-operator',
|
||||
'@babel/plugin-proposal-optional-chaining',
|
||||
],
|
||||
babelrc: false,
|
||||
exclude: [/\/core-js\//],
|
||||
}),
|
||||
],
|
||||
},
|
||||
{
|
||||
name: namespace,
|
||||
format,
|
||||
},
|
||||
),
|
||||
)
|
||||
.pipe(gulpIf(() => extension !== 'mjs', header('typeof navigator === "object" && ')))
|
||||
.pipe(rename({ extname: `.${extension}` }))
|
||||
.pipe(gulp.dest(dist))
|
||||
.pipe(filter(`**/*.${extension}`))
|
||||
.pipe(terser())
|
||||
.pipe(rename({ suffix: minSuffix }))
|
||||
.pipe(size(sizeOptions))
|
||||
.pipe(sourcemaps.write(''))
|
||||
.pipe(gulp.dest(dist)));
|
||||
});
|
||||
});
|
||||
|
||||
// CSS tasks
|
||||
Object.entries(jobs.css).forEach(([filename, entry]) => {
|
||||
const { dist, src } = entry;
|
||||
const name = `css:${filename}`;
|
||||
tasks.css.push(name);
|
||||
|
||||
gulp.task(name, () =>
|
||||
gulp
|
||||
.src(src)
|
||||
.pipe(plumber())
|
||||
.pipe(sassCompiler())
|
||||
.pipe(
|
||||
postcss([
|
||||
customprops(),
|
||||
autoprefixer(),
|
||||
cssnano({ preset: 'default' }),
|
||||
]),
|
||||
)
|
||||
.pipe(size(sizeOptions))
|
||||
.pipe(gulp.dest(dist)));
|
||||
});
|
||||
|
||||
// SVG Sprite tasks
|
||||
Object.entries(jobs.sprite).forEach(([filename, entry]) => {
|
||||
const { dist, src } = entry;
|
||||
const name = `sprite:${filename}`;
|
||||
tasks.sprite.push(name);
|
||||
|
||||
gulp.task(name, () =>
|
||||
gulp
|
||||
.src(src)
|
||||
.pipe(plumber())
|
||||
.pipe(
|
||||
imagemin([
|
||||
imageminSvgo({
|
||||
plugins: [
|
||||
{
|
||||
name: 'preset-default',
|
||||
params: {
|
||||
overrides: {
|
||||
removeViewBox: false, // Keep viewBox attribute
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
]),
|
||||
)
|
||||
.pipe(svgstore())
|
||||
.pipe(rename({ basename: path.parse(filename).name }))
|
||||
.pipe(size(sizeOptions))
|
||||
.pipe(gulp.dest(dist)));
|
||||
});
|
||||
|
||||
// Build tasks
|
||||
export const js = gulp.parallel(...tasks.js);
|
||||
export const css = gulp.parallel(...tasks.css);
|
||||
export const sprites = gulp.parallel(...tasks.sprite);
|
||||
|
||||
// Watch task
|
||||
export function watch() {
|
||||
gulp.watch(paths.plyr.src.js, js);
|
||||
gulp.watch(paths.plyr.src.sass, css);
|
||||
gulp.watch(paths.plyr.src.sprite, sprites);
|
||||
gulp.watch(paths.demo.src.js, js);
|
||||
gulp.watch(paths.demo.src.sass, css);
|
||||
}
|
||||
|
||||
// Serve task
|
||||
export function serve() {
|
||||
return bs.init({
|
||||
server: {
|
||||
baseDir: paths.demo.root,
|
||||
},
|
||||
notify: false,
|
||||
watch: true,
|
||||
ghostMode: false,
|
||||
});
|
||||
}
|
||||
|
||||
// Build distribution
|
||||
export const build = gulp.series(clean, gulp.parallel(js, css, sprites));
|
||||
|
||||
// Default task
|
||||
export default gulp.series(build, gulp.parallel(serve, watch));
|
||||
212
storage/public/dist/libs/plyr/tasks/deploy.js
vendored
Normal file
212
storage/public/dist/libs/plyr/tasks/deploy.js
vendored
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
import { readFileSync } from 'node:fs';
|
||||
import path, { join } from 'node:path';
|
||||
import process from 'node:process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { S3Client } from '@aws-sdk/client-s3';
|
||||
import aws from 'aws-sdk';
|
||||
import { bold, cyan, green } from 'colorette';
|
||||
import log from 'fancy-log';
|
||||
import gitbranch from 'git-branch';
|
||||
import gulp from 'gulp';
|
||||
import open from 'gulp-open';
|
||||
import rename from 'gulp-rename';
|
||||
import replace from 'gulp-replace';
|
||||
import size from 'gulp-size';
|
||||
|
||||
import { publish } from './utils/publish.js';
|
||||
import 'dotenv/config';
|
||||
|
||||
// Convert `import.meta.url` to `__filename` and `__dirname`
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const pkg = JSON.parse(readFileSync(join(path.resolve(), 'package.json'), 'utf-8'));
|
||||
const config = JSON.parse(readFileSync(join(path.resolve(), 'deploy.json'), 'utf-8'));
|
||||
|
||||
// Info from package
|
||||
const { version } = pkg;
|
||||
const minSuffix = '.min';
|
||||
|
||||
// Get AWS config
|
||||
const jobs = Object.fromEntries(Object.entries(config).map(([name, options]) => [name, {
|
||||
...options,
|
||||
client: options.type === 'r2'
|
||||
? new S3Client({
|
||||
region: 'auto',
|
||||
credentials: {
|
||||
accessKeyId: process.env.R2_ACCESS_KEY_ID,
|
||||
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY,
|
||||
},
|
||||
endpoint: `https://${process.env.CF_ACCOUNT_ID}.r2.cloudflarestorage.com`,
|
||||
})
|
||||
: new S3Client({
|
||||
region: options.region,
|
||||
credentials: new aws.SharedIniFileCredentials({ profile: 'plyr' }),
|
||||
}),
|
||||
}]));
|
||||
|
||||
// Paths
|
||||
const root = path.join(__dirname, '..');
|
||||
const paths = {
|
||||
demo: path.join(root, 'demo/'),
|
||||
upload: [
|
||||
path.join(root, `dist/*${minSuffix}.*`),
|
||||
path.join(root, 'dist/*.css'),
|
||||
path.join(root, 'dist/*.svg'),
|
||||
path.join(root, `demo/dist/*${minSuffix}.*`),
|
||||
path.join(root, 'demo/dist/*.css'),
|
||||
path.join(root, 'demo/dist/*.svg'),
|
||||
],
|
||||
};
|
||||
|
||||
// Get git branch info
|
||||
const currentBranch = (() => {
|
||||
try {
|
||||
return gitbranch.sync();
|
||||
}
|
||||
catch {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
|
||||
const branch = {
|
||||
current: currentBranch,
|
||||
isMaster: currentBranch === 'master',
|
||||
isBeta: currentBranch === 'beta',
|
||||
};
|
||||
|
||||
const maxAge = 31536000; // 1 year
|
||||
const options = {
|
||||
cdn: {
|
||||
headers: {
|
||||
'Cache-Control': `max-age=${maxAge}, immutable`,
|
||||
},
|
||||
},
|
||||
demo: {
|
||||
uploadPath: branch.isBeta ? '/beta' : null,
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// Size plugin
|
||||
const sizeOptions = { showFiles: true, gzip: true };
|
||||
|
||||
const regex = '(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)(?:-[\\da-z\\-]+(?:\\.[\\da-z\\-]+)*)?(?:\\+[\\da-z\\-]+(?:\\.[\\da-z\\-]+)*)?';
|
||||
const semver = new RegExp(`v${regex}`, 'gi');
|
||||
const localPath = /(..\/)?dist\//gi;
|
||||
const versionPath = `https://${jobs.cdn.domain}/${version}/`;
|
||||
const cdnPath = new RegExp(`${jobs.cdn.domain}/${regex}/`, 'gi');
|
||||
|
||||
const renameFile = rename((p) => {
|
||||
p.basename = p.basename.replace(minSuffix, '');
|
||||
p.dirname = p.dirname.replace('.', version);
|
||||
});
|
||||
|
||||
// Check we're on the correct branch to deploy
|
||||
function canDeploy() {
|
||||
if (![branch.isMaster, branch.isBeta].some(Boolean)) {
|
||||
console.error(`Must be on an allowed branch to publish! (current: ${branch.current})`);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function prepare(done) {
|
||||
if (!canDeploy()) {
|
||||
done();
|
||||
return null;
|
||||
}
|
||||
|
||||
const { domain } = jobs.cdn;
|
||||
|
||||
log(`Updating version in files to ${green(bold(version))}...`);
|
||||
|
||||
// Replace versioned URLs in source
|
||||
const files = ['plyr.js', 'plyr.polyfilled.js', 'config/defaults.js'];
|
||||
|
||||
return gulp
|
||||
.src(
|
||||
files.map(file => path.join(root, `src/js/${file}`)),
|
||||
{ base: '.' },
|
||||
)
|
||||
.pipe(replace(semver, `v${version}`))
|
||||
.pipe(replace(cdnPath, `${domain}/${version}/`))
|
||||
.pipe(gulp.dest('./'));
|
||||
}
|
||||
|
||||
function cdn(done) {
|
||||
if (!canDeploy()) {
|
||||
done();
|
||||
return null;
|
||||
}
|
||||
|
||||
const { domain, client, bucket } = jobs.cdn;
|
||||
|
||||
log(`Uploading ${green(bold(pkg.version))} to ${cyan(domain)}...`);
|
||||
|
||||
// Upload to CDN
|
||||
return gulp
|
||||
.src(paths.upload)
|
||||
.pipe(renameFile)
|
||||
.pipe(
|
||||
replace(
|
||||
/sourceMappingURL=([\w\-?.]+)/,
|
||||
(_, filename) => `sourceMappingURL=${filename.replace(minSuffix, '')}`,
|
||||
),
|
||||
)
|
||||
.pipe(size(sizeOptions))
|
||||
.pipe(replace(localPath, versionPath))
|
||||
.pipe(publish(client, bucket, options.cdn.headers));
|
||||
}
|
||||
|
||||
function demo(done) {
|
||||
if (!canDeploy()) {
|
||||
done();
|
||||
return null;
|
||||
}
|
||||
|
||||
const { client, bucket, domain } = jobs.demo;
|
||||
log(`Uploading ${green(bold(pkg.version))} to ${cyan(domain)}...`);
|
||||
|
||||
// Replace versioned files in README.md
|
||||
gulp
|
||||
.src([`${root}/README.md`])
|
||||
.pipe(replace(cdnPath, `${jobs.cdn.domain}/${version}/`))
|
||||
.pipe(gulp.dest(root));
|
||||
|
||||
// Replace local file paths with remote paths in demo HTML
|
||||
const index = `${paths.demo}index.html`;
|
||||
const error = `${paths.demo}error.html`;
|
||||
const pages = [index];
|
||||
|
||||
if (branch.isMaster) {
|
||||
pages.push(error);
|
||||
}
|
||||
|
||||
return gulp
|
||||
.src(pages)
|
||||
.pipe(replace(localPath, versionPath))
|
||||
.pipe(
|
||||
rename((p) => {
|
||||
if (options.demo.uploadPath) {
|
||||
p.dirname += options.demo.uploadPath;
|
||||
}
|
||||
}),
|
||||
)
|
||||
.pipe(publish(client, bucket, options.demo.headers));
|
||||
}
|
||||
|
||||
function preview() {
|
||||
const { domain } = jobs.demo;
|
||||
|
||||
return gulp.src(__filename).pipe(
|
||||
open({
|
||||
uri: `https://${domain}/${branch.isBeta ? 'beta' : ''}`,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export const deploy = gulp.series(cdn, demo, preview);
|
||||
34
storage/public/dist/libs/plyr/tasks/utils/publish.js
vendored
Normal file
34
storage/public/dist/libs/plyr/tasks/utils/publish.js
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { PutObjectCommand } from '@aws-sdk/client-s3';
|
||||
import mime from 'mime';
|
||||
import through from 'through2';
|
||||
|
||||
export function publish(client, bucket, headers = {}) {
|
||||
return through.obj(async function (file, _, callback) {
|
||||
if (!file.isBuffer()) return callback(null, file);
|
||||
|
||||
// Use the relative path as the key
|
||||
const key = file.relative.replace(/\\/g, '/'); // Ensure forward slashes for S3 keys
|
||||
|
||||
// Determine the MIME type of the file
|
||||
const contentType = mime.getType(file.path) || 'application/octet-stream';
|
||||
|
||||
try {
|
||||
await client.send(
|
||||
new PutObjectCommand({
|
||||
Bucket: bucket,
|
||||
Key: key,
|
||||
Body: file.contents,
|
||||
ContentType: contentType, // Set the MIME type
|
||||
CacheControl: headers['Cache-Control'], // Use provided Cache-Control header
|
||||
}),
|
||||
);
|
||||
|
||||
console.warn(`Uploaded: ${key} (Content-Type: ${contentType})`);
|
||||
this.push(file);
|
||||
callback();
|
||||
}
|
||||
catch (err) {
|
||||
callback(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue