Commit 76d34f28 authored by rockyl's avatar rockyl

init

parents
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless
This diff is collapsed.
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"sourceMap": true,
"removeComments": true,
"noEmitOnError": true,
"importHelpers": true,
"experimentalDecorators": true,
"lib": [
"es5",
"dom",
"es2015.promise"
]
},
"exclude": [
"node_modules"
]
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
/**
* Created by rockyl on 2018/7/6.
*/
const gutil = require('gulp-util');
const chalk = require('chalk');
const prettyTime = require('pretty-hrtime');
let gulpConfigFile;
let gulpConfig;
let cb;
exports.loadGulpFile = function (file) {
gulpConfig = require(gulpConfigFile = file);
};
exports.setTsConfig = function (tsConfig){
gulpConfig.setTsConfig(tsConfig);
};
exports.startGulpTask = function(tasks = ['default'], callback){
gulpConfig.setCallback(cb = callback);
const gulpInst = require('gulp');
logEvents(gulpInst);
process.nextTick(function() {
gulpInst.start.apply(gulpInst, tasks);
});
};
// Format orchestrator errors
function formatError(e) {
if (!e.err) {
return e.message;
}
// PluginError
if (typeof e.err.showStack === 'boolean') {
return e.err.toString();
}
// Normal error
if (e.err.stack) {
return e.err.stack;
}
// Unknown (string, number, etc.)
return new Error(String(e.err)).stack;
}
// Wire up logging events
function logEvents(gulpInst) {
// Total hack due to poor error management in orchestrator
gulpInst.on('err', function() {
//failed = true;
});
gulpInst.on('task_start', function(e) {
// TODO: batch these
// so when 5 tasks start at once it only logs one time with all 5
gutil.log('Starting', '\'' + chalk.cyan(e.task) + '\'...');
});
gulpInst.on('task_stop', function(e) {
var time = prettyTime(e.hrDuration);
gutil.log(
'Finished', '\'' + chalk.cyan(e.task) + '\'',
'after', chalk.magenta(time)
);
});
gulpInst.on('task_err', function(e) {
var msg = formatError(e);
var time = prettyTime(e.hrDuration);
gutil.log(
'\'' + chalk.cyan(e.task) + '\'',
chalk.red('errored after'),
chalk.magenta(time)
);
if (e.err && e.err.loc) {
let {file, line, column} = e.err.loc;
gutil.log(`[${line}, ${column}] ` + file);
}
gutil.log(msg);
cb(new Error('task_err'))
});
gulpInst.on('task_not_found', function(err) {
gutil.log(
chalk.red('Task \'' + err.task + '\' is not in your gulpfile')
);
gutil.log('Please check the documentation for proper gulpfile formatting');
process.exit(1);
});
}
\ No newline at end of file
/**
* Created by rockyl on 2018/8/3.
*/
const path = require('path');
const {loadGulpFile, startGulpTask, setTsConfig} = require('./gulp-helper');
const gulpFile = path.resolve(__dirname, 'dev-config', 'gulpfile.js');
const tsConfigFile = path.resolve(__dirname, 'dev-config', 'tsconfig.json');
loadGulpFile(gulpFile);
setTsConfig(tsConfigFile);
exports.runGulp = function (task) {
return new Promise((resolve, reject)=>{
startGulpTask([task], function(result){
if(typeof result === 'string'){
resolve(result);
}else{
reject(result);
}
});
})
};
/**
* Created by rockyl on 2018/9/18.
*
* build process for anniejs
*/
const {runGulp} = require('./gulp-init');
exports.dev = function(){
return runGulp('dev');
};
exports.build = function(){
return runGulp('build');
};
exports.publish = async function(){
const result = await runGulp('publish');
console.log(result);
return result;
};
This diff is collapsed.
/**
* Created by rockyl on 2018/7/6.
*/
module.exports = require('./rollup-plugin-typescript.cjs');
\ No newline at end of file
'use strict';
var ts = require('typescript');
var rollupPluginutils = require('rollup-pluginutils');
var path = require('path');
var fs = require('fs');
var assign = Object.assign;
var compareVersions = require('compare-versions');
var tippex = require('tippex');
function endsWith(str, tail) {
return !tail.length || str.slice(-tail.length) === tail;
}
function getDefaultOptions() {
return {
noEmitHelpers: true,
module: 'es2015',
sourceMap: true
};
}
// Gratefully lifted from 'look-up', due to problems using it directly:
// https://github.com/jonschlinkert/look-up/blob/master/index.js
// MIT Licenced
function findFile(cwd, filename) {
var fp = cwd ? (cwd + '/' + filename) : filename;
if (fs.existsSync(fp)) {
return fp;
}
var segs = cwd.split(path.sep);
var len = segs.length;
while (len--) {
cwd = segs.slice(0, len).join('/');
fp = cwd + '/' + filename;
if (fs.existsSync(fp)) {
return fp;
}
}
return null;
}
function compilerOptionsFromTsConfig(typescript, tsconfig) {
var cwd = process.cwd();
var tsconfig = typescript.readConfigFile(
tsconfig,//findFile(cwd, 'tsconfig.json'),
function (path) {
return fs.readFileSync(path, 'utf8');
}
);
if (!tsconfig.config || !tsconfig.config.compilerOptions) return {};
return tsconfig.config.compilerOptions;
}
function adjustCompilerOptions(typescript, options) {
// Set `sourceMap` to `inlineSourceMap` if it's a boolean
// under the assumption that both are never specified simultaneously.
if (typeof options.inlineSourceMap === 'boolean') {
options.sourceMap = options.inlineSourceMap;
delete options.inlineSourceMap;
}
// Delete the `declaration` option to prevent compilation error.
// See: https://github.com/rollup/rollup-plugin-typescript/issues/45
delete options.declaration;
var tsVersion = typescript.version.split('-')[0];
if ('strictNullChecks' in options && compareVersions(tsVersion, '1.9.0') < 0) {
delete options.strictNullChecks;
console.warn("rollup-plugin-typescript: 'strictNullChecks' is not supported; disabling it");
}
}
// Hack around TypeScript's broken handling of `export class` with
// ES6 modules and ES5 script target.
//
// It works because TypeScript transforms
//
// export class A {}
//
// into something like CommonJS, when we wanted ES6 modules.
//
// var A = (function () {
// function A() {
// }
// return A;
// }());
// exports.A = A;
//
// But
//
// class A {}
// export { A };
//
// is transformed into this beauty.
//
// var A = (function () {
// function A() {
// }
// return A;
// }());
// export { A };
//
// The solution is to replace the previous export syntax with the latter.
function fix(code, id) {
// Erase comments, strings etc. to avoid erroneous matches for the Regex.
var cleanCode = getErasedCode(code, id);
var re = /export\s+(default\s+)?((?:abstract\s+)?class)(?:\s+(\w+))?/g;
var match;
while (match = re.exec(cleanCode)) {
// To keep source maps intact, replace non-whitespace characters with spaces.
code = erase(code, match.index, match[0].indexOf(match[2]));
var name = match[3];
if (match[1]) { // it is a default export
// TODO: support this too
if (!name) throw new Error(("TypeScript Plugin: cannot export an un-named class (module " + id + ")"));
// Export the name ` as default`.
name += ' as default';
}
// To keep source maps intact, append the injected exports last.
code += "\nexport { " + name + " };";
}
return code;
}
function getErasedCode(code, id) {
try {
return tippex.erase(code);
} catch (e) {
throw new Error(("rollup-plugin-typescript: " + (e.message) + "; when processing: '" + id + "'"));
}
}
function erase(code, start, length) {
var end = start + length;
return code.slice(0, start) +
code.slice(start, end).replace(/[^\s]/g, ' ') +
code.slice(end);
}
var resolveHost = {
directoryExists: function directoryExists(dirPath) {
try {
return fs.statSync(dirPath).isDirectory();
} catch (err) {
return false;
}
},
fileExists: function fileExists(filePath) {
try {
return fs.statSync(filePath).isFile();
} catch (err) {
return false;
}
}
};
/*
interface Options {
tsconfig?: boolean;
include?: string | string[];
exclude?: string | string[];
typescript?: typeof ts;
module?: string;
}
*/
// The injected id for helpers. Intentially invalid to prevent helpers being included in source maps.
var helpersId = '\0typescript-helpers';
var helpersSource = fs.readFileSync(path.resolve(__dirname, './typescript-helpers.js'), 'utf-8');
function typescript(options) {
options = assign({}, options || {});
var filter = rollupPluginutils.createFilter(
options.include || ['*.ts+(|x)', '**/*.ts+(|x)'],
options.exclude || ['*.d.ts', '**/*.d.ts']);
delete options.include;
delete options.exclude;
// Allow users to override the TypeScript version used for transpilation.
var typescript = options.typescript || ts;
delete options.typescript;
// Load options from `tsconfig.json` unless explicitly asked not to.
var tsconfig = options.tsconfig === false ? {} :
compilerOptionsFromTsConfig(typescript, options.tsconfig);
delete options.tsconfig;
// Since the CompilerOptions aren't designed for the Rollup
// use case, we'll adjust them for use with Rollup.
adjustCompilerOptions(typescript, tsconfig);
adjustCompilerOptions(typescript, options);
// Merge all options.
options = assign(tsconfig, getDefaultOptions(), options);
// Verify that we're targeting ES2015 modules.
if (options.module !== 'es2015' && options.module !== 'es6') {
throw new Error(("rollup-plugin-typescript: The module kind should be 'es2015', found: '" + (options.module) + "'"));
}
var parsed = typescript.convertCompilerOptionsFromJson(options, process.cwd());
if (parsed.errors.length) {
parsed.errors.forEach(function (error) {
return console.error(("rollup-plugin-typescript: " + (error.messageText)));
});
throw new Error("rollup-plugin-typescript: Couldn't process compiler options");
}
var compilerOptions = parsed.options;
return {
resolveId: function resolveId(importee, importer) {
// Handle the special `typescript-helpers` import itself.
if (importee === helpersId) {
return helpersId;
}
if (!importer) return null;
var result;
importer = importer.split('\\').join('/');
if (compareVersions(typescript.version, '1.8.0') < 0) {
// Suppress TypeScript warnings for function call.
result = typescript.nodeModuleNameResolver(importee, importer, resolveHost);
} else {
result = typescript.nodeModuleNameResolver(importee, importer, compilerOptions, resolveHost);
}
if (result.resolvedModule && result.resolvedModule.resolvedFileName) {
if (endsWith(result.resolvedModule.resolvedFileName, '.d.ts')) {
return null;
}
return result.resolvedModule.resolvedFileName;
}
return null;
},
load: function load(id) {
if (id === helpersId) {
return helpersSource;
}
},
transform: function transform(code, id) {
if (!filter(id)) return null;
var transformed = typescript.transpileModule(fix(code, id), {
fileName: id,
reportDiagnostics: true,
compilerOptions: compilerOptions
});
// All errors except `Cannot compile modules into 'es6' when targeting 'ES5' or lower.`
var diagnostics = transformed.diagnostics ?
transformed.diagnostics.filter(function (diagnostic) {
return diagnostic.code !== 1204;
}) : [];
var fatalError = false;
diagnostics.forEach(function (diagnostic) {
var message = typescript.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
if (diagnostic.file) {
var ref = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
var line = ref.line;
var character = ref.character;
console.error(((diagnostic.file.fileName) + "(" + (line + 1) + "," + (character + 1) + "): error TS" + (diagnostic.code) + ": " + message));
} else {
console.error(("Error: " + message));
}
if (diagnostic.category === ts.DiagnosticCategory.Error) {
fatalError = true;
}
});
if (fatalError) {
throw new Error("There were TypeScript errors transpiling");
}
return {
// Always append an import for the helpers.
code: transformed.outputText +
"\nimport { __assign, __awaiter, __extends, __decorate, __metadata, __param } from '" + helpersId + "';",
// Rollup expects `map` to be an object so we must parse the string
map: transformed.sourceMapText ? JSON.parse(transformed.sourceMapText) : null
};
}
};
}
module.exports = typescript;
\ No newline at end of file
export const __assign = Object.assign || function (target) {
for (var source, i = 1; i < arguments.length; i++) {
source = arguments[i];
for (var prop in source) {
if (Object.prototype.hasOwnProperty.call(source, prop)) {
target[prop] = source[prop];
}
}
}
return target;
};
export function __extends(d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
export function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
export function __metadata(k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
}
export function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
export function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment