push the uni-demo project
This commit is contained in:
118
uni-demo/node_modules/zrender/build/build.js
generated
vendored
Normal file
118
uni-demo/node_modules/zrender/build/build.js
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
// const typescript = require('@rollup/plugin-typescript');
|
||||
const typescript = require('rollup-plugin-typescript2');
|
||||
const replace = require('@rollup/plugin-replace');
|
||||
const rollup = require('rollup');
|
||||
const path = require('path');
|
||||
const processs = require('process');
|
||||
const chalk = require('chalk');
|
||||
const progress = require('./progress');
|
||||
const UglifyJS = require('uglify-js');
|
||||
const fs = require('fs');
|
||||
|
||||
function current() {
|
||||
return (new Date()).toLocaleString();
|
||||
}
|
||||
|
||||
function createInputOption(env, isWatch) {
|
||||
return {
|
||||
input: path.resolve(__dirname, '../index.ts'),
|
||||
plugins: [
|
||||
typescript({
|
||||
clean: !isWatch,
|
||||
tsconfigOverride: {
|
||||
compilerOptions: {
|
||||
// Rollup don't use CommonJS by default.
|
||||
module: 'ES2015',
|
||||
sourceMap: true,
|
||||
// Use the esm d.ts
|
||||
declaration: false
|
||||
}
|
||||
}
|
||||
}),
|
||||
replace({
|
||||
preventAssignment: true,
|
||||
'process.env.NODE_ENV': JSON.stringify(env)
|
||||
}),
|
||||
progress({
|
||||
scope: {
|
||||
total: 0
|
||||
}
|
||||
})
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
const outputOption = {
|
||||
format: 'umd',
|
||||
file: path.resolve(__dirname, '../dist/zrender.js'),
|
||||
sourcemap: true,
|
||||
name: 'zrender'
|
||||
};
|
||||
|
||||
function minify(outPath) {
|
||||
const code = fs.readFileSync(outPath, 'utf-8');
|
||||
const uglifyResult = UglifyJS.minify(code);
|
||||
if (uglifyResult.error) {
|
||||
throw new Error(uglifyResult.error);
|
||||
}
|
||||
fs.writeFileSync(outPath, uglifyResult.code, 'utf-8');
|
||||
}
|
||||
|
||||
if (processs.argv.includes('--watch')) {
|
||||
const watcher = rollup.watch({
|
||||
...createInputOption('development', true),
|
||||
output: [outputOption],
|
||||
watch: {
|
||||
clearScreen: true
|
||||
}
|
||||
});
|
||||
watcher.on('event', event => {
|
||||
switch(event.code) {
|
||||
// case 'START':
|
||||
// console.log(chalk.green('Begin to watch'));
|
||||
// break;
|
||||
case 'BUNDLE_START':
|
||||
console.log(
|
||||
chalk.gray(current()),
|
||||
chalk.blue('File changed. Begin to bundle')
|
||||
);
|
||||
break;
|
||||
case 'BUNDLE_END':
|
||||
console.log(
|
||||
chalk.gray(current()),
|
||||
chalk.green('Finished bundle')
|
||||
);
|
||||
break;
|
||||
case 'ERROR':
|
||||
console.log(
|
||||
chalk.gray(current()),
|
||||
chalk.red(event.error)
|
||||
);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Unminified
|
||||
rollup.rollup({
|
||||
...createInputOption('development', false)
|
||||
}).then(bundle => {
|
||||
bundle.write(outputOption)
|
||||
.then(() => {
|
||||
// Minified
|
||||
if (process.argv.indexOf('--minify') >= 0) {
|
||||
rollup.rollup({
|
||||
...createInputOption('production', false)
|
||||
}).then(bundle => {
|
||||
const file = outputOption.file.replace(/.js$/, '.min.js');
|
||||
bundle.write(Object.assign(outputOption, {
|
||||
file,
|
||||
sourcemap: false
|
||||
})).then(function () {
|
||||
minify(file);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
38
uni-demo/node_modules/zrender/build/prepareNightly.js
generated
vendored
Normal file
38
uni-demo/node_modules/zrender/build/prepareNightly.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
const fs = require('fs');
|
||||
const packageJsonPath = __dirname + '/../package.json';
|
||||
const nightlyPackageName = 'zrender-nightly';
|
||||
|
||||
function updateVersion(version) {
|
||||
const isNext = process.argv.includes('--next');
|
||||
const parts = /(\d+)\.(\d+)\.(\d+)($|\-)/.exec(version);
|
||||
if (!parts) {
|
||||
throw new Error(`Invalid version number ${version}`);
|
||||
}
|
||||
// Add date to version.
|
||||
const major = +parts[1];
|
||||
let minor = +parts[2];
|
||||
let patch = +parts[3];
|
||||
const isStable = !parts[4];
|
||||
if (isStable) {
|
||||
// It's previous stable version. Dev version should be higher.
|
||||
if (isNext) {
|
||||
// Increase minor version for next branch.
|
||||
minor++;
|
||||
patch = 0;
|
||||
}
|
||||
else {
|
||||
// Increase main version for master branch.
|
||||
patch++;
|
||||
}
|
||||
}
|
||||
|
||||
const date = new Date().toISOString().replace(/:|T|\.|-/g, '').slice(0, 8);
|
||||
return `${major}.${minor}.${patch}-dev.${date}`;
|
||||
}
|
||||
|
||||
|
||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
||||
packageJson.name = nightlyPackageName;
|
||||
packageJson.version = updateVersion(packageJson.version);
|
||||
|
||||
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');
|
||||
67
uni-demo/node_modules/zrender/build/processLib.js
generated
vendored
Normal file
67
uni-demo/node_modules/zrender/build/processLib.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
// Porcess generated lib files.
|
||||
// Like adding js extension in the import statement.
|
||||
|
||||
const { transformImport } = require('./transformImport');
|
||||
const globby = require('globby');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const chalk = require('chalk');
|
||||
const rollup = require('rollup');
|
||||
const nodeResolve = require('@rollup/plugin-node-resolve').default;
|
||||
|
||||
function addJsExtension(moduleName) {
|
||||
// Ignore 'tslib'
|
||||
if (!(moduleName.startsWith('.'))) {
|
||||
return moduleName;
|
||||
}
|
||||
if (moduleName.endsWith('.ts')) {
|
||||
// Replace ts with js
|
||||
return moduleName.replace(/\.ts$/, '.js');
|
||||
}
|
||||
else if (moduleName.endsWith('.js')) {
|
||||
return moduleName;
|
||||
}
|
||||
else {
|
||||
return moduleName + '.js'
|
||||
}
|
||||
}
|
||||
|
||||
async function transform() {
|
||||
const libFiles = await globby([
|
||||
'**/*.js'
|
||||
], {
|
||||
cwd: path.join(__dirname, '../lib'),
|
||||
absolute: true
|
||||
});
|
||||
|
||||
if (libFiles.length === 0) {
|
||||
throw new Error('No lib files found.')
|
||||
}
|
||||
|
||||
for (let file of libFiles) {
|
||||
const code = fs.readFileSync(file, 'utf-8');
|
||||
fs.writeFileSync(file, transformImport(code, addJsExtension), 'utf-8');
|
||||
}
|
||||
|
||||
// Transform index;
|
||||
const indexFile = path.join(__dirname, '../index.js');
|
||||
fs.writeFileSync(
|
||||
indexFile,
|
||||
transformImport(
|
||||
fs.readFileSync(indexFile, 'utf-8'),
|
||||
(mduleName) => addJsExtension(mduleName).replace('./src', './lib')
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
transform().then(() => {
|
||||
console.log(chalk.green('Added .js extensions.'));
|
||||
console.log(chalk.gray('Start testing generated libs...'));
|
||||
}).then(() => {
|
||||
return rollup.rollup({
|
||||
input: path.resolve(__dirname, '../index.js'),
|
||||
plugins: [nodeResolve()]
|
||||
});
|
||||
}).then(() => {
|
||||
console.log(chalk.green('Libs can be bundled!'));
|
||||
});
|
||||
65
uni-demo/node_modules/zrender/build/progress.js
generated
vendored
Normal file
65
uni-demo/node_modules/zrender/build/progress.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
const chalk = require('chalk');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = function progress(options = {}) {
|
||||
const scope = options.scope || {};
|
||||
scope.finished = scope.finished || 0;
|
||||
scope.total = scope.total || 0;
|
||||
|
||||
return {
|
||||
name: 'progress',
|
||||
|
||||
buildStart() {
|
||||
scope.finished = 0;
|
||||
scope.total = 0;
|
||||
},
|
||||
|
||||
load() {
|
||||
// TODO More accurate total number
|
||||
scope.total++;
|
||||
},
|
||||
|
||||
transform(code, id) {
|
||||
scope.finished++;
|
||||
const filePath = path.relative(process.cwd(), id).split(path.sep).join('/');
|
||||
|
||||
const output = `[${scope.finished}/${scope.total}]: ${chalk.grey(filePath)}`;
|
||||
if (process.stdout.isTTY) {
|
||||
process.stdout.clearLine();
|
||||
process.stdout.cursorTo(0);
|
||||
process.stdout.write(output);
|
||||
}
|
||||
else {
|
||||
console.log(output);
|
||||
}
|
||||
},
|
||||
|
||||
buildEnd() {
|
||||
if (process.stdout.isTTY) {
|
||||
process.stdout.clearLine();
|
||||
process.stdout.cursorTo(0);
|
||||
}
|
||||
else {
|
||||
console.log('');
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
115
uni-demo/node_modules/zrender/build/transformImport.js
generated
vendored
Normal file
115
uni-demo/node_modules/zrender/build/transformImport.js
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
// adding js extension in the import statement.
|
||||
|
||||
// Reference:
|
||||
// https://regexr.com/47jlq
|
||||
// https://gist.github.com/manekinekko/7e58a17bc62a9be47172
|
||||
const regexp = /((?:(?:import)|(?:export))\s+?(?:(?:(?:[\w*\s{},\/]*)\s+from\s+?)|))(?:(?:"(.*?)")|(?:'(.*?)'))([\s]*?(?:;|$|))/g;
|
||||
|
||||
module.exports.transformImport = function (code, processModuleName) {
|
||||
return code.replace(regexp, (str, prefix, moduleNameA, moduleNameB, postfix) => {
|
||||
let moduleName = (moduleNameA === undefined ? moduleNameB : moduleNameA).trim();
|
||||
const quote = moduleNameA === undefined ? "'" : '"';
|
||||
return prefix + quote + processModuleName(moduleName) + quote + postfix;
|
||||
// Not support other extensions.
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const testCases = `import videos from './videos/index.js'
|
||||
|
||||
export default (socket, context) => {
|
||||
// dynamically importing all the socket.io handler (it's dynamic import that happen at run time)
|
||||
import {
|
||||
something
|
||||
} from "./test/okbb"
|
||||
|
||||
const f = 2;
|
||||
|
||||
import test from 'obb'
|
||||
|
||||
|
||||
import {
|
||||
Component
|
||||
} from '@angular2/core';
|
||||
|
||||
import defaultMember from "module-0";
|
||||
|
||||
import * as name from "module-1 ";
|
||||
|
||||
import { member } from " module-2";
|
||||
|
||||
import { member as alias } from "module-3";
|
||||
|
||||
import { member1 , member2 } from "module-4";
|
||||
|
||||
import { member1 , member2 as alias2 , member3 as alias3 } from "module-5";
|
||||
|
||||
import defaultMember, { member, member } from "module-6";
|
||||
|
||||
import defaultMember, * as name from "module-7";
|
||||
|
||||
import "module-8";
|
||||
|
||||
import "module-9" // comment no problem
|
||||
|
||||
import {
|
||||
AAAA,
|
||||
// BBB
|
||||
} from 'module-10';
|
||||
|
||||
import "module-b' // doesn't match -> the opening and closing quation mark are different
|
||||
|
||||
importing hya from 'ttt'
|
||||
|
||||
import fbsfrom ''
|
||||
|
||||
|
||||
// Export expressions.
|
||||
export { aaa };
|
||||
|
||||
export * from "module-11";
|
||||
|
||||
export { aaa } from "module-12";
|
||||
|
||||
// Should not be parsed
|
||||
export default aaa;
|
||||
|
||||
export function bbb () {
|
||||
};
|
||||
`
|
||||
|
||||
module.exports.runTest = function () {
|
||||
const expected = [
|
||||
'./videos/index.js',
|
||||
'./test/okbb',
|
||||
'obb',
|
||||
'@angular2/core',
|
||||
'module-0',
|
||||
'module-1',
|
||||
'module-2',
|
||||
'module-3',
|
||||
'module-4',
|
||||
'module-5',
|
||||
'module-6',
|
||||
'module-7',
|
||||
'module-8',
|
||||
'module-9',
|
||||
'module-10',
|
||||
'module-11',
|
||||
'module-12'
|
||||
]
|
||||
let cursor = 0;
|
||||
module.exports.transformImport(testCases, (moduleName) => {
|
||||
if (expected[cursor] !== moduleName) {
|
||||
throw new Error(`Expected ${expected[cursor]}. Actual ${moduleName}`);
|
||||
}
|
||||
cursor++;
|
||||
return moduleName;
|
||||
})
|
||||
if (cursor !== expected.length) {
|
||||
throw new Error('Test failed');
|
||||
}
|
||||
console.log('All test passed!')
|
||||
}
|
||||
|
||||
// module.exports.runTest();
|
||||
Reference in New Issue
Block a user