Skip to content

Instantly share code, notes, and snippets.

@xx7y7xx
Last active Jul 29, 2016
Embed
What would you like to do?
// input file `/tmp/xx3` is created by:
//
// ```
// $ ls -d -1 $PWD/**/*
// ```
var util = require('util');
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream('/tmp/xx3')
});
var l = function (msg) {
console.log(msg);
};
// Check input file type
var typeOf = function (path) {
if (path.endsWith('.html')) {
return 'html';
} else {
return 'js';
}
};
l('var config = {');
l(' define: {');
lineReader.on('line', function (line) {
var atom, moduleName, newLine,
ext = typeOf(line);
// integer/template
// ssc/integer/viewmodel
atom = line.replace("/home/chenyang/source/ssc_webcomp/comp/", "").replace('.' + ext, '');
switch(ext) {
// Input: /home/chenyang/source/ssc_webcomp/comp/integer/template.html
case 'html':
// text!ssc/integer/template.html
moduleName = 'text!' + atom + '.' + ext;
break;
// Input: /home/chenyang/source/ssc_webcomp/comp/integer/viewmodel.js
case 'js':
moduleName = 'ssc/' + atom;
break;
default:
}
newLine = util.format(" '%s': '/'+path.project+'/'+path.version+'/%s/'+'%s.%s',", moduleName, ext, atom, ext);
// Output: '/iwebap/js/ref/refers_RefGrid.js':'/'+path.project+'/'+path.version+'/js/'+'RefTree/refers_RefGrid.js',
l(newLine);
});
lineReader.on('close', function (line) {
l(' }');
l('}');
});
/*
'/iwebap/trd/handlebars/handlebars-v4.0.5.js': '/'+path.project+'/'+path.version+'/js/lib/'+'handlebars/handlebars-v4.0.5.js',
'/iwebap/trd/handlebars/handlebars.runtime-v4.0.5.js': '/'+path.project+'/'+path.version+'/js/lib/'+'handlebars/handlebars.runtime-v4.0.5.js',
*/
@xx7y7xx
Copy link
Author

xx7y7xx commented Jul 29, 2016

result:

// http://git.yonyou.com/sscplatform/ssc_webcomp/issues/98

