Beispiel #1
2
function initProjectFile() {
  // generator app.json
  const appJsonObject = Object.assign({
    name: _.camelCase(require(path.join(process.cwd(), 'package.json')).name)
  }, rnConfig.appJson)
  // generator .${tempPath}/package.json TODO JSON.parse 这种写法可能会有隐患
  const pkgTempObj = JSON.parse(
    ejs.render(pkgTmpl, {
        projectName: _.camelCase(projectConfig.projectName),
        version: Util.getPkgVersion()
      }
    ).replace(/(\r\n|\n|\r|\s+)/gm, '')
  )
  const dependencies = require(path.join(process.cwd(), 'package.json')).dependencies
  pkgTempObj.dependencies = Object.assign({}, pkgTempObj.dependencies, dependencies)

  const indexJsStr = `
  import {AppRegistry} from 'react-native';
  import App from './${entryBaseName}';
  import {name as appName} from './app.json';

  AppRegistry.registerComponent(appName, () => App);`

  fs.writeFileSync(path.join(tempDir, 'index.js'), indexJsStr)
  Util.printLog(processTypeEnum.GENERATE, 'index.js', path.join(tempPath, 'index.js'))
  fs.writeFileSync(path.join(tempDir, 'app.json'), JSON.stringify(appJsonObject, null, 2))
  Util.printLog(processTypeEnum.GENERATE, 'app.json', path.join(tempPath, 'app.json'))
  fs.writeFileSync(path.join(tempDir, 'package.json'), JSON.stringify(pkgTempObj, null, 2))
  Util.printLog(processTypeEnum.GENERATE, 'package.json', path.join(tempPath, 'package.json'))
}
Beispiel #2
0
async function processFile(filePath) {
  if (!fs.existsSync(filePath)) {
    return
  }
  const dirname = path.dirname(filePath)
  const distDirname = dirname.replace(sourceDir, tempDir)
  let distPath = path.format({dir: distDirname, base: path.basename(filePath)})
  const code = fs.readFileSync(filePath, 'utf-8')
  if (REG_STYLE.test(filePath)) {
    // do something
  } else if (REG_SCRIPTS.test(filePath)) {
    if (REG_TYPESCRIPT.test(filePath)) {
      distPath = distPath.replace(/\.(tsx|ts)(\?.*)?$/, '.js')
    }
    Util.printLog(processTypeEnum.COMPILE, _.camelCase(path.extname(filePath)).toUpperCase(), filePath)
    // transformJSCode
    const transformResult = transformJSCode({code, filePath, isEntryFile: isEntryFile(filePath), projectConfig})
    const jsCode = transformResult.code
    fs.ensureDirSync(distDirname)
    fs.writeFileSync(distPath, Buffer.from(jsCode))
    // compileDepStyles
    const styleFiles = transformResult.styleFiles
    depTree[filePath] = styleFiles
    await compileDepStyles(filePath, styleFiles)
  } else {
    fs.ensureDirSync(distDirname)
    fs.copySync(filePath, distPath)
    Util.printLog(processTypeEnum.COPY, _.camelCase(path.extname(filePath)).toUpperCase(), filePath)
  }
}
export function parseFunctionMetadata({ prefixMap, name }) {
  let typeName;
  let methodName;

  const matchedPrefix = Object.keys(prefixMap).find(
    prefix => name.indexOf(prefix) === 0
  );
  if (matchedPrefix) {
    typeName = prefixMap[matchedPrefix];

    methodName = camelCase(name.replace(matchedPrefix, ''));
  } else {
    // The type name is the word before the first dash capitalized. If the type
    // is Vim, then it a editor-global method which will be attached to the Nvim
    // class.
    const parts = name.split('_');
    typeName = capitalize(parts[0]);
    methodName = camelCase(
      (typeName === 'Ui' ? parts : parts.slice(1)).join('_')
    );
  }

  return {
    typeName,
    methodName,
  };
}
Beispiel #4
0
 return this.builderReady.then(() => {
   this.form.title = this.formTitle.nativeElement.value;
   this.form.display = this.formType.nativeElement.value;
   this.form.components = this.builder.formio.schema.components;
   if (this.config.tag) {
     this.form.tags = this.form.tags || [];
     this.form.tags.push(this.config.tag);
     this.form.tags = _.uniq(this.form.tags);
   }
   if (!this.form._id) {
     this.form.name = _.camelCase(this.form.title).toLowerCase();
     this.form.path = this.form.name;
   }
   return this.service.formio.saveForm(this.form).then(form => {
     this.form = this.service.setForm(form);
     this.loading = false;
     return this.form;
   }).catch(err => {
     this.loading = false;
     // Catch if a form is returned as an error. This is a conflict.
     if (err._id && err.type) {
       throw err;
     }
     this.alerts.setAlert({type: 'danger', message: (err.message || err)});
   });
 });
