11const babel = require ( 'gulp-babel' ) ;
2- const browserify = require ( 'browserify' ) ;
3- const derequire = require ( 'gulp-derequire' ) ;
42const gulp = require ( 'gulp' ) ;
5- const insert = require ( 'gulp-insert' ) ;
63const path = require ( 'path' ) ;
7- const rename = require ( 'gulp-rename' ) ;
8- const source = require ( 'vinyl-source-stream' ) ;
9- const uglify = require ( 'gulp-uglify' ) ;
104const watch = require ( 'gulp-watch' ) ;
115
126const BUILD = process . env . PARSE_BUILD || 'browser' ;
13- const VERSION = require ( './package.json' ) . version ;
147
158const transformRuntime = [ "@babel/plugin-transform-runtime" , {
169 "corejs" : 3 ,
@@ -32,39 +25,14 @@ const PRESETS = {
3225 'react-native' : [ "@babel/preset-typescript" , 'module:metro-react-native-babel-preset' ] ,
3326} ;
3427const PLUGINS = {
35- 'browser' : [ transformRuntime , '@babel/plugin-proposal-class-properties' , 'inline-package-json' ,
28+ 'browser' : [ transformRuntime , '@babel/plugin-proposal-class-properties' ,
3629 [ 'transform-inline-environment-variables' , { 'exclude' : [ 'SERVER_RENDERING' ] } ] ] ,
37- 'weapp' : [ transformRuntime , '@babel/plugin-proposal-class-properties' , 'inline-package-json' ,
30+ 'weapp' : [ transformRuntime , '@babel/plugin-proposal-class-properties' ,
3831 [ 'transform-inline-environment-variables' , { 'exclude' : [ 'SERVER_RENDERING' ] } ] ] ,
39- 'node' : [ 'inline-package-json' , ' transform-inline-environment-variables'] ,
40- 'react-native' : [ 'inline-package-json' , ' transform-inline-environment-variables']
32+ 'node' : [ 'transform-inline-environment-variables' ] ,
33+ 'react-native' : [ 'transform-inline-environment-variables' ]
4134} ;
4235
43- const DEV_HEADER = (
44- '/**\n' +
45- ' * Parse JavaScript SDK v' + VERSION + '\n' +
46- ' *\n' +
47- ' * The source tree of this library can be found at\n' +
48- ' * https://github.com/ParsePlatform/Parse-SDK-JS\n' +
49- ' */\n'
50- ) ;
51-
52- const FULL_HEADER = (
53- '/**\n' +
54- ' * Parse JavaScript SDK v' + VERSION + '\n' +
55- ' *\n' +
56- ' * Copyright 2015-present Parse Platform\n' +
57- ' * All rights reserved.\n' +
58- ' *\n' +
59- ' * The source tree of this library can be found at\n' +
60- ' * https://github.com/ParsePlatform/Parse-SDK-JS\n' +
61- ' *\n' +
62- ' * This source code is licensed under the license found in the LICENSE\n' +
63- ' * file in the root directory of this source tree. Additional legal\n' +
64- ' * information can be found in the NOTICE file in the same directory.\n' +
65- ' */\n'
66- ) ;
67-
6836function compileTask ( stream ) {
6937 return stream
7038 . pipe ( babel ( {
@@ -82,69 +50,6 @@ gulp.task('compile', function() {
8250 return compileTask ( gulp . src ( 'src/*.*(js|ts)' ) ) ;
8351} ) ;
8452
85- gulp . task ( 'browserify' , function ( cb ) {
86- const stream = browserify ( {
87- builtins : [ '_process' , 'events' ] ,
88- entries : 'lib/browser/Parse.js' ,
89- standalone : 'Parse'
90- } )
91- . exclude ( 'xmlhttprequest' )
92- . ignore ( '_process' )
93- . bundle ( ) ;
94- stream . on ( 'end' , ( ) => {
95- cb ( ) ;
96- } ) ;
97- return stream . pipe ( source ( 'parse.js' ) )
98- . pipe ( derequire ( ) )
99- . pipe ( insert . prepend ( DEV_HEADER ) )
100- . pipe ( gulp . dest ( './dist' ) ) ;
101- } ) ;
102-
103-
104- gulp . task ( 'browserify-weapp' , function ( cb ) {
105- const stream = browserify ( {
106- builtins : [ '_process' , 'events' ] ,
107- entries : 'lib/weapp/Parse.js' ,
108- standalone : 'Parse'
109- } )
110- . exclude ( 'xmlhttprequest' )
111- . ignore ( '_process' )
112- . bundle ( ) ;
113- stream . on ( 'end' , ( ) => {
114- cb ( ) ;
115- } ) ;
116- return stream . pipe ( source ( 'parse.weapp.js' ) )
117- . pipe ( derequire ( ) )
118- . pipe ( insert . prepend ( DEV_HEADER ) )
119- . pipe ( gulp . dest ( './dist' ) ) ;
120- } ) ;
121-
122- gulp . task ( 'minify' , function ( ) {
123- return gulp . src ( 'dist/parse.js' )
124- . pipe ( uglify ( ) )
125- . pipe ( insert . prepend ( FULL_HEADER ) )
126- . pipe ( rename ( { extname : '.min.js' } ) )
127- . pipe ( gulp . dest ( './dist' ) )
128- } ) ;
129-
130- gulp . task ( 'minify-weapp' , function ( ) {
131- return gulp . src ( 'dist/parse.weapp.js' )
132- . pipe ( uglify ( ) )
133- . pipe ( insert . prepend ( FULL_HEADER ) )
134- . pipe ( rename ( { extname : '.min.js' } ) )
135- . pipe ( gulp . dest ( './dist' ) )
136- } ) ;
137-
13853gulp . task ( 'watch' , function ( ) {
139- if ( BUILD === 'browser' ) {
140- const watcher = gulp . watch ( 'src/*.*(js|ts)' , { ignoreInitial : false } , gulp . series ( 'compile' , 'browserify' , 'minify' ) ) ;
141- watcher . on ( 'add' , function ( path ) {
142- console . log ( `File ${ path } was added` ) ;
143- } ) ;
144- watcher . on ( 'change' , function ( path ) {
145- console . log ( `File ${ path } was changed` ) ;
146- } ) ;
147- return watcher ;
148- }
14954 return compileTask ( watch ( 'src/*.*(js|ts)' , { ignoreInitial : false , verbose : true } ) ) ;
15055} ) ;
0 commit comments