Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
game-template-egret
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
game-template-egret
Commits
abc51ea0
Commit
abc51ea0
authored
Sep 21, 2018
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将alienlib移动到外部
parent
b5467de2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
232 additions
and
15 deletions
+232
-15
package.json
package.json
+1
-1
package.json
scripts/package.json
+1
-2
rollup-compile-plugin.ts
scripts/rollup-compile-plugin.ts
+0
-12
rollup-plugin-typescript.js
scripts/rollup-plugin-typescript.js
+230
-0
No files found.
package.json
View file @
abc51ea0
...
...
@@ -4,7 +4,7 @@
"description"
:
""
,
"main"
:
"template-config.js"
,
"dependencies"
:
{
"
tslib
"
:
"
^1.9.3
"
},
"devDependencies"
:
{},
"scripts"
:
{
...
...
scripts/package.json
View file @
abc51ea0
...
...
@@ -14,11 +14,10 @@
"minimatch"
:
"^3.0.4"
,
"node-notifier"
:
"^5.2.1"
,
"rollup"
:
"^0.65.2"
,
"rollup-plugin-commonjs"
:
"^9.1.6"
,
"rollup-plugin-node-resolve"
:
"^3.4.0"
,
"rollup-plugin-typescript-path-mapping"
:
"^1.0.2"
,
"rollup-plugin-uglify"
:
"^5.0.2"
,
"tippex"
:
"^3.0.0"
,
"tslib"
:
"^1.9.3"
,
"typescript"
:
"^3.0.3"
}
}
scripts/rollup-compile-plugin.ts
View file @
abc51ea0
...
...
@@ -5,9 +5,7 @@ const rollup = require('rollup');
const
resolve
=
require
(
'rollup-plugin-node-resolve'
);
const
typescriptPlugin
=
require
(
'./rollup-plugin-typescript'
);
const
typescript
=
require
(
'typescript'
);
const
rollupPluginTypescriptPathMapping
=
require
(
'rollup-plugin-typescript-path-mapping'
);
const
{
uglify
}
=
require
(
'rollup-plugin-uglify'
);
const
commonjs
=
require
(
'rollup-plugin-commonjs'
);
const
glob
=
require
(
'glob'
);
export
class
RollupCompilePlugin
implements
plugins
.
Command
{
...
...
@@ -28,21 +26,11 @@ export class RollupCompilePlugin implements plugins.Command {
const
debugMode
=
publishPolicy
===
'debug'
;
const
tsconfig
=
require
(
'../tsconfig.json'
);
/*if (!debugMode) {
tsconfig.compilerOptions.defines = defines;
}
console.log(tsconfig);*/
let
plugins
=
[
typescriptPlugin
({
typescript
,
tsconfig
,
}),
resolve
(),
commonjs
(),
rollupPluginTypescriptPathMapping
({
tsconfig
:
true
}),
];
if
(
!
debugMode
)
{
...
...
scripts/rollup-plugin-typescript.js
0 → 100644
View file @
abc51ea0
'use strict'
;
function
_interopDefault
(
ex
)
{
return
(
ex
&&
(
typeof
ex
===
'object'
)
&&
'default'
in
ex
)
?
ex
[
'default'
]
:
ex
;
}
var
path
=
require
(
'path'
);
var
fs
=
require
(
'fs'
);
var
ts
=
require
(
'typescript'
);
var
rollupPluginutils
=
require
(
'rollup-pluginutils'
);
var
resolveId
=
_interopDefault
(
require
(
'resolve'
));
function
endsWith
(
str
,
tail
)
{
return
!
tail
.
length
||
str
.
slice
(
-
tail
.
length
)
===
tail
;
}
function
getDefaultOptions
()
{
return
{
noEmitHelpers
:
true
,
module
:
'ESNext'
,
sourceMap
:
true
,
importHelpers
:
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
getConfigContent
(
path
){
var
content
=
fs
.
readFileSync
(
path
,
'utf8'
);
/*if(process.env.hasOwnProperty('GAME_LIB_PATH')){
content = content.replace('$GAME_LIB_PATH$', process.env.GAME_LIB_PATH)
}*/
return
content
;
}
function
getCompilerOptionsFromTsConfig
(
typescript
,
tsconfigPath
)
{
if
(
tsconfigPath
&&
!
fs
.
existsSync
(
tsconfigPath
))
{
throw
new
Error
((
"Could not find specified tsconfig.json at "
+
tsconfigPath
));
}
var
existingTsConfig
=
tsconfigPath
||
findFile
(
process
.
cwd
(),
'tsconfig.json'
);
if
(
!
existingTsConfig
)
{
return
{};
}
var
tsconfig
=
typescript
.
readConfigFile
(
existingTsConfig
,
getConfigContent
);
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
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
;
}
}
};
var
TSLIB_ID
=
'
\
0tslib'
;
function
typescript
(
options
)
{
if
(
options
===
void
0
)
options
=
{};
options
=
Object
.
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 and tslib version used for helpers.
var
typescript
=
options
.
typescript
||
ts
;
var
tslib
=
options
.
tslib
||
fs
.
readFileSync
(
resolveId
.
sync
(
'tslib/tslib.es6.js'
,
{
basedir
:
__dirname
}),
'utf-8'
);
delete
options
.
typescript
;
delete
options
.
tslib
;
// Load options from `tsconfig.json` unless explicitly asked not to.
var
tsconfig
=
options
.
tsconfig
===
false
?
{}
:
getCompilerOptionsFromTsConfig
(
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
);
options
=
Object
.
assign
(
tsconfig
,
getDefaultOptions
(),
options
);
// Verify that we're targeting ES2015 modules.
var
moduleType
=
options
.
module
.
toUpperCase
();
if
(
moduleType
!==
'ES2015'
&&
moduleType
!==
'ES6'
&&
moduleType
!==
'ESNEXT'
&&
moduleType
!==
'COMMONJS'
)
{
throw
new
Error
(
(
"rollup-plugin-typescript: The module kind should be 'ES2015' or 'ESNext, 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
{
name
:
'typescript'
,
resolveId
:
function
resolveId$$1
(
importee
,
importer
)
{
if
(
importee
===
'tslib'
)
{
return
TSLIB_ID
;
}
if
(
!
importer
)
{
return
null
;
}
importer
=
importer
.
split
(
'
\
\'
).join('
/
');
var 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 === TSLIB_ID ) {
return tslib;
}
},
transform: function transform ( code, id ) {
//if ( !filter( id ) ) { return null; }
var transformed = typescript.transpileModule( code, {
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 {
code: transformed.outputText,
// Rollup expects `map` to be an object so we must parse the string
map: transformed.sourceMapText ? JSON.parse(transformed.sourceMapText) : null
};
}
};
}
module.exports = typescript;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment