How to use the @codesandbox/common/lib/templates/configuration/package-json.generateFileFromSandbox 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 / internalActions.ts View on Github external
export const ensurePackageJSON: AsyncAction = async ({
  state,
  actions,
  effects,
}) => {
  const sandbox = state.editor.currentSandbox;
  const existingPackageJson = sandbox.modules.find(
    module => module.directoryShortid == null && module.title === 'package.json'
  );

  if (sandbox.owned && !existingPackageJson) {
    const optimisticId = effects.utils.createOptimisticId();
    const optimisticModule = createOptimisticModule({
      id: optimisticId,
      title: 'package.json',
      code: generatePackageJsonFromSandbox(sandbox),
      path: '/package.json',
    });

    state.editor.currentSandbox.modules.push(optimisticModule as Module);
    optimisticModule.path = getModulePath(
      sandbox.modules,
      sandbox.directories,
      optimisticId
    );

    // We grab the module from the state to continue working with it (proxy)
    const module = sandbox.modules[sandbox.modules.length - 1];

    effects.vscode.sandboxFsSync.writeFile(state.editor.modulesByPath, module);

    try {
github codesandbox / codesandbox-client / packages / app / src / sandbox / index.js View on Github external
.then(x => {
        const moduleObject = {};

        // We convert the modules to a format the manager understands
        x.data.modules.forEach(m => {
          const path = getModulePath(x.data.modules, x.data.directories, m.id);
          moduleObject[path] = {
            path,
            code: m.code,
          };
        });

        if (!moduleObject['/package.json']) {
          moduleObject['/package.json'] = {
            code: generateFileFromSandbox(x.data),
            path: '/package.json',
          };
        }

        const data = {
          sandboxId: id,
          modules: moduleObject,
          entry: '/' + x.data.entry,
          externalResources: x.data.externalResources,
          dependencies: x.data.npmDependencies,
          hasActions: false,
          template: x.data.template,
          version: 3,
          disableDependencyPreprocessing: document.location.search.includes(
            'csb-dynamic-download'
          ),
github nscozzaro / physics-is-beautiful / courses / static / courses / js / containers / StudioViews / EditorsViews / containers / LessonWorkSpace / Codesandbox / sandbox-exe / index.js View on Github external
.then(x => {
        const moduleObject = {};

        // We convert the modules to a format the manager understands
        x.data.modules.forEach(m => {
          const path = getModulePath(x.data.modules, x.data.directories, m.id);
          moduleObject[path] = {
            path,
            code: m.code,
          };
        });

        if (!moduleObject['/package.json']) {
          moduleObject['/package.json'] = {
            code: generateFileFromSandbox(x.data),
            path: '/package.json',
          };
        }

        const data = {
          sandboxId: id,
          modules: moduleObject,
          entry: '/' + x.data.entry,
          externalResources: x.data.externalResources,
          dependencies: x.data.npmDependencies,
          hasActions: false,
          template: x.data.template,
          version: 3,
          disableDependencyPreprocessing: document.location.search.includes(
            'csb-dynamic-download'
          ),
github codesandbox / codesandbox-client / packages / app / src / app / utils / executor-manager.ts View on Github external
sandbox.modules.forEach(m => {
    const { path } = m;
    if (path) {
      modulesObject[path] = {
        code: m.code,
        savedCode: m.savedCode,
        path,
        isBinary: m.isBinary,
      };
    }
  });

  if (!modulesObject['/package.json']) {
    modulesObject['/package.json'] = {
      code: generateFileFromSandbox(sandbox),
      savedCode: null,
      path: '/package.json',
      isBinary: false,
    };
  }

  return modulesObject;
}
github codesandbox / codesandbox-client / packages / app / src / app / store / actions.js View on Github external
export function createPackageJSON({ props }) {
  const { sandbox } = props;

  const code = generateFileFromSandbox(sandbox);

  return {
    title: 'package.json',
    newCode: code,
  };
}
github codesandbox / codesandbox-client / packages / app / src / app / overmind / namespaces / editor / state.ts View on Github external
currentPackageJSONCode: ({ currentSandbox, currentPackageJSON }) => {
    if (!currentPackageJSON) {
      return null;
    }

    return currentPackageJSON.code
      ? currentPackageJSON.code
      : generateFileFromSandbox(currentSandbox);
  },
  shouldDirectoryBeOpen: ({
github codesandbox / codesandbox-client / packages / app / src / app / store / modules / editor / getters.js View on Github external
export function currentPackageJSONCode() {
  return this.currentPackageJSON
    ? this.currentPackageJSON.code
    : generateFileFromSandbox(this.currentSandbox);
}