Beispiel #5
0
 function getFieldData(field: Field): IColumnFieldData {
     const fieldName = field.fieldName;
     const fieldProps: IFieldProperties = field.properties;
     const modelMeta: IFieldMeta = getFieldMeta(config.model, fieldName);
     if (!modelMeta.list) { return null as IColumnFieldData; }
     let columnCode = "";
     const prefixCode = "";
     let hasValue = true;
     let render = null;
     let isRenderInline = true;
     switch (fieldProps.type) {
         case FieldType.Text:
         case FieldType.Password:
         case FieldType.File:
         case FieldType.Relation:
         case FieldType.List:
         case FieldType.Object:
             hasValue = false;
             break;
         // case FieldType.String:
         // case FieldType.Tel:
         // case FieldType.EMail:
         // case FieldType.URL:
         // case FieldType.Number:
         // case FieldType.Integer:
         // case FieldType.Float:
         //     break;
         case FieldType.Timestamp:
             isRenderInline = false;
             render = `dateTime.setTime(r.${fieldName});
             return dateTime.format("Y/m/d");`;
             break;
         case FieldType.Boolean:
             render = `tr(r.${fieldName} ? "yes" : "no")`;
             break;
         case FieldType.Enum:
             if (modelMeta.enum) {
                 // const listClass = file.getClass();
                 const enumName = camelCase(modelMeta.enum.options[0].split(".")[0]) + "Options";
                 const options = modelMeta.enum.options.map((option, index) => `${fieldProps.enum[index]}: tr("enum_${option.split(".")[1].toLowerCase()}")`);
                 // code = `const ${enumName} = {${options.join(', ')}};`;
                 render = `tr(${enumName}[r.${fieldName}])`;
                 // listClass.addProperty({ name: enumName, access: "private", defaultValue: `{${options.join(", ")}}` });
             }
             break;
     }
     if (hasValue) {
         if (render) {
             columnCode = isRenderInline ? `{ title: tr("fld_${fieldName}"), render: (r: ${model.interfaceName}) => ${render} }` : `{
         title: tr("fld_${fieldName}"),
         render: (r: ${model.interfaceName}) => {
             ${render}
         }
     }`;
         } else {
             columnCode = `{ name: "${fieldName}", title: tr("fld_${fieldName}") }`;
         }
     }
     return { column: columnCode, code: prefixCode };
 }
Beispiel #6
0
 mapToActionCreator(stream, actionType) {
   const actionCreator = this.actionCreators[camelCase(actionType)];
   if (!!actionCreator === false) {
     throw new Error(`No action creator defined for this action: ${actionType}`);
   }
   return stream.map(actionCreator);
 }
 createCustomElement: ({ selectedNodes }: Props) => (
   name = '',
   description = '',
   image = ''
 ): void => {
   if (selectedNodes.length) {
     const content = JSON.stringify({ selectedNodes });
     const customElement = {
       id: getId('custom-element'),
       name: camelCase(name),
       displayName: name,
       help: description,
       image,
       content,
     };
     customElementService
       .create(customElement)
       .then(() =>
         notify.success(
           `Custom element '${customElement.displayName || customElement.id}' was saved`
         )
       )
       .catch((result: Http2ServerResponse) =>
         notify.warning(result, {
           title: `Custom element '${customElement.displayName ||
             customElement.id}' was not saved`,
         })
       );
   }
 },
Beispiel #8
0
(async function init() {
  for (const commandPath of commandsPath) {
    const className = upperFirst(camelCase(commandPath.replace(/\./g, '-')));

    if (
      process.env.NODE_ENV !== 'production' &&
      filter &&
      `${filter}.command` !== commandPath
    ) {
      continue;
    }

    const classInterface = (await import(`./commands/${commandPath}`))[
      className
    ];

    const commandObject = new classInterface();
    try {
      yargs.command(commandObject);
    } catch (e) {
      console.log('ERROR ON COMMAND');
      console.log(e);
    }
  }

  yargs
    .demandCommand(1)
    .strict()
    .help('h')
    .alias('v', 'version').argv;
})();
Beispiel #9
0
 source.split(/\s*;\s*/g).forEach(kv => {
   const [name, value] = kv.split(":");
   if (!name || !value) {
     return;
   }
   style[camelCase(name.trim())] = value.trim();
 });
Beispiel #10
0
export function compose(): FrontendLibs {
  const api = new AxiosRestAPIAdapter(chrome.getXsrfToken(), chrome.getBasePath());
  const esAdapter = new RestElasticsearchAdapter(api, INDEX_NAMES.BEATS);
  const elasticsearchLib = new ElasticsearchLib(esAdapter);
  const configBlocks = new ConfigBlocksLib(
    new RestConfigBlocksAdapter(api),
    translateConfigSchema(configBlockSchemas)
  );
  const tags = new TagsLib(new RestTagsAdapter(api), elasticsearchLib);
  const tokens = new RestTokensAdapter(api);
  const beats = new BeatsLib(new RestBeatsAdapter(api), elasticsearchLib);

  const framework = new FrameworkLib(
    new KibanaFrameworkAdapter(
      camelCase(PLUGIN.ID),
      management,
      routes,
      chrome.getBasePath,
      onKibanaReady,
      XPackInfoProvider,
      chrome.getKibanaVersion()
    )
  );

  const libs: FrontendLibs = {
    framework,
    elasticsearch: elasticsearchLib,
    tags,
    tokens,
    beats,
    configBlocks,
  };
  return libs;
}