How to use the @codesandbox/common/lib/templates function in @codesandbox/common

To help you get started, we’ve selected a few @codesandbox/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codesandbox / codesandbox-client / packages / app / src / app / overmind / namespaces / editor / internalActions.ts View on Github external
// No idea why this typing fails!
        // @ts-ignore
        content: module.code || '',
        // @ts-ignore
        isBinary: module.isBinary,
      }));

      // TODO: What is a template really? Two different kinds of templates here, need to fix the types
      // Talk to Ives and Bogdan
      const newTemplate = (computeTemplate(parsed, modulesByPath) ||
        'node') as TemplateType;

      if (
        newTemplate !== currentTemplate &&
        templateDefinition.isServer ===
          getTemplateDefinition(newTemplate).isServer
      ) {
        state.editor.currentSandbox.template = newTemplate;
        await effects.api.saveTemplate(
          state.editor.currentSandbox.id,
          newTemplate
        );
      }
    }
  } catch (e) {
    // We don't want this to be blocking at all, it's low prio
    if (process.env.NODE_ENV === 'development') {
      console.error(e);
    }
  }
};
github codesandbox / codesandbox-client / packages / app / src / app / overmind / effects / zeit.ts View on Github external
async function getApiData(contents: any, sandbox: Sandbox) {
  const template = getTemplate(sandbox.template);

  let apiData: Partial = {
    files: [],
  };
  let packageJSON: any = {};
  let nowJSON: any = {};

  const projectPackage = contents.files['package.json'];
  const nowFile = contents.files['now.json'];

  if (projectPackage) {
    const data = await projectPackage.async('text'); // eslint-disable-line no-await-in-loop

    const parsed = JSON.parse(data);
    packageJSON = parsed;
  }
github codesandbox / codesandbox-client / packages / app / src / app / store / modules / deployment / actions.js View on Github external
export async function deployToNetlify({ http, props, state }) {
  const { file } = props;
  state.set('deployment.netlifyLogs', null);
  const userId = state.get('user.id');
  const sandboxId = state.get('editor.currentId');
  const sandbox = state.get(`editor.sandboxes.${sandboxId}`);
  const template = getTemplate(sandbox.template);
  const buildCommand = name => {
    switch (name) {
      case 'styleguidist':
        return 'styleguide:build';
      case 'nuxt':
        return 'generate';
      default:
        return 'build';
    }
  };

  const buildConfig = getNetlifyConfig(sandbox);
  // command needs to be passed without the package manager name
  const buildCommandFromConfig = (buildConfig.command || '')
    .replace('npm run', '')
    .replace('yarn ', '');
github codesandbox / codesandbox-client / packages / app / src / app / overmind / effects / netlify.ts View on Github external
async deploy(file: string, sandbox: Sandbox): Promise {
      const userId = _options.getUserId();
      const template = getTemplate(sandbox.template);
      const buildCommand = (name: string) => {
        if (name === 'styleguidist') {
          return 'styleguide:build';
        }
        if (name === 'nuxt') {
          return 'generate';
        }

        return 'build';
      };
      const buildConfig = getNetlifyConfig(sandbox);
      // command needs to be passed without the package manager name
      const buildCommandFromConfig = (buildConfig.command || '')
        .replace('npm run', '')
        .replace('yarn ', '');
      let id = '';
github codesandbox / codesandbox-client / packages / app / src / app / store / modules / workspace / sequences.js View on Github external
(template, privacy) => {
      const templateDefinition = getTemplate(template);

      return templateDefinition.isServer && privacy === 2;
    }
  ),
github codesandbox / codesandbox-client / packages / app / src / app / overmind / utils / items.ts View on Github external
const { currentSandbox } = store.editor;

  if (!currentSandbox.owned) {
    return [PROJECT_SUMMARY, CONFIGURATION];
  }

  const isCustomTemplate = !!currentSandbox.customTemplate;
  const items = [
    isCustomTemplate ? PROJECT_TEMPLATE : PROJECT,
    FILES,
    CONFIGURATION,
  ];

  if (store.isLoggedIn && currentSandbox) {
    const templateDef = getTemplate(currentSandbox.template);
    if (templateDef.isServer) {
      items.push(SERVER);
    }
  }

  if (store.isLoggedIn && currentSandbox && !currentSandbox.git) {
    items.push(GITHUB);
  }

  if (store.isLoggedIn) {
    items.push(DEPLOYMENT);
  }

  if (store.isLoggedIn) {
    items.push(LIVE);
  }
github codesandbox / codesandbox-client / packages / app / src / app / pages / Sandbox / Editor / Workspace / items / Deployment / Netlify / Netlify.tsx View on Github external
const {
    actions: {
      deployment: { getNetlifyDeploys },
    },
    state: {
      deployment: { deploying, netlifySite },
      editor: { currentSandbox },
    },
  } = useOvermind();
  const [isVisible, setVisible] = useState(false);

  useEffect(() => {
    getNetlifyDeploys();
  }, [getNetlifyDeploys]);

  const template = getTemplate(currentSandbox.template);

  return (
    template.netlify !== false && (
      
         setVisible(show => !show)}
        />

        {netlifySite && isVisible ?  : null}
      
    )
  );
};
github codesandbox / codesandbox-client / packages / app / src / app / store / utils / main-module.js View on Github external
export function defaultOpenedModule(
  sandbox: Sandbox,
  parsedConfigurations: Object
) {
  const templateDefinition = getDefinition(sandbox.template);

  const resolve = resolveModuleWrapped(sandbox);

  const module = templateDefinition
    .getDefaultOpenedFiles(parsedConfigurations)
    .map(p => resolve(p))
    .find(m => m);

  return module || sandbox.modules[0];
}
github codesandbox / codesandbox-client / packages / app / src / app / pages / Sandbox / Editor / Workspace / SSEDownNotice / SSEDownNotice.tsx View on Github external
export const SSEDownNotice: FunctionComponent = () => {
  const {
    state: {
      editor: {
        currentSandbox: { template },
      },
      server: { status },
    },
  } = useOvermind();

  if (!getTemplate(template).isServer) {
    return null;
  }

  if (status !== 'disconnected') {
    return null;
  }

  return (