var config = {
  define: {
    'ssc/boolean/main': '/'+path.project+'/'+path.version+'/js/'+'boolean/main.js',
    'text!boolean/template.html': '/'+path.project+'/'+path.version+'/html/'+'boolean/template.html',
    'ssc/boolean/viewmodel': '/'+path.project+'/'+path.version+'/js/'+'boolean/viewmodel.js',
    'ssc/date/main': '/'+path.project+'/'+path.version+'/js/'+'date/main.js',
    'text!date/template.html': '/'+path.project+'/'+path.version+'/html/'+'date/template.html',
    'ssc/date/viewmodel': '/'+path.project+'/'+path.version+'/js/'+'date/viewmodel.js',
    'ssc/decimal/main': '/'+path.project+'/'+path.version+'/js/'+'decimal/main.js',
    'text!decimal/template.html': '/'+path.project+'/'+path.version+'/html/'+'decimal/template.html',
    'ssc/decimal/viewmodel': '/'+path.project+'/'+path.version+'/js/'+'decimal/viewmodel.js',
    'ssc/emailaddress/main': '/'+path.project+'/'+path.version+'/js/'+'emailaddress/main.js',
    'text!emailaddress/template.html': '/'+path.project+'/'+path.version+'/html/'+'emailaddress/template.html',
    'ssc/emailaddress/viewmodel': '/'+path.project+'/'+path.version+'/js/'+'emailaddress/viewmodel.js',
    'ssc/integer/main': '/'+path.project+'/'+path.version+'/js/'+'integer/main.js',
    'text!integer/template.html': '/'+path.project+'/'+path.version+'/html/'+'integer/template.html',
    'ssc/integer/viewmodel': '/'+path.project+'/'+path.version+'/js/'+'integer/viewmodel.js',
    'ssc/money/main': '/'+path.project+'/'+path.version+'/js/'+'money/main.js',
    'text!money/template.html': '/'+path.project+'/'+path.version+'/html/'+'money/template.html',
    'ssc/money/viewmodel': '/'+path.project+'/'+path.version+'/js/'+'money/viewmodel.js',
    'ssc/multilang/main': '/'+path.project+'/'+path.version+'/js/'+'multilang/main.js',
    'text!multilang/template.html': '/'+path.project+'/'+path.version+'/html/'+'multilang/template.html',
    'ssc/multilang/viewmodel': '/'+path.project+'/'+path.version+'/js/'+'multilang/viewmodel.js',
    'ssc/other/main': '/'+path.project+'/'+path.version+'/js/'+'other/main.js',
    'text!other/template.html': '/'+path.project+'/'+path.version+'/html/'+'other/template.html',
    'ssc/other/viewmodel': '/'+path.project+'/'+path.version+'/js/'+'other/viewmodel.js',
    'ssc/queryform/main': '/'+path.project+'/'+path.version+'/js/'+'queryform/main.js',
    'ssc/queryform/querytpl.bind_event': '/'+path.project+'/'+path.version+'/js/'+'queryform/querytpl.bind_event.js',
    'ssc/queryform/querytpl.exports': '/'+path.project+'/'+path.version+'/js/'+'queryform/querytpl.exports.js',
    'ssc/queryform/querytpl.helper': '/'+path.project+'/'+path.version+'/js/'+'queryform/querytpl.helper.js',
    'ssc/queryform/querytpl.init_date': '/'+path.project+'/'+path.version+'/js/'+'queryform/querytpl.init_date.js',
    'ssc/queryform/querytpl': '/'+path.project+'/'+path.version+'/js/'+'queryform/querytpl.js',
    'ssc/queryform/querytpl.refer': '/'+path.project+'/'+path.version+'/js/'+'queryform/querytpl.refer.js',
    'text!queryform/template.html': '/'+path.project+'/'+path.version+'/html/'+'queryform/template.html',
    'ssc/queryform/utils': '/'+path.project+'/'+path.version+'/js/'+'queryform/utils.js',
    'ssc/queryform/viewmodel': '/'+path.project+'/'+path.version+'/js/'+'queryform/viewmodel.js',
    'ssc/string/main': '/'+path.project+'/'+path.version+'/js/'+'string/main.js',
    'text!string/template.html': '/'+path.project+'/'+path.version+'/html/'+'string/template.html',
    'ssc/string/viewmodel': '/'+path.project+'/'+path.version+'/js/'+'string/viewmodel.js',
    'ssc/ufref/main': '/'+path.project+'/'+path.version+'/js/'+'ufref/main.js',
    'text!ufref/template.html': '/'+path.project+'/'+path.version+'/html/'+'ufref/template.html',
    'ssc/ufref/viewmodel': '/'+path.project+'/'+path.version+'/js/'+'ufref/viewmodel.js',
    'ssc/uftime/main': '/'+path.project+'/'+path.version+'/js/'+'uftime/main.js',
    'text!uftime/template.html': '/'+path.project+'/'+path.version+'/html/'+'uftime/template.html',
    'ssc/uftime/viewmodel': '/'+path.project+'/'+path.version+'/js/'+'uftime/viewmodel.js',
    'ssc/usercombo/main': '/'+path.project+'/'+path.version+'/js/'+'usercombo/main.js',
    'text!usercombo/template.html': '/'+path.project+'/'+path.version+'/html/'+'usercombo/template.html',
    'ssc/usercombo/viewmodel': '/'+path.project+'/'+path.version+'/js/'+'usercombo/viewmodel.js',
    '/iwebap/trd/handlebars/handlebars-v4.0.5.js': '/'+path.project+'/'+path.version+'/js/lib/'+'handlebars/handlebars-v4.0.5.js',
    '/iwebap/trd/handlebars/handlebars.runtime-v4.0.5.js': '/'+path.project+'/'+path.version+'/js/lib/'+'handlebars/handlebars.runtime-v4.0.5.js',
  }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment