mirror of
https://github.com/bobwen-dev/react-templates
synced 2025-04-12 00:56:39 +02:00
Fix #167 --native CLI behaviour
This commit is contained in:
parent
46caeea387
commit
a993ebffde
@ -32,12 +32,13 @@ function convertFile(source, target, options, context) {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const shouldAddName = options.modules === 'none' && !options.name;
|
const modules = options.modules || 'none';
|
||||||
|
const shouldAddName = modules === 'none' && !options.name;
|
||||||
if (shouldAddName) {
|
if (shouldAddName) {
|
||||||
options.name = reactTemplates.normalizeName(path.basename(source, path.extname(source))) + 'RT';
|
options.name = reactTemplates.normalizeName(path.basename(source, path.extname(source))) + 'RT';
|
||||||
}
|
}
|
||||||
options.readFileSync = fsUtil.createRelativeReadFileSync(source);
|
options.readFileSync = fsUtil.createRelativeReadFileSync(source);
|
||||||
const js = options.modules === 'jsrt' ? convertJSRTToJS(html, context, options) : convertRT(html, context, options);
|
const js = modules === 'jsrt' ? convertJSRTToJS(html, context, options) : convertRT(html, context, options);
|
||||||
if (!options.dryRun) {
|
if (!options.dryRun) {
|
||||||
fs.writeFileSync(target, js);
|
fs.writeFileSync(target, js);
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ $ rt <filename> [<filename> ...] [<args>]`,
|
|||||||
}, {
|
}, {
|
||||||
option: 'modules',
|
option: 'modules',
|
||||||
alias: 'm',
|
alias: 'm',
|
||||||
default: 'none',
|
|
||||||
type: 'String',
|
type: 'String',
|
||||||
|
enum: ['amd', 'commonjs', 'none', 'es6', 'typescript', 'jsrt'],
|
||||||
description: 'Use output modules. (amd|commonjs|none|es6|typescript|jsrt)'
|
description: 'Use output modules. (amd|commonjs|none|es6|typescript|jsrt)'
|
||||||
}, {
|
}, {
|
||||||
option: 'name',
|
option: 'name',
|
||||||
@ -93,7 +93,6 @@ $ rt <filename> [<filename> ...] [<args>]`,
|
|||||||
description: 'Show stack trace on errors.'
|
description: 'Show stack trace on errors.'
|
||||||
}, {
|
}, {
|
||||||
option: 'react-import-path',
|
option: 'react-import-path',
|
||||||
default: 'react/addons',
|
|
||||||
type: 'String',
|
type: 'String',
|
||||||
description: 'Dependency path for importing React.'
|
description: 'Dependency path for importing React.'
|
||||||
}, {
|
}, {
|
||||||
|
@ -75,8 +75,8 @@ function getOptions(options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const finalOptions = _.defaults({}, options, defaultOptions);
|
const finalOptions = _.defaults({}, options, defaultOptions);
|
||||||
finalOptions.reactImportPath = finalOptions.reactImportPath || reactImport(finalOptions);
|
finalOptions.reactImportPath = reactImport(finalOptions);
|
||||||
finalOptions.modules = finalOptions.modules || (finalOptions.native ? 'commonjs' : 'amd');
|
finalOptions.modules = finalOptions.modules || (finalOptions.native ? 'commonjs' : 'none');
|
||||||
|
|
||||||
const defaultPropTemplates = finalOptions.native ?
|
const defaultPropTemplates = finalOptions.native ?
|
||||||
reactPropTemplates.native[finalOptions.nativeTargetVersion] :
|
reactPropTemplates.native[finalOptions.nativeTargetVersion] :
|
||||||
@ -90,7 +90,7 @@ function reactImport(options) {
|
|||||||
if (options.native) {
|
if (options.native) {
|
||||||
return 'react-native';
|
return 'react-native';
|
||||||
}
|
}
|
||||||
if (options.targetVersion === '0.14.0' || options.targetVersion === '0.15.0' || options.targetVersion === '15.0.0' || options.targetVersion === '15.0.1') {
|
if (_.includes(['0.14.0', '0.15.0', '15.0.0', '15.0.1'], options.targetVersion)) {
|
||||||
return 'react';
|
return 'react';
|
||||||
}
|
}
|
||||||
return 'react/addons';
|
return 'react/addons';
|
||||||
|
@ -25,12 +25,12 @@ module.exports = {
|
|||||||
|
|
||||||
test('rt-if with rt-scope test', t => {
|
test('rt-if with rt-scope test', t => {
|
||||||
const files = ['if-with-scope/valid-if-scope.rt'];
|
const files = ['if-with-scope/valid-if-scope.rt'];
|
||||||
testFiles(t, files);
|
testFiles(t, files, {modules: 'amd'});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('conversion test', t => {
|
test('conversion test', t => {
|
||||||
const files = ['div.rt', 'test.rt', 'repeat.rt', 'repeat-with-index.rt', 'inputs.rt', 'virtual.rt', 'stateless.rt', 'style-vendor-prefix.rt'];
|
const files = ['div.rt', 'test.rt', 'repeat.rt', 'repeat-with-index.rt', 'inputs.rt', 'virtual.rt', 'stateless.rt', 'style-vendor-prefix.rt'];
|
||||||
testFiles(t, files);
|
testFiles(t, files, {modules: 'amd'});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('prop template conversion test', t => {
|
test('prop template conversion test', t => {
|
||||||
@ -39,7 +39,8 @@ module.exports = {
|
|||||||
List: {
|
List: {
|
||||||
Row: {prop: 'renderRow', arguments: ['rowData']}
|
Row: {prop: 'renderRow', arguments: ['rowData']}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
modules: 'amd'
|
||||||
};
|
};
|
||||||
const files = ['propTemplates/simpleTemplate.rt', 'propTemplates/templateInScope.rt', 'propTemplates/implicitTemplate.rt', 'propTemplates/twoTemplates.rt'];
|
const files = ['propTemplates/simpleTemplate.rt', 'propTemplates/templateInScope.rt', 'propTemplates/implicitTemplate.rt', 'propTemplates/twoTemplates.rt'];
|
||||||
testFiles(t, files, options);
|
testFiles(t, files, options);
|
||||||
@ -180,7 +181,8 @@ module.exports = {
|
|||||||
function check(testFile) {
|
function check(testFile) {
|
||||||
const filename = path.join(dataPath, testFile);
|
const filename = path.join(dataPath, testFile);
|
||||||
const options = {
|
const options = {
|
||||||
readFileSync: fsUtil.createRelativeReadFileSync(filename)
|
readFileSync: fsUtil.createRelativeReadFileSync(filename),
|
||||||
|
modules: 'amd'
|
||||||
};
|
};
|
||||||
let code = '';
|
let code = '';
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user